From: Ash Tyndall Date: Sat, 22 Oct 2011 03:15:11 +0000 (+0800) Subject: (no commit message) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=bc7b210b34ea0d6fb40bd163955a50d80db3a11e;p=atyndall%2Fcits2231.git --- diff --git a/helper.c b/helper.c index 9cfb1fb..1e7c568 100644 --- 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].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 diff --git a/scene.c b/scene.c index c6f3d2c..6f74153 100644 --- 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) { if ( buttonSelected == -1 ) return; // No button selected, no action + float diffx = x - startx; + float diffy = y - starty; + switch ( manipulateState ) { case STATE_CAMERA_ROTATE_MOVE: // w: rotate - rotate += (x - startx); + rotate += diffx; if ( buttonSelected == GLUT_LEFT_BUTTON ) { // h: zoom - zoom += (y - starty); + zoom += diffy; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // h: tilt - camAngle += (y - starty); + camAngle += diffy; } - - starty = y; - startx = x; - break; case STATE_OBJECT_POSITION_SCALE: - + if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: left/right, h: near/far - //so.x, so.y, so.z - //sceneObjs[curObject].x += (x - startx)*leftrightFactor; + + // **NOTE: Currently a work in progress printf("cam angle: %f\n", rotate*rotateFactor); - sceneObjs[curObject].x = (x - startx) * sin(rotate*rotateFactor); - sceneObjs[curObject].z = (x - startx) * cos(rotate*rotateFactor); + sceneObjs[curObject].x += diffx * sin(rotate*rotateFactor); + sceneObjs[curObject].z += diffx * cos(rotate*rotateFactor); + } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: big/small - float diff = (x - startx); float max = (float)height/bigsmallFactor; - float scaling = ( diff + max) / max; + float scaling = (diffx + max) / max; sceneObjs[curObject].scale[0] *= scaling; sceneObjs[curObject].scale[1] *= scaling; sceneObjs[curObject].scale[2] *= scaling; // h: up/down - sceneObjs[curObject].y -= (y - starty) * updownFactor; + sceneObjs[curObject].y -= diffy * updownFactor; } - starty = y; - startx = x; - break; case STATE_OBJECT_ROTATION_TEXTURE_SCALE: if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: rotate on width, h: rotate on h + sceneObjs[curObject].rotation.x += diffx * rotateFactor; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: rotate on height, h: texture scale @@ -342,6 +339,9 @@ void motion(int x, int y) { } + starty = y; + startx = x; + glutPostRedisplay(); } @@ -415,8 +415,10 @@ void display() { glPushMatrix(); SceneObject so = sceneObjs[i]; - // Apply rotation vector - glRotatef(so.rotation.amount, so.rotation.vector[0], so.rotation.vector[1], so.rotation.vector[2]); + // Apply independant rotation vectors + glRotatef(so.rotation.x, 1.0, 0.0, 0.0); + glRotatef(so.rotation.y, 0.0, 1.0, 0.0); + glRotatef(so.rotation.z, 0.0, 0.0, 1.0); // Apply scaling vector glScalef(so.scale[0], so.scale[1], so.scale[2]); @@ -447,24 +449,22 @@ void display() { } - // Draw a white ball over the light source + // Draw a white ball over the light sources + glDisable(GL_LIGHTING); + glColor3f(1.0, 1.0, 1.0); + glPushMatrix(); - glDisable(GL_LIGHTING); - glColor3f(1.0, 1.0, 1.0); glTranslatef(lightPosition0[0], lightPosition0[1], lightPosition0[2]); glutSolidSphere(0.5, 50, 50); - glEnable(GL_LIGHTING); glPopMatrix(); - // Draw a white ball over the light source glPushMatrix(); - glDisable(GL_LIGHTING); - glColor3f(1.0, 1.0, 1.0); glTranslatef(lightPosition1[0], lightPosition1[1], lightPosition1[2]); glutSolidSphere(0.5, 50, 50); - glEnable(GL_LIGHTING); glPopMatrix(); + glEnable(GL_LIGHTING); + drawAxisLines(); glPopMatrix(); diff --git a/types.h b/types.h index be7c1e4..3c0b75b 100644 --- a/types.h +++ b/types.h @@ -35,14 +35,13 @@ 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 - float x,y,z; // Scene position + GLfloat x,y,z; // Scene position GLfloat scale[3]; // Scale vector transform rotation; // Rotation transformation } SceneObject;