* @param y Mouse y position\r
*/\r
void mouse(int button, int state, int x, int y) {\r
- if (button == GLUT_LEFT_BUTTON) {\r
- if (state == GLUT_DOWN) {\r
- moving = 1;\r
+ switch(button) {\r
+ case GLUT_LEFT_BUTTON:\r
+ case GLUT_MIDDLE_BUTTON:\r
+ if ( state == GLUT_DOWN ) {\r
+ buttonSelected = button;\r
+ } else if ( state == GLUT_UP ) {\r
+ buttonSelected = -1;\r
+ }\r
startx = x;\r
starty = y;\r
- }\r
- if (state == GLUT_UP) {\r
- moving = 0;\r
- }\r
+ break;\r
}\r
}\r
\r
* @param y Mouse y position\r
*/\r
void motion(int x, int y) {\r
- if (moving) {\r
- zoom += (y - starty);\r
- rotate += (x - startx);\r
- startx = x;\r
- starty = y;\r
- glutPostRedisplay();\r
- }\r
- if (lightMoving0) {\r
- lightAngle0 += (x - lightStartX0)/40.0;\r
- lightHeight0 += (lightStartY0 - y)/20.0;\r
- lightStartX0 = x;\r
- lightStartY0 = y;\r
- glutPostRedisplay();\r
- }\r
- if (lightMoving1) {\r
- lightAngle1 += (x - lightStartX1)/40.0;\r
- lightHeight1 += (lightStartY1 - y)/20.0;\r
- lightStartX1 = x;\r
- lightStartY1 = y;\r
- glutPostRedisplay();\r
+ if ( buttonSelected == -1 ) return; // No button selected, no action\r
+\r
+ switch ( manipulateState ) {\r
+ case STATE_CAMERA_ROTATE_MOVE:\r
+ rotate += (x - startx);\r
+\r
+ if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
+ // w: rotate, h: zoom\r
+ zoom += (y - starty);\r
+ } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
+ // w: rotate, h: tilt\r
+ camAngle += (y - starty);\r
+ }\r
+\r
+ starty = y;\r
+ startx = x;\r
+\r
+ break;\r
+\r
+ case STATE_OBJECT_POSITION_SCALE:\r
+ //SceneObject co = sceneObjs[curObject];\r
+\r
+ if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
+ // w: left/right, h: near/far\r
+ \r
+ } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
+ // w: big/small, h: up/down\r
+ }\r
+ break;\r
+\r
+ case STATE_OBJECT_ROTATION_TEXTURE_SCALE:\r
+ if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
+ // w: rotate on width, h: rotate on h\r
+ } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
+ // w & h, rotate on h\r
+ }\r
+ break;\r
+\r
}\r
+\r
+ glutPostRedisplay();\r
}\r
\r
/**\r
0.0, 10.0, 0.0 /* up is in postivie Y direction */\r
);\r
\r
- glRotatef(40.0, 1.0, 0.0, 0.0);\r
+ glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0);\r
\r
/* Reposition the light source 0. */\r
lightPosition0[0] = 12*cos(lightAngle0);\r
\r
drawFloor();\r
\r
- // Draw teapot for a test object\r
+ // Draw sceneObjs array\r
glPushMatrix();\r
- glTranslatef(0.0, 0.5, 0.0); // **NOTE: Teapot currently does not rest on surface\r
- glColor3f(0.0, 0.0, 1.0);\r
- glFrontFace(GL_CW); // The teapot does not obey the right-hand rule\r
- glutSolidTeapot(1);\r
- glFrontFace(GL_CCW);\r
+ for ( int i = 0; i < nObjects; i++ ) {\r
+ SceneObject so = sceneObjs[i];\r
+\r
+ // Apply rotation vector\r
+ vector* rv = so.rotation.vect;\r
+ glRotatef(so.rotation.parameter, *rv[0], *rv[1], *rv[2]);\r
+\r
+ // Apply scaling vector\r
+ vector* sv = so.scale;\r
+ glScalef(*sv[0], *sv[1], *sv[2]);\r
+\r
+ // Apply translation vector\r
+ glTranslatef(so.x, so.y, so.z);\r
+\r
+ // Apply texture\r
+ if ( so.texture > 0 ) {\r
+ getTexture(so.texture);\r
+ glBindTexture(GL_TEXTURE_2D, so.texture);\r
+ } else {\r
+ getTexture(0);\r
+ glBindTexture(GL_TEXTURE_2D, 0);\r
+ }\r
+\r
+ // Draw actual object\r
+ if ( so.mesh > 0 ) {\r
+ // drawMesh();\r
+ } else if ( so.mesh == -1 ) { // a mesh of -1 draws the teapot\r
+ // The teapot does not obey the right-hand rule\r
+ glFrontFace(GL_CW);\r
+ glutSolidTeapot(1);\r
+ glFrontFace(GL_CCW);\r
+ }\r
+\r
+ glBindTexture(GL_TEXTURE_2D, 0);\r
+ }\r
glPopMatrix();\r
\r
// Draw a white ball over the light source\r