From: Ash Tyndall Date: Sat, 22 Oct 2011 03:24:59 +0000 (+0800) Subject: (no commit message) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=295ff719ec8db6df738d0210005a948eb2507c77;p=atyndall%2Fcits2231.git --- diff --git a/globals.c b/globals.c index 948327e..c79395a 100644 --- 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; diff --git a/globals.h b/globals.h index c7d62d2..5dd4300 100644 --- 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; diff --git a/helper.c b/helper.c index 1e7c568..ab96c88 100644 --- 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 --- a/scene.c +++ b/scene.c @@ -121,7 +121,7 @@ void processObjectEvents(int id) { */ void processTextureEvents(int id) { if ( curObject >= 0 ) { - sceneObjs[curObject].texture = id; + sceneObjs[curObject].texture.id = id; glutPostRedisplay(); } } @@ -307,9 +307,9 @@ void motion(int x, int y) { // w: left/right, h: near/far // **NOTE: Currently a work in progress - printf("cam angle: %f\n", rotate*rotateFactor); - sceneObjs[curObject].x += diffx * sin(rotate*rotateFactor); - sceneObjs[curObject].z += diffx * cos(rotate*rotateFactor); + printf("cam angle: %f\n", rotate*camRotateFactor); + sceneObjs[curObject].x += diffx * sin(rotate*camRotateFactor); + sceneObjs[curObject].z += diffx * cos(rotate*camRotateFactor); } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: big/small @@ -328,12 +328,17 @@ void motion(int x, int y) { case STATE_OBJECT_ROTATION_TEXTURE_SCALE: if ( buttonSelected == GLUT_LEFT_BUTTON ) { - // w: rotate on width, h: rotate on h - sceneObjs[curObject].rotation.x += diffy * rotateFactor; + // w: rotate on y sceneObjs[curObject].rotation.y += diffx * rotateFactor; + // h: rotate on x + sceneObjs[curObject].rotation.x += diffy * rotateFactor; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { - // w: rotate on height, h: texture scale - + // w: rotate on x + sceneObjs[curObject].rotation.x += diffx * rotateFactor; + // h: texture scale + float max = (float)height/texscaleFactor; + float scaling = (diffy + max) / max; + sceneObjs[curObject].texture.scale *= scaling; } break; @@ -401,7 +406,7 @@ void display() { glPushMatrix(); /* Perform scene rotations based on user mouse/keyboard input. */ - glRotatef(rotate*rotateFactor, 0.0, 1.0, 0.0); + glRotatef(rotate*camRotateFactor, 0.0, 1.0, 0.0); glTranslatef(camx, camy, camz); glRotatef(keyrot, 1.0, 0.0, 0.0); @@ -427,9 +432,12 @@ void display() { glTranslatef(so.x, so.y, so.z); // Apply texture - if ( so.texture > 0 ) { - getTexture(so.texture); - glBindTexture(GL_TEXTURE_2D, so.texture); + if ( so.texture.id > 0 ) { + getTexture(so.texture.id); + glBindTexture(GL_TEXTURE_2D, so.texture.id); + glMatrixMode(GL_TEXTURE); + glScalef(so.texture.scale, so.texture.scale, so.texture.scale); + glMatrixMode(GL_MODELVIEW); } else { glBindTexture(GL_TEXTURE_2D, 0); } diff --git a/types.h b/types.h index 3c0b75b..0d7110e 100644 --- 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;