(no commit message)
[atyndall/cits2231.git] / scene.c
diff --git a/scene.c b/scene.c
index 6f14e04..618c1ae 100644 (file)
--- a/scene.c
+++ b/scene.c
@@ -87,7 +87,7 @@ void processMaterialEvents(int id) {
 void processLightEvents(int id) {\r
   switch (id) {\r
     case M_LIGHT_MOVE_LIGHT_1:\r
-      // Do stuff\r
+      manipulateState = STATE_LIGHT_1_MOVE;\r
       break;\r
 \r
     case M_LIGHT_RGBALL_LIGHT_1:\r
@@ -95,7 +95,7 @@ void processLightEvents(int id) {
       break;\r
 \r
     case M_LIGHT_MOVE_LIGHT_2:\r
-      // Do stuff\r
+      manipulateState = STATE_LIGHT_2_MOVE;\r
       break;\r
 \r
     case M_LIGHT_RGBALL_LIGHT_2:\r
@@ -346,6 +346,29 @@ void motion(int x, int y) {
       \r
       break;\r
 \r
+    case STATE_LIGHT_1_MOVE:\r
+    case STATE_LIGHT_2_MOVE:\r
+      ; // Semi-colon required to allow variable declaration below\r
+      \r
+      int i = 0;\r
+      if ( manipulateState == STATE_LIGHT_2_MOVE ) i = 1;\r
+\r
+      if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
+        // w: left/right, h: near/far\r
+        float angler = 2 * M_PI * ( (rotate*camRotateFactor)/360.0 );\r
+        lightObjs[i].position[0] += diffx * cos(angler) * lleftrightFactor + diffy * cos(M_PI/2 + angler) * lnearfarFactor;\r
+        lightObjs[i].position[2] += diffx * sin(angler) * lleftrightFactor + diffy * sin(M_PI/2 + angler) * lnearfarFactor;\r
+\r
+      } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
+        // w: increase/decrease some light param\r
+        // **NOTE: Currently not implemented\r
+\r
+        // h: up/down\r
+        lightObjs[i].position[1] -= diffy * updownFactor;\r
+      }\r
+\r
+      break;\r
+\r
   }\r
 \r
   starty = y;\r
@@ -389,21 +412,6 @@ void display() {
 \r
   glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0); // Set camera angle upward\r
 \r
-  /* Reposition the light source 0. */\r
-  lightObjs[0].position[0] = 9*cos(45);\r
-  lightObjs[0].position[1] = 5;\r
-  lightObjs[0].position[2] = 9*sin(45);\r
-  lightObjs[0].position[3] = 0.0;\r
-\r
-  /* Reposition the light source 1. */\r
-  lightObjs[1].position[0] = 9*cos(45 + 90);\r
-  lightObjs[1].position[1] = 5;\r
-  lightObjs[1].position[2] = 9*sin(45 + 90);\r
-  lightObjs[1].position[3] = 0.0;\r
-\r
-  //direction0[0] = lightPosition0[0];\r
-  //direction0[2] = lightPosition0[2];\r
-\r
   glPushMatrix();\r
 \r
     /* Perform scene rotations based on user mouse/keyboard input. */\r
@@ -509,5 +517,17 @@ int main(int argc, char **argv) {
 \r
   initializeLights();\r
 \r
+  /* Initial light 0 position. */\r
+  lightObjs[0].position[0] = 4;\r
+  lightObjs[0].position[1] = 5;\r
+  lightObjs[0].position[2] = 6;\r
+  lightObjs[0].position[3] = 0.0;\r
+\r
+  /* Initial light 1 position. */\r
+  lightObjs[1].position[0] = -4;\r
+  lightObjs[1].position[1] = 5;\r
+  lightObjs[1].position[2] = -6;\r
+  lightObjs[1].position[3] = 0.0;\r
+\r
   glutMainLoop();\r
 }
\ No newline at end of file

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