Commits

dbacchet committed 521ae55

updated trackball example

Comments (0)

Files changed (3)

sources/opengl2_samples/test7c_trackballmanipulatorcamera/glfw_utils.cpp

             context.current_key = (char)KEY_TAB;
         else if (key == GLFW_KEY_ENTER)
             context.current_key = (char)KEY_ENTER;
+        else if (key == GLFW_KEY_LSHIFT || key == GLFW_KEY_RSHIFT)
+            context.current_key = (char)KEY_SHIFT;
+        else if (key == GLFW_KEY_LCTRL || key == GLFW_KEY_RCTRL)
+            context.current_key = (char)KEY_CTRL;
+        else if (key == GLFW_KEY_LALT || key == GLFW_KEY_RALT)
+            context.current_key = (char)KEY_ALT;
+        else if (key == GLFW_KEY_LSUPER || key == GLFW_KEY_RSUPER)
+            context.current_key = (char)KEY_SUPER;
+    }
+    else
+    {
+        context.current_key = (char)0;
     }
 }
 

sources/opengl2_samples/test7c_trackballmanipulatorcamera/glfw_utils.h

 #define MOUSE_BUTTON_MIDDLE 2
 #define MOUSE_BUTTON_RIGHT  3
 
-#define KEY_BACKSPACE 0x01
-#define KEY_DELETE    0x02
-#define KEY_TAB       0x03
-#define KEY_ENTER     0x04
+#define KEY_BACKSPACE 1
+#define KEY_DELETE    2
+#define KEY_TAB       3
+#define KEY_ENTER     4
+#define KEY_SHIFT     5
+#define KEY_CTRL      6
+#define KEY_ALT       7
+#define KEY_SUPER     8 // windows key of apple command key
 
 
 #define ARB_TO_CORE(fun) if (!fun && fun##ARB) fun = fun##ARB;

sources/opengl2_samples/test7c_trackballmanipulatorcamera/main.cpp

     float nx = 2.0f*((float)ctx.mouse_posx-ctx.width/2.0f)/w;
     float ny = 2.0f*((float)ctx.mouse_posy-ctx.height/2.0f)/w;
 
-    if (ctx.mouse_button==MOUSE_BUTTON_LEFT && !ctx.dragging)
+    if ( (ctx.mouse_button==MOUSE_BUTTON_LEFT && !ctx.dragging) )
     {
         trackball.setMode(GLCameraManipulatorf::evRotate);
         trackball.beginDrag(nx,ny);
     }
-    if (ctx.mouse_button==MOUSE_BUTTON_MIDDLE && !ctx.dragging)
+    if ( (ctx.mouse_button==MOUSE_BUTTON_MIDDLE && !ctx.dragging)
+       || (ctx.mouse_button==MOUSE_BUTTON_LEFT && ctx.current_key==KEY_SHIFT  && !ctx.dragging) )
     {
         trackball.setMode(GLCameraManipulatorf::evPan);
         trackball.beginDrag(nx,ny);
     }
-    if (ctx.mouse_button==MOUSE_BUTTON_RIGHT && !ctx.dragging)
+    if ( (ctx.mouse_button==MOUSE_BUTTON_RIGHT && !ctx.dragging)
+       || (ctx.mouse_button==MOUSE_BUTTON_LEFT && ctx.current_key==KEY_ALT && !ctx.dragging)
+       || (ctx.mouse_button==MOUSE_BUTTON_LEFT && ctx.current_key==KEY_SUPER && !ctx.dragging) )
     {
         trackball.setMode(GLCameraManipulatorf::evZoom);
         trackball.beginDrag(nx,ny);