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

index 948327e..c79395a 100644 (file)
--- a/globals.c
+++ b/globals.c
@@ -91,8 +91,8 @@ GLfloat emission[] = {0.0, 0.3, 0.3, 1.0};
 
 /* Zoom and rotate tracking */
 GLfloat zoom = 0.0, rotate = 0.0, camAngle = 40.0;
-GLfloat zoomFactor = 0.2, rotateFactor = 0.5, camAngleFactor = 0.5;
-GLfloat leftrightFactor = 0.5, nearfarFactor = 0.5, bigsmallFactor = 0.6, updownFactor = 0.03;
+GLfloat zoomFactor = 0.2, camRotateFactor = 0.5, camAngleFactor = 0.5;
+GLfloat leftrightFactor = 0.5, nearfarFactor = 0.5, bigsmallFactor = 0.6, updownFactor = 0.03, rotateFactor = 0.8, texscaleFactor = 0.5;
 
 /* Beginning width, height */
 int width = 500, height = 500;
index c7d62d2..5dd4300 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -83,8 +83,8 @@ extern int width, height;
 
 /* Zoom and rotate tracking */
 extern GLfloat zoom, rotate, camAngle;
-extern GLfloat zoomFactor, rotateFactor, camAngleFactor;
-extern GLfloat leftrightFactor, nearfarFactor, bigsmallFactor, updownFactor;
+extern GLfloat zoomFactor, camRotateFactor, camAngleFactor;
+extern GLfloat leftrightFactor, nearfarFactor, bigsmallFactor, updownFactor, rotateFactor, texscaleFactor;
 
 /* Texture state tracking */
 extern int currentGroundTexture, currentMeshTexture;
index 1e7c568..ab96c88 100644 (file)
--- a/helper.c
+++ b/helper.c
@@ -299,7 +299,8 @@ int addSceneObject(int id) {
   curObject = nObjects;
 
   sceneObjs[nObjects].mesh = -1; // Teapot is -1 mesh
-  sceneObjs[nObjects].texture = -1; // No texture
+  sceneObjs[nObjects].texture.id = -1; // No texture
+  sceneObjs[nObjects].texture.scale = 1;
   sceneObjs[nObjects].x = 0;
   sceneObjs[nObjects].y = 0;
   sceneObjs[nObjects].z = 0;
diff --git a/scene.c b/scene.c
index 8d875b0..a0fbff1 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
@@ -307,9 +307,9 @@ void motion(int x, int y) {
         // 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
+        printf("cam angle: %f\n", rotate*camRotateFactor);\r
+        sceneObjs[curObject].x += diffx * sin(rotate*camRotateFactor);\r
+        sceneObjs[curObject].z += diffx * cos(rotate*camRotateFactor);\r
 \r
       } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
         // w: big/small\r
@@ -328,12 +328,17 @@ void motion(int x, int y) {
 \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
+        // w: rotate on y\r
         sceneObjs[curObject].rotation.y += diffx * rotateFactor;\r
+        // h: rotate on x\r
+        sceneObjs[curObject].rotation.x += diffy * rotateFactor;\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
+        // h: texture scale\r
+        float max = (float)height/texscaleFactor;\r
+        float scaling = (diffy + max) / max;\r
+        sceneObjs[curObject].texture.scale *= scaling;\r
       }\r
       break;\r
 \r
@@ -401,7 +406,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
@@ -427,9 +432,12 @@ void display() {
         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
diff --git a/types.h b/types.h
index 3c0b75b..0d7110e 100644 (file)
--- a/types.h
+++ b/types.h
@@ -38,10 +38,15 @@ typedef struct {
     GLfloat x, y, z;    // Amount of rotation on axis
 } transform;
 
+typedef struct {
+    int id;
+    GLfloat scale;
+} texturedat;
+
 typedef struct {
     int mesh;           // Mesh index number
-    int texture;        // Texture index number
-    GLfloat x,y,z;        // Scene position
+    texturedat texture; // Texture index number
+    GLfloat x,y,z;      // Scene position
     GLfloat scale[3];   // Scale vector
     transform rotation; // Rotation transformation
 } SceneObject;

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