X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=c6f3d2c15b841f19206d119d9c6019a832257a04;hp=72d08d078b34516f605522968d5c9646ca84e02c;hb=974b0d95620640e8589a286f16f746b3b7887b52;hpb=7947c53d4ab7cbb0525796413d38415f86375c27 diff --git a/scene.c b/scene.c index 72d08d0..c6f3d2c 100644 --- a/scene.c +++ b/scene.c @@ -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,32 +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 + //so.x, so.y, so.z //sceneObjs[curObject].x += (x - startx)*leftrightFactor; + printf("cam angle: %f\n", rotate*rotateFactor); + sceneObjs[curObject].x = (x - startx) * sin(rotate*rotateFactor); + sceneObjs[curObject].z = (x - startx) * cos(rotate*rotateFactor); } 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; - // For big/small scaling, we map negative numbers to 0->1 and positive numbers to 1->inf - float diff = (y - starty); - float scaling; + sceneObjs[curObject].scale[0] *= scaling; + sceneObjs[curObject].scale[1] *= scaling; + sceneObjs[curObject].scale[2] *= scaling; - if ( diff < 0 ) { - scaling = (diff - -((float)height/2))/(0 - -((float)height/2)); - } else { - scaling = diff; - } - - printf("Diff is %f, Scaling by %f on all axii\n", diff, scaling); - sceneObjs[curObject].scale[0] = scaling; - sceneObjs[curObject].scale[1] = scaling; - sceneObjs[curObject].scale[2] = scaling; - - starty = y; + // h: up/down + sceneObjs[curObject].y -= (y - starty) * updownFactor; } + starty = y; startx = x; + break; case STATE_OBJECT_ROTATION_TEXTURE_SCALE: @@ -375,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);