+ if ( buttonSelected == -1 ) return; // No button selected, no action\r
+\r
+ float diffx = x - startx;\r
+ float diffy = y - starty;\r
+\r
+ switch ( manipulateState ) {\r
+ case STATE_CAMERA_ROTATE_MOVE:\r
+ // w: rotate\r
+ rotate += diffx;\r
+\r
+ if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
+ // h: zoom\r
+ zoom += diffy;\r
+ } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
+ // h: tilt\r
+ camAngle += diffy;\r
+ }\r
+ break;\r
+\r
+ case STATE_OBJECT_POSITION_SCALE:\r
+\r
+ if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
+ // w: left/right, h: near/far\r
+ float angler = 2 * M_PI * ( (rotate*camRotateFactor)/360.0 );\r
+ sceneObjs[curObject].x += diffx * cos(angler) * leftrightFactor + diffy * cos(M_PI/2 + angler) * nearfarFactor;\r
+ sceneObjs[curObject].z += diffx * sin(angler) * leftrightFactor + diffy * sin(M_PI/2 + angler) * nearfarFactor;\r
+\r
+ } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
+ // w: big/small\r
+ float max = (float)height/bigsmallFactor;\r
+ float scaling = (diffx + max) / max;\r
+\r
+ sceneObjs[curObject].scale[0] *= scaling;\r
+ sceneObjs[curObject].scale[1] *= scaling;\r
+ sceneObjs[curObject].scale[2] *= scaling;\r
+\r
+ // h: up/down\r
+ sceneObjs[curObject].y -= diffy * updownFactor;\r
+ }\r
+\r
+ break;\r
+\r
+ case STATE_OBJECT_ROTATION_TEXTURE_SCALE:\r
+\r
+ if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
+ // w: rotate on y\r
+ sceneObjs[curObject].rotation.y += diffx * rotateFactor;\r
+\r
+ // h: rotate on x\r
+ sceneObjs[curObject].rotation.x += diffy * rotateFactor;\r
+\r
+ } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
+ // w: rotate on x\r
+ sceneObjs[curObject].rotation.x += diffx * rotateFactor;\r
+\r
+ // h: texture scale\r
+ float max = (float)height/texscaleFactor;\r
+ float scaling = (diffy + max) / max;\r
+ sceneObjs[curObject].texture.scale *= scaling;\r
+\r
+ }\r
+ \r
+ break;\r
+\r