void AppWindow::motion ( int x, int y ) { int dx = last_x - x; int dy = y - last_y; // Handle GUI interaction in nvGui by calling guiMouseDrag if ( guiMouseDrag ( x, y ) ) return; // Camera interaction Camera3D* cam = scene.getCamera (); switch ( cam_mode ) { case MODE_CAMERA: if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT ) { Vector4DF angs = cam->getAng(); angs.x += dx*.1; angs.y += dy*.1; cam->setOrbit ( angs, cam->getToPos(), cam->getOrbitDist(), cam->getOrbitDist() ); //cam->moveOrbit ( dx*.1, dy*.1, 0, 0 ); } else if ( dragging == NVPWindow::MOUSE_BUTTON_MIDDLE ) { cam->moveRelative ( dx*.1, dy*.1, 0 ); } else if ( dragging == NVPWindow::MOUSE_BUTTON_RIGHT ) { float orb = cam->getOrbitDist() + dy*0.1; cam->setOrbit ( cam->getAng(), cam->getToPos(), orb, orb); } break; case MODE_FOV: if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT ) { cam->setFov ( cam->getFov() + dy*.1 ); } break; case MODE_LIGHT: Light* light = scene.getLight(); if ( dragging == NVPWindow::MOUSE_BUTTON_LEFT ) { light->moveOrbit ( dx*0.1, dy*0.1, 0, 0 ); } else if ( dragging == NVPWindow::MOUSE_BUTTON_RIGHT ) { light->moveOrbit ( 0, 0, dy*0.1, 0 ); } break; } last_x = x; last_y = y; }
// This function called by both OpenGL (GLUT) and DirectX void mouse_click_func ( int button, int state, int x, int y ) { cangs = cam.getAng(); ctp = cam.getToPos(); cdist = cam.getOrbitDist(); if ( state==GLUT_DOWN && guiMouseDown ( x, y ) ) return; // event handling for nv2D GUIs if( state == GLUT_DOWN ) { if ( button == GLUT_LEFT_BUTTON ) dragging = DRAG_LEFT; else if ( button == GLUT_RIGHT_BUTTON ) dragging = DRAG_RIGHT; last_x = x; last_y = y; } else if ( state==GLUT_UP ) { dragging = DRAG_OFF; } }
void AppWindow::mouse ( NVPWindow::MouseButton button, ButtonAction action, int mods, int x, int y ) { Vector3DF cangs, ctp; float cdist; Camera3D* cam = scene.getCamera (); cangs = cam->getAng(); ctp = cam->getToPos(); cdist = cam->getOrbitDist(); if ( action==NVPWindow::BUTTON_PRESS && guiMouseDown ( x, y ) ) return; if( action==NVPWindow::BUTTON_PRESS ) { dragging = (int) button; last_x = x; last_y = y; } else if ( action==NVPWindow::BUTTON_RELEASE ) { dragging = -1; } }