X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=debba608da20efb80cf51e68205f7bdf0538aacd;hp=77d2c108dc75dbdf1e1e7ea3ea58fcb96ef2f087;hb=9d534bb644d7510782a835c701e4b185957f7e64;hpb=47f587200c6be35f945d40d837a50d3c415c8588;ds=sidebyside diff --git a/scene.c b/scene.c index 77d2c10..debba60 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,8 @@ 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(); } @@ -120,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(); + } } /** @@ -168,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); @@ -196,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: @@ -280,13 +286,14 @@ 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); } @@ -296,21 +303,37 @@ 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 + // 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;