(no commit message)
authorAsh Tyndall <[email protected]>
Fri, 21 Oct 2011 11:59:39 +0000 (19:59 +0800)
committerAsh Tyndall <[email protected]>
Fri, 21 Oct 2011 11:59:39 +0000 (19:59 +0800)
globals.c
globals.h
helper.c
helper.h
scene.c
types.h

index ded55aa..4f7c69e 100644 (file)
--- a/globals.c
+++ b/globals.c
@@ -35,7 +35,10 @@ const char *objectMenuEntries[NMESH] = {
 };
 
 SceneObject sceneObjs[MAXOBJECTS];  // An array with details of the objects in a scene
 };
 
 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";
 
 // Directories containing models
 char *dirDefault1 = "models-textures";
@@ -60,9 +63,9 @@ GLfloat factor = 1.0;
 GLfloat lineLength = 10;
 
 /* Light 0 parameters */
 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];
 GLfloat direction0[] = {0.0, 0.0, 0.0};
 
 GLfloat lightPosition0[4];
@@ -71,9 +74,9 @@ float lightAngle0 = 0.0, lightHeight0 = 5;
 int lightMoving0 = 0, lightStartX0, lightStartY0;
 
 /* Light 1 parameters */
 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 direction1[] = {0.0, 0.0, 0.0};
 
 GLfloat lightPosition1[4];
@@ -90,8 +93,9 @@ GLfloat glightmodel[] = {0.2,0.2,0.2,1};
 GLfloat emission[] = {0.0, 0.3, 0.3, 1.0};
 
 /* Zoom and rotate tracking */
 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;
 
 /* Beginning width, height */
 int width = 500, height = 500;
index b3d0d6b..058e32c 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -24,6 +24,9 @@ extern const char *objectMenuEntries[];
 // Scene object arrays
 extern SceneObject sceneObjs[];
 extern int nObjects;
 // Scene object arrays
 extern SceneObject sceneObjs[];
 extern int nObjects;
+extern int curObject;
+extern int buttonSelected;
+extern int manipulateState;
 
 // Directories containing models
 extern char *dirDefault1;
 
 // Directories containing models
 extern char *dirDefault1;
@@ -82,8 +85,9 @@ extern GLfloat emission[];
 extern int width, height;
 
 /* Zoom and rotate tracking */
 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;
 
 /* Texture state tracking */
 extern int currentGroundTexture, currentMeshTexture;
index ea80294..f6ecc8c 100644 (file)
--- a/helper.c
+++ b/helper.c
@@ -293,10 +293,10 @@ void drawAxisLines() {
   glEnable(GL_TEXTURE_2D);
 }
 
   glEnable(GL_TEXTURE_2D);
 }
 
-void addSceneObject(int id) {
+int addSceneObject(int id) {
   // **NOTE: Currently only adds the teapot
 
   // **NOTE: Currently only adds the teapot
 
-  nObjects += 1; // New object in scene
+  curObject = nObjects;
 
   sceneObjs[nObjects].mesh = -1;
   sceneObjs[nObjects].texture = -1;
 
   sceneObjs[nObjects].mesh = -1;
   sceneObjs[nObjects].texture = -1;
@@ -308,4 +308,8 @@ void addSceneObject(int id) {
 
   sceneObjs[nObjects].rotation.parameter = 0;
   sceneObjs[nObjects].rotation.vect = (vector*)calloc( 3, sizeof(vector[0]) );
 
   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
 }
\ No newline at end of file
index f6d86c8..c0c2462 100644 (file)
--- a/helper.h
+++ b/helper.h
@@ -24,6 +24,6 @@ void drawSquare(int recurseLevel, float x1, float z1, float x2, float z2);
 void drawFloor();
 void drawAxisLines();
 
 void drawFloor();
 void drawAxisLines();
 
-void addSceneObject(int id);
+int addSceneObject(int id);
 
 #endif /* HELPER_H */
 
 #endif /* HELPER_H */
diff --git a/scene.c b/scene.c
index 6ae85a7..e2e8cd2 100644 (file)
--- a/scene.c
+++ b/scene.c
@@ -198,15 +198,15 @@ void windowReshape(int w, int h) {
  * @param y Mouse y position\r
  */\r
 void mouse(int button, int state, int x, int y) {\r
  * @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
   }\r
 }\r
 \r
@@ -276,27 +276,47 @@ void keyboard(unsigned char key, int x, int y) {
  * @param y Mouse y position\r
  */\r
 void motion(int x, int y) {\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
+\r
+  glutPostRedisplay();\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -332,7 +352,7 @@ void display() {
     0.0,  10.0,  0.0   /* up is in postivie Y direction */\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
   /* Reposition the light source 0. */\r
   lightPosition0[0] = 12*cos(lightAngle0);\r
@@ -364,13 +384,43 @@ void display() {
 \r
     drawFloor();\r
     \r
 \r
     drawFloor();\r
     \r
-    // Draw teapot for a test object\r
+    // Draw sceneObjs array\r
     glPushMatrix();\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
     glPopMatrix();\r
 \r
     // Draw a white ball over the light source\r
diff --git a/types.h b/types.h
index 197eb03..91813ee 100644 (file)
--- a/types.h
+++ b/types.h
@@ -35,7 +35,7 @@ typedef struct {
 } texture;
 
 
 } texture;
 
 
-typedef GLfloat vector[3]; // Vector datatyle
+typedef GLfloat vector[3]; // Vector datatype
 
 typedef struct {
     GLfloat parameter;  // Transform amount
 
 typedef struct {
     GLfloat parameter;  // Transform amount
@@ -75,5 +75,11 @@ enum menu {
   M_LIGHT_RGBALL_LIGHT_2
 };
 
   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

UCC git Repository :: git.ucc.asn.au