X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=99ccfa0b902ca7fdbc6102addaf2b1708302d733;hp=8d875b0237d05291fb2b040217d671405569dcb1;hb=97f14d98d0a9bee56fdaebcea092dba1925c9552;hpb=3f3a50c529bc7bf7b51939205c43606e8392cd49;ds=sidebyside diff --git a/scene.c b/scene.c index 8d875b0..99ccfa0 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,11 @@ 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 + printf("cam angle: %f\n", rotate*camRotateFactor); + // float arc = arctan() + sceneObjs[curObject].x += diffx * sin(rotate*camRotateFactor); + sceneObjs[curObject].z += diffx * cos(rotate*camRotateFactor); } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: big/small @@ -327,14 +328,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 += 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 +413,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 +427,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 +438,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 +462,6 @@ void display() { glBindTexture(GL_TEXTURE_2D, 0); glPopMatrix(); } - // Draw a white ball over the light sources glDisable(GL_LIGHTING); @@ -516,8 +530,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