X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=8d875b0237d05291fb2b040217d671405569dcb1;hp=49661b14a2ce786b87cce1c044ac7d3c299a4f0b;hb=3f3a50c529bc7bf7b51939205c43606e8392cd49;hpb=fe589a3051db988450daaf58dd76b2fb321abdba diff --git a/scene.c b/scene.c index 49661b1..8d875b0 100644 --- a/scene.c +++ b/scene.c @@ -284,53 +284,53 @@ 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 += 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 += diffy * rotateFactor; + sceneObjs[curObject].rotation.y += diffx * rotateFactor; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: rotate on height, h: texture scale @@ -339,6 +339,9 @@ void motion(int x, int y) { } + starty = y; + startx = x; + glutPostRedisplay(); } @@ -375,7 +378,7 @@ void display() { 0.0, 10.0, 0.0 /* up is in postivie Y direction */ ); - glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0); + glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0); // Set camera angle upward /* Reposition the light source 0. */ lightPosition0[0] = 12*cos(lightAngle0); @@ -412,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]); @@ -444,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();