(no commit message)
[atyndall/cits2231.git] / scene.c
diff --git a/scene.c b/scene.c
index c650c05..8d875b0 100644 (file)
--- a/scene.c
+++ b/scene.c
@@ -1,6 +1,6 @@
 /**\r
  * CITS2231 Graphics Scene Editor\r
- * @author Ashley Tyndall (20915779)\r
+ * @author Ashley Tyndall (20915779), Jenna de la Harpe (20367932)\r
  */\r
 \r
 #include <stdlib.h>\r
@@ -111,6 +111,7 @@ void processLightEvents(int id) {
  */\r
 void processObjectEvents(int id) {\r
   addSceneObject(id);\r
+  manipulateState = STATE_OBJECT_POSITION_SCALE;\r
   glutPostRedisplay();\r
 }\r
 \r
@@ -198,6 +199,9 @@ void windowReshape(int w, int h) {
  * @param y Mouse y position\r
  */\r
 void mouse(int button, int state, int x, int y) {\r
+  if ( button == GLUT_LEFT_BUTTON && glutGetModifiers() == GLUT_ACTIVE_SHIFT ) {\r
+    button = GLUT_MIDDLE_BUTTON; // Holding shift with left button is the same as the middle button\r
+  }\r
   switch(button) {\r
     case GLUT_LEFT_BUTTON:\r
     case GLUT_MIDDLE_BUTTON:\r
@@ -280,44 +284,64 @@ void keyboard(unsigned char key, int x, int y) {
 void motion(int x, int y) {\r
   if ( buttonSelected == -1 ) return; // No button selected, no action\r
 \r
+  float diffx = x - startx;\r
+  float diffy = y - starty;\r
+\r
   switch ( manipulateState ) {\r
     case STATE_CAMERA_ROTATE_MOVE:\r
-      rotate += (x - startx);\r
+      // w: rotate\r
+      rotate += diffx;\r
 \r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
-        // w: rotate, h: zoom\r
-        zoom += (y - starty);\r
+        // h: zoom\r
+        zoom += diffy;\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
-        // w: rotate, h: tilt\r
-        camAngle += (y - starty);\r
+        // h: tilt\r
+        camAngle += diffy;\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
+\r
+        // **NOTE: Currently a work in progress\r
+        printf("cam angle: %f\n", rotate*rotateFactor);\r
+        sceneObjs[curObject].x += diffx * sin(rotate*rotateFactor);\r
+        sceneObjs[curObject].z += diffx * cos(rotate*rotateFactor);\r
+\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
-        // w: big/small, h: up/down\r
+        // w: big/small\r
+        float max = (float)height/bigsmallFactor;\r
+        float scaling = (diffx + max) / max;\r
+\r
+        sceneObjs[curObject].scale[0] *= scaling;\r
+        sceneObjs[curObject].scale[1] *= scaling;\r
+        sceneObjs[curObject].scale[2] *= scaling;\r
+\r
+        // h: up/down\r
+        sceneObjs[curObject].y -= diffy * updownFactor;\r
       }\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
+        sceneObjs[curObject].rotation.x += diffy * rotateFactor;\r
+        sceneObjs[curObject].rotation.y += diffx * rotateFactor;\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
-        // w & h, rotate on h\r
+        // w: rotate on height, h: texture scale\r
+        \r
       }\r
       break;\r
 \r
   }\r
 \r
+  starty = y;\r
+  startx = x;\r
+\r
   glutPostRedisplay();\r
 }\r
 \r
@@ -354,7 +378,7 @@ void display() {
     0.0,  10.0,  0.0   /* up is in postivie Y direction */\r
     );\r
 \r
-  glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0);\r
+  glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0); // Set camera angle upward\r
 \r
   /* Reposition the light source 0. */\r
   lightPosition0[0] = 12*cos(lightAngle0);\r
@@ -391,8 +415,10 @@ void display() {
       glPushMatrix();\r
         SceneObject so = sceneObjs[i];\r
 \r
-        // Apply rotation vector\r
-        glRotatef(so.rotation.amount, so.rotation.vector[0], so.rotation.vector[1], so.rotation.vector[2]);\r
+        // Apply independant rotation vectors\r
+        glRotatef(so.rotation.x, 1.0, 0.0, 0.0);\r
+        glRotatef(so.rotation.y, 0.0, 1.0, 0.0);\r
+        glRotatef(so.rotation.z, 0.0, 0.0, 1.0);\r
 \r
         // Apply scaling vector\r
         glScalef(so.scale[0], so.scale[1], so.scale[2]);\r
@@ -423,24 +449,22 @@ void display() {
     }\r
     \r
 \r
-    // Draw a white ball over the light source\r
+    // Draw a white ball over the light sources\r
+    glDisable(GL_LIGHTING);\r
+    glColor3f(1.0, 1.0, 1.0);\r
+\r
     glPushMatrix();\r
-      glDisable(GL_LIGHTING);\r
-      glColor3f(1.0, 1.0, 1.0);\r
       glTranslatef(lightPosition0[0], lightPosition0[1], lightPosition0[2]);\r
       glutSolidSphere(0.5, 50, 50);\r
-      glEnable(GL_LIGHTING);\r
     glPopMatrix();\r
 \r
-    // Draw a white ball over the light source\r
     glPushMatrix();\r
-      glDisable(GL_LIGHTING);\r
-      glColor3f(1.0, 1.0, 1.0);\r
       glTranslatef(lightPosition1[0], lightPosition1[1], lightPosition1[2]);\r
       glutSolidSphere(0.5, 50, 50);\r
-      glEnable(GL_LIGHTING);\r
     glPopMatrix();\r
 \r
+    glEnable(GL_LIGHTING);\r
+\r
     drawAxisLines();\r
 \r
   glPopMatrix();\r

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