};
SceneObject sceneObjs[MAXOBJECTS]; // An array with details of the objects in a scene
-int nObjects=0; // How many objects there are in the scene currently.
+int nObjects = 0; // How many objects there are in the scene currently.
+int curObject = -1; // The scene object that is currently selected, (-1 is no object)
+int buttonSelected = -1; // Either GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or -1 (no button)
+int manipulateState = STATE_CAMERA_ROTATE_MOVE; // See manipulateStates enum
// Directories containing models
char *dirDefault1 = "models-textures";
GLfloat lineLength = 10;
/* Light 0 parameters */
-GLfloat diffuse0[]={1.0, 1.0, 1.0, 0.1};
-GLfloat ambient0[]={1.0, 1.0, 1.0, 0.1};
-GLfloat specular0[]={1.0, 1.0, 1.0, 0.1};
+GLfloat diffuse0[]={1.0, 0.0, 0.0, 1.0};
+GLfloat ambient0[]={1.0, 0.0, 0.0, 1.0};
+GLfloat specular0[]={1.0, 0.0, 0.0, 1.0};
GLfloat direction0[] = {0.0, 0.0, 0.0};
GLfloat lightPosition0[4];
int lightMoving0 = 0, lightStartX0, lightStartY0;
/* Light 1 parameters */
-GLfloat diffuse1[]={1.0, 1.0, 1.0, 0.1};
-GLfloat ambient1[]={1.0, 1.0, 1.0, 0.1};
-GLfloat specular1[]={1.0, 1.0, 1.0, 0.1};
+GLfloat diffuse1[]={0.0, 1.0, 0.0, 1.0};
+GLfloat ambient1[]={0.0, 1.0, 0.0, 1.0};
+GLfloat specular1[]={0.0, 1.0, 0.0, 1.0};
GLfloat direction1[] = {0.0, 0.0, 0.0};
GLfloat lightPosition1[4];
GLfloat emission[] = {0.0, 0.3, 0.3, 1.0};
/* Zoom and rotate tracking */
-GLfloat zoom = 0.0, rotate = 0.0;
-GLfloat zoomFactor = 0.2, rotateFactor = 0.5;
+GLfloat zoom = 0.0, rotate = 0.0, camAngle = 40.0;
+GLfloat zoomFactor = 0.2, rotateFactor = 0.5, camAngleFactor = 0.5;
+GLfloat leftrightFactor = 0.5, nearfarFactor = 0.5, bigsmallFactor = 0.5, updownFactor = 0.5;
/* Beginning width, height */
int width = 500, height = 500;
// Scene object arrays
extern SceneObject sceneObjs[];
extern int nObjects;
+extern int curObject;
+extern int buttonSelected;
+extern int manipulateState;
// Directories containing models
extern char *dirDefault1;
extern int width, height;
/* Zoom and rotate tracking */
-extern GLfloat zoom, rotate;
-extern GLfloat zoomFactor, rotateFactor;
+extern GLfloat zoom, rotate, camAngle;
+extern GLfloat zoomFactor, rotateFactor, camAngleFactor;
+extern GLfloat leftrightFactor, nearfarFactor, bigsmallFactor, updownFactor;
/* Texture state tracking */
extern int currentGroundTexture, currentMeshTexture;
glEnable(GL_TEXTURE_2D);
}
-void addSceneObject(int id) {
+int addSceneObject(int id) {
// **NOTE: Currently only adds the teapot
- nObjects += 1; // New object in scene
+ curObject = nObjects;
sceneObjs[nObjects].mesh = -1;
sceneObjs[nObjects].texture = -1;
sceneObjs[nObjects].rotation.parameter = 0;
sceneObjs[nObjects].rotation.vect = (vector*)calloc( 3, sizeof(vector[0]) );
+
+ nObjects += 1; // New object in scene
+
+ return nObjects;
}
\ No newline at end of file
void drawFloor();
void drawAxisLines();
-void addSceneObject(int id);
+int addSceneObject(int id);
#endif /* HELPER_H */
* @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
- startx = x;\r
- starty = y;\r
- }\r
- if (state == GLUT_UP) {\r
- moving = 0;\r
- }\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
+ 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
} texture;
-typedef GLfloat vector[3]; // Vector datatyle
+typedef GLfloat vector[3]; // Vector datatype
typedef struct {
GLfloat parameter; // Transform amount
M_LIGHT_RGBALL_LIGHT_2
};
-#endif /* TYPES_H */
+// Manipulation states
+enum manipulateStates {
+ STATE_CAMERA_ROTATE_MOVE,
+ STATE_OBJECT_POSITION_SCALE,
+ STATE_OBJECT_ROTATION_TEXTURE_SCALE
+};
+#endif /* TYPES_H */
\ No newline at end of file