From e33bd4d50841fa14812882fde150435ed3063a98 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Tue, 25 Feb 2014 14:24:35 +0100
Subject: [PATCH] camera rotation via ctrl-left button drag

---
 apps/opencs/view/render/scenewidget.cpp | 44 +++++++++++++++++++------
 apps/opencs/view/render/scenewidget.hpp |  1 +
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp
index 35a29c6687..b498fba061 100644
--- a/apps/opencs/view/render/scenewidget.cpp
+++ b/apps/opencs/view/render/scenewidget.cpp
@@ -17,7 +17,7 @@ namespace CSVRender
         , mCamera(NULL)
         , mSceneMgr(NULL), mNavigationMode (NavigationMode_Free), mUpdate (false)
         , mKeyForward (false), mKeyBackward (false), mKeyLeft (false), mKeyRight (false)
-        , mFast (false), mDragging (false)
+        , mFast (false), mDragging (false), mMod1 (false)
         , mMouseSensitivity (2), mFastFactor (4) /// \todo make these configurable
     {
         setAttribute(Qt::WA_PaintOnScreen);
@@ -148,6 +148,7 @@ namespace CSVRender
             case Qt::Key_A: mKeyLeft = true; break;
             case Qt::Key_D: mKeyRight = true; break;
             case Qt::Key_Shift: mFast = true; break;
+            case Qt::Key_Control: mMod1 = true; break;
             default: QWidget::keyPressEvent (event);
         }
     }
@@ -161,6 +162,7 @@ namespace CSVRender
             case Qt::Key_A: mKeyLeft = false; break;
             case Qt::Key_D: mKeyRight = false; break;
             case Qt::Key_Shift: mFast = false; break;
+            case Qt::Key_Control: mMod1 = false; break;
             default: QWidget::keyReleaseEvent (event);
         }
     }
@@ -188,18 +190,39 @@ namespace CSVRender
                 QPoint diff = mOldPos-event->pos();
                 mOldPos = event->pos();
 
-                if (diff.x())
+                if (mMod1)
                 {
-                    Ogre::Vector3 direction = mCamera->getDerivedRight();
-                    mCamera->move ((getFastFactor() * direction * diff.x())/mMouseSensitivity);
-                    mUpdate = true;
-                }
+                    // turn camera
+                    if (diff.x())
+                    {
+                        mCamera->yaw (
+                            Ogre::Degree ((getFastFactor() * diff.x())/mMouseSensitivity));
+                        mUpdate = true;
+                    }
 
-                if (diff.y())
+                    if (diff.y())
+                    {
+                        mCamera->pitch (
+                            Ogre::Degree ((getFastFactor() * diff.y())/mMouseSensitivity));
+                        mUpdate = true;
+                    }
+                }
+                else
                 {
-                    Ogre::Vector3 direction = mCamera->getDerivedUp();
-                    mCamera->move ((getFastFactor() * -direction * diff.y())/mMouseSensitivity);
-                    mUpdate = true;
+                    // pan camera
+                    if (diff.x())
+                    {
+                        Ogre::Vector3 direction = mCamera->getDerivedRight();
+                        mCamera->move ((getFastFactor() * direction * diff.x())/mMouseSensitivity);
+                        mUpdate = true;
+                    }
+
+                    if (diff.y())
+                    {
+                        Ogre::Vector3 direction = mCamera->getDerivedUp();
+                        mCamera->move ((getFastFactor() * -direction * diff.y())/mMouseSensitivity);
+                        mUpdate = true;
+                    }
                 }
             }
             else
@@ -223,6 +246,7 @@ namespace CSVRender
         mKeyLeft = false;
         mKeyRight = false;
         mFast = false;
+        mMod1 = false;
 
         QWidget::focusOutEvent (event);
     }
diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp
index 37ef3cb94c..58b122deea 100644
--- a/apps/opencs/view/render/scenewidget.hpp
+++ b/apps/opencs/view/render/scenewidget.hpp
@@ -63,6 +63,7 @@ namespace CSVRender
             int mKeyRight;
             bool mFast;
             bool mDragging;
+            bool mMod1;
             QPoint mOldPos;
             int mMouseSensitivity;
             int mFastFactor;