X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=39ff405faa73a3fe9433fdde86c30c0defc1acac;hp=ffc138da54b474c663d25aa339a6bbcfff1135a1;hb=3ffbf1f81f45280aaa92e8c9844868a2d1964ac4;hpb=94605c9ba4cad948d4488cb87cb8134240adf8c2 diff --git a/scene.c b/scene.c index ffc138d..39ff405 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 @@ -25,17 +25,14 @@ void processMainEvents(int id) { switch (id) { case M_ROTATE_MOVE_CAMERA: - // Do stuff + manipulateState = STATE_CAMERA_ROTATE_MOVE; break; - case M_POSITION_SCALE: - // Do stuff + manipulateState = STATE_OBJECT_POSITION_SCALE; break; - case M_ROTATION_TEXTURE_SCALE: - // Do stuff + manipulateState = STATE_OBJECT_ROTATION_TEXTURE_SCALE; break; - case M_EXIT: exit(EXIT_SUCCESS); @@ -113,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(); } /** @@ -122,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(); + } } /** @@ -165,12 +166,12 @@ void makeMenu() { // Construct main menu glutCreateMenu(processMainEvents); - //glutAddMenuEntry("Rotate/Move Camera", M_ROTATE_MOVE_CAMERA); - //glutAddSubMenu("Add object", objectMenu); - //glutAddMenuEntry("Position/Scale", M_POSITION_SCALE); - //glutAddMenuEntry("Rotation/Texture Scale", M_ROTATION_TEXTURE_SCALE); + glutAddMenuEntry("Rotate/Move Camera", M_ROTATE_MOVE_CAMERA); + glutAddSubMenu("Add object", objectMenu); + 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); @@ -198,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 ( button == GLUT_LEFT_BUTTON && glutGetModifiers() == GLUT_ACTIVE_SHIFT ) { + button = GLUT_MIDDLE_BUTTON; // Holding shift with left button is the same as the middle button + } switch(button) { case GLUT_LEFT_BUTTON: case GLUT_MIDDLE_BUTTON: @@ -206,6 +210,8 @@ void mouse(int button, int state, int x, int y) { } else if ( state == GLUT_UP ) { buttonSelected = -1; } + startx = x; + starty = y; break; } } @@ -280,38 +286,57 @@ void motion(int x, int y) { switch ( manipulateState ) { case STATE_CAMERA_ROTATE_MOVE: + // w: rotate rotate += (x - startx); if ( buttonSelected == GLUT_LEFT_BUTTON ) { - // w: rotate, h: zoom + // h: zoom zoom += (y - starty); } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { - // w: rotate, h: tilt + // h: tilt camAngle += (y - starty); } starty = y; - printf("zoom is %f, y is %f starty is %f\n", zoom, y, starty); startx = x; 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; + + sceneObjs[curObject].x += (x - startx) * sin(90 - camAngle*camAngleFactor); + sceneObjs[curObject].z += (x - startx) * cos(90 - camAngle*camAngleFactor); } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { - // w: big/small, h: up/down + // w: big/small + 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; + + // h: up/down + sceneObjs[curObject].y -= (y - starty) * updownFactor; } + + starty = y; + 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; @@ -353,7 +378,7 @@ void display() { 0.0, 10.0, 0.0 /* up is in postivie Y direction */ ); - glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0); + glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0); // Set camera angle upward /* Reposition the light source 0. */ lightPosition0[0] = 12*cos(lightAngle0); @@ -386,17 +411,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); @@ -406,7 +429,6 @@ void display() { getTexture(so.texture); glBindTexture(GL_TEXTURE_2D, so.texture); } else { - getTexture(0); glBindTexture(GL_TEXTURE_2D, 0); } @@ -421,8 +443,9 @@ void display() { } glBindTexture(GL_TEXTURE_2D, 0); - } - glPopMatrix(); + glPopMatrix(); + } + // Draw a white ball over the light source glPushMatrix();