diff --git a/src/Gui/BlenderNavigationStyle.cpp b/src/Gui/BlenderNavigationStyle.cpp index d40ab1acc..154180072 100644 --- a/src/Gui/BlenderNavigationStyle.cpp +++ b/src/Gui/BlenderNavigationStyle.cpp @@ -79,10 +79,10 @@ const char* BlenderNavigationStyle::mouseButtons(ViewerMode mode) SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) { - // Events when in "ready-to-seek" mode are ignored, except those - // which influence the seek mode itself -- these are handled further - // up the inheritance hierarchy. - if (this->isSeekMode()) { return inherited::processSoEvent(ev); } + // Events when in "ready-to-seek" mode are ignored, except those + // which influence the seek mode itself -- these are handled further + // up the inheritance hierarchy. + if (this->isSeekMode()) { return inherited::processSoEvent(ev); } const SoType type(ev->getTypeId()); @@ -291,20 +291,9 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) // Spaceball & Joystick handling if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) { - SoMotion3Event * const event = (SoMotion3Event *) ev; - SoCamera * const camera = viewer->getCamera(); - - SbVec3f dir = event->getTranslation(); - if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){ - static float zoomConstant(-.03f); - dir[2] = 0.0;//don't move the cam for z translation. - - SoOrthographicCamera *oCam = static_cast(camera); - oCam->scaleHeight(1.0-event->getTranslation()[2] * zoomConstant); - } - camera->orientation.getValue().multVec(dir,dir); - camera->position = camera->position.getValue() + dir; - camera->orientation = event->getRotation() * camera->orientation.getValue(); + const SoMotion3Event * const event = static_cast(ev); + if (event) + this->processMotionEvent(event); processed = TRUE; } diff --git a/src/Gui/CADNavigationStyle.cpp b/src/Gui/CADNavigationStyle.cpp index 99f0d5919..a85124a02 100644 --- a/src/Gui/CADNavigationStyle.cpp +++ b/src/Gui/CADNavigationStyle.cpp @@ -320,20 +320,9 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev) // Spaceball & Joystick handling if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) { - SoMotion3Event * const event = (SoMotion3Event *) ev; - SoCamera * const camera = viewer->getCamera(); - - SbVec3f dir = event->getTranslation(); - if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){ - static float zoomConstant(-.03f); - dir[2] = 0.0;//don't move the cam for z translation. - - SoOrthographicCamera *oCam = static_cast(camera); - oCam->scaleHeight(1.0-event->getTranslation()[2] * zoomConstant); - } - camera->orientation.getValue().multVec(dir,dir); - camera->position = camera->position.getValue() + dir; - camera->orientation = event->getRotation() * camera->orientation.getValue(); + const SoMotion3Event * const event = static_cast(ev); + if (event) + this->processMotionEvent(event); processed = TRUE; } diff --git a/src/Gui/InventorNavigationStyle.cpp b/src/Gui/InventorNavigationStyle.cpp index 5fb72f989..e1e6f4755 100644 --- a/src/Gui/InventorNavigationStyle.cpp +++ b/src/Gui/InventorNavigationStyle.cpp @@ -285,16 +285,10 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) // Spaceball & Joystick handling if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) { - SoMotion3Event * const event = (SoMotion3Event *) ev; - SoCamera * const camera = viewer->getCamera(); - if (camera) { - SbVec3f dir = event->getTranslation(); - camera->orientation.getValue().multVec(dir,dir); - camera->position = camera->position.getValue() + dir; - camera->orientation = - event->getRotation() * camera->orientation.getValue(); - processed = TRUE; - } + const SoMotion3Event * const event = static_cast(ev); + if (event) + this->processMotionEvent(event); + processed = TRUE; } enum { diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 8a44dd667..192cb7ae5 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -1140,6 +1140,37 @@ SbBool NavigationStyle::processSoEvent(const SoEvent * const ev) return viewer->processSoEventBase(ev); } +SbBool NavigationStyle::processMotionEvent(const SoMotion3Event * const ev) +{ + SoCamera * const camera = viewer->getCamera(); + if (!camera) + return FALSE; + + SbViewVolume volume(camera->getViewVolume()); + SbVec3f center(volume.getSightPoint(camera->focalDistance.getValue())); + float scale(volume.getWorldToScreenScale(center, 1.0)); + float translationFactor = scale * .0001; + + SbVec3f dir = ev->getTranslation(); + + if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){ + SoOrthographicCamera *oCam = static_cast(camera); + oCam->scaleHeight(1.0 + (dir[2] * 0.0001)); + dir[2] = 0.0;//don't move the cam for z translation. + } + + SbRotation newRotation(ev->getRotation() * camera->orientation.getValue()); + SbVec3f newPosition, newDirection; + newRotation.multVec(SbVec3f(0.0, 0.0, -1.0), newDirection); + newPosition = center - (newDirection * camera->focalDistance.getValue()); + + camera->orientation.setValue(newRotation); + camera->orientation.getValue().multVec(dir,dir); + camera->position = newPosition + (dir * translationFactor); + + return TRUE; +} + void NavigationStyle::setPopupMenuEnabled(const SbBool on) { this->menuenabled = on; diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 846e65f86..7644a7340 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -38,6 +38,7 @@ // forward declarations class SoEvent; +class SoMotion3Event; class SoQtViewer; class SoCamera; class SoSensor; @@ -90,10 +91,10 @@ public: Clip = 3, /**< Clip objects using a lasso. */ }; - enum OrbitStyle { - Turntable, - Trackball - }; + enum OrbitStyle { + Turntable, + Trackball + }; public: NavigationStyle(); @@ -126,6 +127,7 @@ public: void setViewingMode(const ViewerMode newmode); int getViewingMode() const; virtual SbBool processEvent(const SoEvent * const ev); + virtual SbBool processMotionEvent(const SoMotion3Event * const ev); void setPopupMenuEnabled(const SbBool on); SbBool isPopupMenuEnabled(void) const; diff --git a/src/Gui/TouchpadNavigationStyle.cpp b/src/Gui/TouchpadNavigationStyle.cpp index 530b0650d..e33323c33 100644 --- a/src/Gui/TouchpadNavigationStyle.cpp +++ b/src/Gui/TouchpadNavigationStyle.cpp @@ -79,10 +79,10 @@ const char* TouchpadNavigationStyle::mouseButtons(ViewerMode mode) SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) { - // Events when in "ready-to-seek" mode are ignored, except those - // which influence the seek mode itself -- these are handled further - // up the inheritance hierarchy. - if (this->isSeekMode()) { return inherited::processSoEvent(ev); } + // Events when in "ready-to-seek" mode are ignored, except those + // which influence the seek mode itself -- these are handled further + // up the inheritance hierarchy. + if (this->isSeekMode()) { return inherited::processSoEvent(ev); } const SoType type(ev->getTypeId()); @@ -265,20 +265,9 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) // Spaceball & Joystick handling if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) { - SoMotion3Event * const event = (SoMotion3Event *) ev; - SoCamera * const camera = viewer->getCamera(); - - SbVec3f dir = event->getTranslation(); - if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){ - static float zoomConstant(-.03f); - dir[2] = 0.0;//don't move the cam for z translation. - - SoOrthographicCamera *oCam = static_cast(camera); - oCam->scaleHeight(1.0-event->getTranslation()[2] * zoomConstant); - } - camera->orientation.getValue().multVec(dir,dir); - camera->position = camera->position.getValue() + dir; - camera->orientation = event->getRotation() * camera->orientation.getValue(); + const SoMotion3Event * const event = static_cast(ev); + if (event) + this->processMotionEvent(event); processed = TRUE; } diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index ab3dd8e10..93d06c691 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1070,18 +1070,16 @@ void View3DInventorViewer::processEvent(QEvent * event) motionEvent->setHandled(true); - static float translationConstant(-.001f); float xTrans, yTrans, zTrans; xTrans = static_cast(motionEvent->translationX()); yTrans = static_cast(motionEvent->translationY()); zTrans = static_cast(motionEvent->translationZ()); - SbVec3f translationVector(xTrans, yTrans, zTrans * -1.0); - translationVector *= translationConstant; + SbVec3f translationVector(xTrans, yTrans, zTrans); static float rotationConstant(.0001f); SbRotation xRot, yRot, zRot; - xRot.setValue(SbVec3f(-1.0, 0.0, 0.0), static_cast(motionEvent->rotationX()) * rotationConstant); - yRot.setValue(SbVec3f(0.0, -1.0, 0.0), static_cast(motionEvent->rotationY()) * rotationConstant); + xRot.setValue(SbVec3f(1.0, 0.0, 0.0), static_cast(motionEvent->rotationX()) * rotationConstant); + yRot.setValue(SbVec3f(0.0, 1.0, 0.0), static_cast(motionEvent->rotationY()) * rotationConstant); zRot.setValue(SbVec3f(0.0, 0.0, 1.0), static_cast(motionEvent->rotationZ()) * rotationConstant); SoMotion3Event motion3Event;