X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=57803e56aa52f479d83ef5b7066fece38a930337;hp=a0fbff18df54e6e473c8f518462e5a2dd1ce3bf8;hb=cbe1aa264b15c345870500646003c777e4bdef03;hpb=295ff719ec8db6df738d0210005a948eb2507c77 diff --git a/scene.c b/scene.c index a0fbff1..57803e5 100644 --- a/scene.c +++ b/scene.c @@ -305,11 +305,9 @@ void motion(int x, int y) { if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: left/right, h: near/far - - // **NOTE: Currently a work in progress - printf("cam angle: %f\n", rotate*camRotateFactor); - sceneObjs[curObject].x += diffx * sin(rotate*camRotateFactor); - sceneObjs[curObject].z += diffx * cos(rotate*camRotateFactor); + float angler = 2 * M_PI * ( (rotate*camRotateFactor)/360.0 ); + sceneObjs[curObject].x += diffx * cos(angler) * leftrightFactor + diffy * cos(M_PI/2 + angler) * nearfarFactor; + sceneObjs[curObject].z += diffx * sin(angler) * leftrightFactor + diffy * sin(M_PI/2 + angler) * nearfarFactor; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: big/small @@ -327,19 +325,25 @@ void motion(int x, int y) { break; case STATE_OBJECT_ROTATION_TEXTURE_SCALE: + if ( buttonSelected == GLUT_LEFT_BUTTON ) { // 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 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; } @@ -420,6 +424,9 @@ void display() { glPushMatrix(); SceneObject so = sceneObjs[i]; + // Apply translation vector + glTranslatef(so.x, so.y, so.z); + // Apply independant rotation vectors glRotatef(so.rotation.x, 1.0, 0.0, 0.0); glRotatef(so.rotation.y, 0.0, 1.0, 0.0); @@ -428,9 +435,6 @@ void display() { // Apply scaling vector glScalef(so.scale[0], so.scale[1], so.scale[2]); - // Apply translation vector - glTranslatef(so.x, so.y, so.z); - // Apply texture if ( so.texture.id > 0 ) { getTexture(so.texture.id); @@ -455,7 +459,6 @@ void display() { glBindTexture(GL_TEXTURE_2D, 0); glPopMatrix(); } - // Draw a white ball over the light sources glDisable(GL_LIGHTING); @@ -524,8 +527,8 @@ int main(int argc, char **argv) { glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); - glutInitWindowSize(500, 500); - glutCreateWindow("Scene Editor"); + glutInitWindowSize(width, height); + glutCreateWindow("Scene Editor - Ashley Tyndall (20915779), Jenna de la Harpe (20367932)"); glShadeModel(GL_SMOOTH); // Enables Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background