/* 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;
/* 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;
*/\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
// 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
\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
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
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
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;