(no commit message)
[atyndall/cits2231.git] / scene.c
diff --git a/scene.c b/scene.c
index 8d875b0..9a803cb 100644 (file)
--- a/scene.c
+++ b/scene.c
@@ -121,7 +121,7 @@ void processObjectEvents(int id) {
  */\r
 void processTextureEvents(int id) {\r
   if ( curObject >= 0 ) {\r
-    sceneObjs[curObject].texture = id;\r
+    sceneObjs[curObject].texture.id = id;\r
     glutPostRedisplay();\r
   }\r
 }\r
@@ -153,8 +153,8 @@ void makeMenu() {
   // Construct light menu\r
   int lightMenu = glutCreateMenu(processLightEvents);\r
   glutAddMenuEntry("Move Light 1", M_LIGHT_MOVE_LIGHT_1);\r
-  glutAddMenuEntry("R/G/B/All Light 1", M_LIGHT_RGBALL_LIGHT_1);\r
-  glutAddMenuEntry("Move Light 2", M_LIGHT_MOVE_LIGHT_2);\r
+  //glutAddMenuEntry("R/G/B/All Light 1", M_LIGHT_RGBALL_LIGHT_1);\r
+  //glutAddMenuEntry("Move Light 2", M_LIGHT_MOVE_LIGHT_2);\r
   glutAddMenuEntry("R/G/B/All Light 2", M_LIGHT_RGBALL_LIGHT_2);\r
 \r
   // Construct object menu\r
@@ -173,7 +173,7 @@ void makeMenu() {
   //glutAddSubMenu("Material", materialMenu);\r
   glutAddSubMenu("Texture", textureMenu);\r
   glutAddSubMenu("Ground texture", gTextureMenu);\r
-  //glutAddSubMenu("Lights", lightMenu);\r
+  glutAddSubMenu("Lights", lightMenu);\r
   glutAddMenuEntry("Exit", M_EXIT);\r
 \r
   // Bind to right mouse button\r
@@ -305,11 +305,9 @@ void motion(int x, int y) {
 \r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
         // w: left/right, h: near/far\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
+        float angler = 2 * M_PI * ( (rotate*camRotateFactor)/360.0 );\r
+        sceneObjs[curObject].x += diffx * cos(angler) * leftrightFactor + diffy * cos(M_PI/2 + angler) * nearfarFactor;\r
+        sceneObjs[curObject].z += diffx * sin(angler) * leftrightFactor + diffy * sin(M_PI/2 + angler) * nearfarFactor;\r
 \r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
         // w: big/small\r
@@ -327,14 +325,25 @@ void motion(int x, int y) {
       break;\r
 \r
     case STATE_OBJECT_ROTATION_TEXTURE_SCALE:\r
+\r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
-        // w: rotate on width, h: rotate on h\r
-        sceneObjs[curObject].rotation.x += diffy * rotateFactor;\r
+        // w: rotate on y\r
         sceneObjs[curObject].rotation.y += diffx * rotateFactor;\r
+\r
+        // h: rotate on x\r
+        sceneObjs[curObject].rotation.x += diffy * rotateFactor;\r
+\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
-        // w: rotate on height, h: texture scale\r
-        \r
+        // w: rotate on x\r
+        sceneObjs[curObject].rotation.x += diffx * rotateFactor;\r
+\r
+        // h: texture scale\r
+        float max = (float)height/texscaleFactor;\r
+        float scaling = (diffy + max) / max;\r
+        sceneObjs[curObject].texture.scale *= scaling;\r
+\r
       }\r
+      \r
       break;\r
 \r
   }\r
@@ -401,7 +410,7 @@ void display() {
   glPushMatrix();\r
 \r
     /* Perform scene rotations based on user mouse/keyboard input. */\r
-    glRotatef(rotate*rotateFactor, 0.0, 1.0, 0.0);\r
+    glRotatef(rotate*camRotateFactor, 0.0, 1.0, 0.0);\r
     glTranslatef(camx, camy, camz);\r
     glRotatef(keyrot, 1.0, 0.0, 0.0);\r
 \r
@@ -415,6 +424,9 @@ void display() {
       glPushMatrix();\r
         SceneObject so = sceneObjs[i];\r
 \r
+        // Apply translation vector\r
+        glTranslatef(so.x, so.y, so.z);\r
+\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
@@ -423,13 +435,13 @@ void display() {
         // 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
-\r
         // Apply texture\r
-        if ( so.texture > 0 ) {\r
-          getTexture(so.texture);\r
-          glBindTexture(GL_TEXTURE_2D, so.texture);\r
+        if ( so.texture.id > 0 ) {\r
+          getTexture(so.texture.id);\r
+          glBindTexture(GL_TEXTURE_2D, so.texture.id);\r
+          glMatrixMode(GL_TEXTURE);\r
+          glScalef(so.texture.scale, so.texture.scale, so.texture.scale);\r
+          glMatrixMode(GL_MODELVIEW);\r
         } else {\r
           glBindTexture(GL_TEXTURE_2D, 0);\r
         }\r
@@ -447,7 +459,6 @@ void display() {
         glBindTexture(GL_TEXTURE_2D, 0);\r
       glPopMatrix();\r
     }\r
-    \r
 \r
     // Draw a white ball over the light sources\r
     glDisable(GL_LIGHTING);\r
@@ -455,12 +466,12 @@ void display() {
 \r
     glPushMatrix();\r
       glTranslatef(lightPosition0[0], lightPosition0[1], lightPosition0[2]);\r
-      glutSolidSphere(0.5, 50, 50);\r
+      glutSolidSphere(lightBallSize, 20, 20);\r
     glPopMatrix();\r
 \r
     glPushMatrix();\r
       glTranslatef(lightPosition1[0], lightPosition1[1], lightPosition1[2]);\r
-      glutSolidSphere(0.5, 50, 50);\r
+      glutSolidSphere(lightBallSize, 20, 20);\r
     glPopMatrix();\r
 \r
     glEnable(GL_LIGHTING);\r
@@ -516,8 +527,8 @@ int main(int argc, char **argv) {
 \r
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);\r
 \r
-  glutInitWindowSize(500, 500);\r
-  glutCreateWindow("Scene Editor");\r
+  glutInitWindowSize(width, height);\r
+  glutCreateWindow("Scene Editor - Ashley Tyndall (20915779), Jenna de la Harpe (20367932)");\r
 \r
   glShadeModel(GL_SMOOTH); // Enables Smooth Shading\r
   glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background\r

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