(no commit message)
authorAsh Tyndall <[email protected]>
Sat, 22 Oct 2011 03:15:11 +0000 (11:15 +0800)
committerAsh Tyndall <[email protected]>
Sat, 22 Oct 2011 03:15:11 +0000 (11:15 +0800)
helper.c
scene.c
types.h

index 9cfb1fb..1e7c568 100644 (file)
--- a/helper.c
+++ b/helper.c
@@ -308,10 +308,9 @@ int addSceneObject(int id) {
   sceneObjs[nObjects].scale[1] = 1;
   sceneObjs[nObjects].scale[2] = 1;
 
   sceneObjs[nObjects].scale[1] = 1;
   sceneObjs[nObjects].scale[2] = 1;
 
-  sceneObjs[nObjects].rotation.amount = 0;
-  sceneObjs[nObjects].rotation.vector[0] = 0;
-  sceneObjs[nObjects].rotation.vector[1] = 0;
-  sceneObjs[nObjects].rotation.vector[2] = 0;
+  sceneObjs[nObjects].rotation.x = 0;
+  sceneObjs[nObjects].rotation.y = 0;
+  sceneObjs[nObjects].rotation.z = 0;
 
   nObjects += 1; // New object in scene
 
 
   nObjects += 1; // New object in scene
 
diff --git a/scene.c b/scene.c
index c6f3d2c..6f74153 100644 (file)
--- a/scene.c
+++ b/scene.c
@@ -284,55 +284,52 @@ 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
 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
       // w: rotate\r
   switch ( manipulateState ) {\r
     case STATE_CAMERA_ROTATE_MOVE:\r
       // w: rotate\r
-      rotate += (x - startx);\r
+      rotate += diffx;\r
 \r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
         // h: zoom\r
 \r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
         // h: zoom\r
-        zoom += (y - starty);\r
+        zoom += diffy;\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
         // h: tilt\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
         // h: tilt\r
-        camAngle += (y - starty);\r
+        camAngle += diffy;\r
       }\r
       }\r
-\r
-      starty = y;\r
-      startx = x;\r
-\r
       break;\r
 \r
     case STATE_OBJECT_POSITION_SCALE:\r
       break;\r
 \r
     case STATE_OBJECT_POSITION_SCALE:\r
-     \r
+\r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
         // w: left/right, h: near/far\r
       if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
         // w: left/right, h: near/far\r
-         //so.x, so.y, so.z\r
-        //sceneObjs[curObject].x += (x - startx)*leftrightFactor;\r
+\r
+        // **NOTE: Currently a work in progress\r
         printf("cam angle: %f\n", rotate*rotateFactor);\r
         printf("cam angle: %f\n", rotate*rotateFactor);\r
-        sceneObjs[curObject].x = (x - startx) * sin(rotate*rotateFactor);\r
-        sceneObjs[curObject].z = (x - startx) * cos(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\r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
         // w: big/small\r
-        float diff = (x - startx);\r
         float max = (float)height/bigsmallFactor;\r
         float max = (float)height/bigsmallFactor;\r
-        float scaling = ( diff + max) / max;\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
 \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
+        sceneObjs[curObject].y -= diffy * updownFactor;\r
       }\r
 \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
       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 += diffx * rotateFactor;\r
 \r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
         // w: rotate on height, h: texture scale\r
 \r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
         // w: rotate on height, h: texture scale\r
@@ -342,6 +339,9 @@ void motion(int x, int y) {
 \r
   }\r
 \r
 \r
   }\r
 \r
+  starty = y;\r
+  startx = x;\r
+\r
   glutPostRedisplay();\r
 }\r
 \r
   glutPostRedisplay();\r
 }\r
 \r
@@ -415,8 +415,10 @@ void display() {
       glPushMatrix();\r
         SceneObject so = sceneObjs[i];\r
 \r
       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
 \r
         // Apply scaling vector\r
         glScalef(so.scale[0], so.scale[1], so.scale[2]);\r
@@ -447,24 +449,22 @@ void display() {
     }\r
     \r
 \r
     }\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
     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
       glTranslatef(lightPosition0[0], lightPosition0[1], lightPosition0[2]);\r
       glutSolidSphere(0.5, 50, 50);\r
-      glEnable(GL_LIGHTING);\r
     glPopMatrix();\r
 \r
     glPopMatrix();\r
 \r
-    // Draw a white ball over the light source\r
     glPushMatrix();\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
       glTranslatef(lightPosition1[0], lightPosition1[1], lightPosition1[2]);\r
       glutSolidSphere(0.5, 50, 50);\r
-      glEnable(GL_LIGHTING);\r
     glPopMatrix();\r
 \r
     glPopMatrix();\r
 \r
+    glEnable(GL_LIGHTING);\r
+\r
     drawAxisLines();\r
 \r
   glPopMatrix();\r
     drawAxisLines();\r
 \r
   glPopMatrix();\r
diff --git a/types.h b/types.h
index be7c1e4..3c0b75b 100644 (file)
--- a/types.h
+++ b/types.h
@@ -35,14 +35,13 @@ typedef struct {
 } texture;
 
 typedef struct {
 } texture;
 
 typedef struct {
-    GLfloat amount;     // Transform amount
-    GLfloat vector[3];  // Transform vector
+    GLfloat x, y, z;    // Amount of rotation on axis
 } transform;
 
 typedef struct {
     int mesh;           // Mesh index number
     int texture;        // Texture index number
 } transform;
 
 typedef struct {
     int mesh;           // Mesh index number
     int texture;        // Texture index number
-    float x,y,z;        // Scene position
+    GLfloat x,y,z;        // Scene position
     GLfloat scale[3];   // Scale vector
     transform rotation; // Rotation transformation
 } SceneObject;
     GLfloat scale[3];   // Scale vector
     transform rotation; // Rotation transformation
 } SceneObject;

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