X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=d581f44d4d6d91e429e678ccf0e959658c406afd;hp=6f74153d176ed43babe4a7cb788b9b89e4fdefe1;hb=e2732074b7b13b6e9a8ad9c8351c1707e9170daa;hpb=bc7b210b34ea0d6fb40bd163955a50d80db3a11e diff --git a/scene.c b/scene.c index 6f74153..d581f44 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(); } } @@ -306,10 +306,18 @@ 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*rotateFactor); - sceneObjs[curObject].x += diffx * sin(rotate*rotateFactor); - sceneObjs[curObject].z += diffx * cos(rotate*rotateFactor); + // **NOTE: Currently a work in progress, does not work correctly + float angler = 2 * M_PI * ( (rotate*camRotateFactor)/360.0 ); + printf("cam angle: %f\n", rotate*camRotateFactor); + + //sceneObjs[curObject].x += diffx * cos(angler) * 0.1; + sceneObjs[curObject].x += diffy * sin(angler) * 0.1; + + //sceneObjs[curObject].z += diffx * sin(angler) * 0.1; + sceneObjs[curObject].z += diffy * cos(angler) * 0.1; + + //sceneObjs[curObject].x += ; + //sceneObjs[curObject].z += ; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: big/small @@ -327,14 +335,25 @@ void motion(int x, int y) { 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; + // 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 +420,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); @@ -415,6 +434,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); @@ -423,13 +445,13 @@ 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 > 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); } @@ -447,7 +469,6 @@ void display() { glBindTexture(GL_TEXTURE_2D, 0); glPopMatrix(); } - // Draw a white ball over the light sources glDisable(GL_LIGHTING); @@ -516,8 +537,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