X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=a8d9596c57cba66c849a537877481abee49d1cc2;hp=386586e549f2e1656f3f6d9a73095ad7a7ec90e5;hb=fe551bcf4f464576a9e1e76acc83ba24d0bfe63c;hpb=d6176afd69975dd4fd1a474db49995b4066a8548 diff --git a/scene.c b/scene.c index 386586e..a8d9596 100644 --- a/scene.c +++ b/scene.c @@ -1,6 +1,6 @@ /** * CITS2231 Graphics Scene Editor - * @author Ashley Tyndall (20915779) + * @author Ashley Tyndall (20915779), Jenna de la Harpe (20367932) */ #include @@ -110,8 +110,9 @@ void processLightEvents(int id) { * @param id ID of object selected */ void processObjectEvents(int id) { - // **NOTE: For the testing phase, only have the teapot addSceneObject(id); + manipulateState = STATE_OBJECT_POSITION_SCALE; + glutPostRedisplay(); } /** @@ -119,7 +120,10 @@ void processObjectEvents(int id) { * @param id ID of texutre selected */ void processTextureEvents(int id) { - + if ( curObject >= 0 ) { + sceneObjs[curObject].texture = id; + glutPostRedisplay(); + } } /** @@ -167,7 +171,7 @@ void makeMenu() { glutAddMenuEntry("Position/Scale", M_POSITION_SCALE); glutAddMenuEntry("Rotation/Texture Scale", M_ROTATION_TEXTURE_SCALE); //glutAddSubMenu("Material", materialMenu); - //glutAddSubMenu("Texture", textureMenu); + glutAddSubMenu("Texture", textureMenu); glutAddSubMenu("Ground texture", gTextureMenu); //glutAddSubMenu("Lights", lightMenu); glutAddMenuEntry("Exit", M_EXIT); @@ -195,6 +199,9 @@ void windowReshape(int w, int h) { * @param y Mouse y position */ void mouse(int button, int state, int x, int y) { + if ( glutGetModifiers() == GLUT_ACTIVE_SHIFT ) { + button = GLUT_MIDDLE_BUTTON; + } switch(button) { case GLUT_LEFT_BUTTON: case GLUT_MIDDLE_BUTTON: @@ -295,21 +302,34 @@ void motion(int x, int y) { break; case STATE_OBJECT_POSITION_SCALE: - //SceneObject co = sceneObjs[curObject]; - + if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: left/right, h: near/far - + //so.x, so.y, so.z + //sceneObjs[curObject].x += (x - startx)*leftrightFactor; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: big/small, h: up/down + + // For big/small scaling, we map negative numbers to 0->1 and positive numbers to 1->inf + float diff = (x - startx); + float max = (float)height/bigsmallFactor; + float scaling = ( diff + max) / max; + + sceneObjs[curObject].scale[0] *= scaling; + sceneObjs[curObject].scale[1] *= scaling; + sceneObjs[curObject].scale[2] *= scaling; } + + startx = x; break; case STATE_OBJECT_ROTATION_TEXTURE_SCALE: if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: rotate on width, h: rotate on h + } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { - // w & h, rotate on h + // w: rotate on height, h: texture scale + } break; @@ -384,17 +404,15 @@ void display() { drawFloor(); // Draw sceneObjs array - glPushMatrix(); - for ( int i = 0; i < nObjects; i++ ) { + for ( int i = 0; i < nObjects; i++ ) { + glPushMatrix(); SceneObject so = sceneObjs[i]; // Apply rotation vector - vector* rv = so.rotation.vect; - glRotatef(so.rotation.parameter, *rv[0], *rv[1], *rv[2]); + glRotatef(so.rotation.amount, so.rotation.vector[0], so.rotation.vector[1], so.rotation.vector[2]); // Apply scaling vector - vector* sv = so.scale; - glScalef(*sv[0], *sv[1], *sv[2]); + glScalef(so.scale[0], so.scale[1], so.scale[2]); // Apply translation vector glTranslatef(so.x, so.y, so.z); @@ -404,7 +422,6 @@ void display() { getTexture(so.texture); glBindTexture(GL_TEXTURE_2D, so.texture); } else { - getTexture(0); glBindTexture(GL_TEXTURE_2D, 0); } @@ -419,8 +436,9 @@ void display() { } glBindTexture(GL_TEXTURE_2D, 0); - } - glPopMatrix(); + glPopMatrix(); + } + // Draw a white ball over the light source glPushMatrix();