(no commit message)
[atyndall/cits2231.git] / scene.c
diff --git a/scene.c b/scene.c
index 0251439..b724f24 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
@@ -110,8 +110,8 @@ void processLightEvents(int id) {
  * @param id ID of object selected\r
  */\r
 void processObjectEvents(int id) {\r
-  // **NOTE: For the testing phase, only have the teapot\r
   addSceneObject(id);\r
+  manipulateState = STATE_OBJECT_POSITION_SCALE;\r
   glutPostRedisplay();\r
 }\r
 \r
@@ -120,7 +120,10 @@ void processObjectEvents(int id) {
  * @param id ID of texutre selected\r
  */\r
 void processTextureEvents(int id) {\r
-\r
+  if ( curObject >= 0 ) {\r
+    sceneObjs[curObject].texture = id;\r
+    glutPostRedisplay();\r
+  }\r
 }\r
 \r
 /**\r
@@ -168,7 +171,7 @@ void makeMenu() {
   glutAddMenuEntry("Position/Scale", M_POSITION_SCALE);\r
   glutAddMenuEntry("Rotation/Texture Scale", M_ROTATION_TEXTURE_SCALE);\r
   //glutAddSubMenu("Material", materialMenu);\r
-  //glutAddSubMenu("Texture", textureMenu);\r
+  glutAddSubMenu("Texture", textureMenu);\r
   glutAddSubMenu("Ground texture", gTextureMenu);\r
   //glutAddSubMenu("Lights", lightMenu);\r
   glutAddMenuEntry("Exit", M_EXIT);\r
@@ -196,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,13 +286,14 @@ void motion(int x, int y) {
 \r
   switch ( manipulateState ) {\r
     case STATE_CAMERA_ROTATE_MOVE:\r
+      // w: rotate\r
       rotate += (x - startx);\r
 \r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
-        // w: rotate, h: zoom\r
+        // h: zoom\r
         zoom += (y - starty);\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
-        // w: rotate, h: tilt\r
+        // h: tilt\r
         camAngle += (y - starty);\r
       }\r
 \r
@@ -296,21 +303,40 @@ void motion(int x, int y) {
       break;\r
 \r
     case STATE_OBJECT_POSITION_SCALE:\r
-      //SceneObject co = sceneObjs[curObject];\r
-\r
+     \r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
         // w: left/right, h: near/far\r
-        \r
+         //so.x, so.y, so.z\r
+        //sceneObjs[curObject].x += (x - startx)*leftrightFactor;\r
+        printf("cam angle: %f\n", camAngle*camAngleFactor);\r
+        sceneObjs[curObject].x += (x - startx) * sin(90 - camAngle*camAngleFactor);\r
+        sceneObjs[curObject].z += (x - startx) * cos(90 - camAngle*camAngleFactor);\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
-        // w: big/small, h: up/down\r
+        // w: big/small\r
+        float diff = (x - startx);\r
+        float max = (float)height/bigsmallFactor;\r
+        float scaling = ( diff + 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 -= (y - starty) * updownFactor;\r
       }\r
+\r
+      starty = y;\r
+      startx = x;\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
+\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
@@ -352,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
@@ -390,13 +416,13 @@ void display() {
         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
+        glRotatef(so.rotation.amount, so.rotation.vector[0], so.rotation.vector[1], so.rotation.vector[2]);\r
 \r
         // Apply scaling vector\r
         glScalef(so.scale[0], so.scale[1], so.scale[2]);\r
 \r
         // Apply translation vector\r
-        //glTranslatef(so.x, so.y, so.z);\r
+        glTranslatef(so.x, so.y, so.z);\r
 \r
         // Apply texture\r
         if ( so.texture > 0 ) {\r

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