X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=eefeec1d5359f35fc00e76105bc8f3af1d486845;hp=8d875b0237d05291fb2b040217d671405569dcb1;hb=0bf9a194f13fd3e429d83da842d5107db8dbf967;hpb=3f3a50c529bc7bf7b51939205c43606e8392cd49 diff --git a/scene.c b/scene.c index 8d875b0..eefeec1 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,10 @@ 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); + 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 +327,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 +412,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); @@ -427,9 +438,12 @@ void display() { 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); } @@ -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