X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=39ff405faa73a3fe9433fdde86c30c0defc1acac;hp=ffa63dd14f3f7cf7b7772685e66766999cb985c0;hb=3ffbf1f81f45280aaa92e8c9844868a2d1964ac4;hpb=876a9341282f91027829f3e544ad4e4a7215c682 diff --git a/scene.c b/scene.c index ffa63dd..39ff405 100644 --- a/scene.c +++ b/scene.c @@ -168,8 +168,8 @@ void makeMenu() { 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("Position/Scale", M_POSITION_SCALE); + glutAddMenuEntry("Rotation/Texture Scale", M_ROTATION_TEXTURE_SCALE); //glutAddSubMenu("Material", materialMenu); glutAddSubMenu("Texture", textureMenu); glutAddSubMenu("Ground texture", gTextureMenu); @@ -199,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: @@ -283,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); } @@ -299,15 +303,31 @@ void motion(int x, int y) { break; case STATE_OBJECT_POSITION_SCALE: - //so.x, so.y, so.z + if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: left/right, h: near/far - sceneObjs[curObject].x += (x - startx); + //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: @@ -358,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);