Browse Source

Updated navigation by no longer using alt or shift
Camera movement speed can be increased decreased using mouse wheel
Holding right mouse button and using mouse wheel zooms in and out

weinand 9 years ago
parent
commit
58aaba3b7e

+ 49 - 16
Source/AtomicEditor/Editors/SceneEditor3D/SceneView3D.cpp

@@ -73,7 +73,8 @@ SceneView3D ::SceneView3D(Context* context, SceneEditor3D *sceneEditor) :
     mouseLeftDown_(false),
     mouseLeftDown_(false),
     mouseMoved_(false),
     mouseMoved_(false),
     enabled_(true),
     enabled_(true),
-    cameraMove_(false)
+    cameraMove_(false),
+    cameraMoveSpeed_(20.0f)
 {
 {
 
 
     sceneEditor_ = sceneEditor;
     sceneEditor_ = sceneEditor;
@@ -160,7 +161,26 @@ bool SceneView3D::GetOrbitting()
 bool SceneView3D::GetZooming()
 bool SceneView3D::GetZooming()
 {
 {
     Input* input = GetSubsystem<Input>();
     Input* input = GetSubsystem<Input>();
-    return MouseInView() && input->GetKeyDown(KEY_ALT) && input->GetMouseMoveWheel();
+    return MouseInView() && input->GetMouseMoveWheel() && !input->GetMouseButtonDown(MOUSEB_RIGHT);
+}
+
+bool SceneView3D::GetChangingCameraSpeed()
+{
+    Input* input = GetSubsystem<Input>();
+    return MouseInView() && input->GetMouseMoveWheel() && input->GetMouseButtonDown(MOUSEB_RIGHT);
+}
+
+void SceneView3D::CheckCameraSpeedBounds()
+{
+    const float MAX_CAMERA_SPEED = 80.0f;
+    const float MIN_CAMERA_SPEED = 2.0f;
+
+    if (cameraMoveSpeed_ >= MAX_CAMERA_SPEED)
+    {
+        cameraMoveSpeed_ = MAX_CAMERA_SPEED;
+    }
+    if (cameraMoveSpeed_ <= MIN_CAMERA_SPEED)
+        cameraMoveSpeed_ = MIN_CAMERA_SPEED;
 }
 }
 
 
 
 
@@ -177,14 +197,14 @@ void SceneView3D::MoveCamera(float timeStep)
     bool mouseInView = MouseInView();
     bool mouseInView = MouseInView();
     bool orbitting = GetOrbitting();
     bool orbitting = GetOrbitting();
     bool zooming = GetZooming();
     bool zooming = GetZooming();
+    bool changingCameraSpeed = GetChangingCameraSpeed();
 
 
-    // Movement speed as world units per second
-    float MOVE_SPEED = 20.0f;
     // Mouse sensitivity as degrees per pixel
     // Mouse sensitivity as degrees per pixel
     const float MOUSE_SENSITIVITY = 0.2f;
     const float MOUSE_SENSITIVITY = 0.2f;
-
-    if (shiftDown)
-        MOVE_SPEED *= 3.0f;
+    // Tempo at which mouse speed increases using mousewheel
+    const float CAMERA_MOVE_TEMPO = 5.0f;
+    // Tempo used when zooming in and out
+    const float ZOOM_TEMPO = 0.6f;
 
 
     // Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
     // Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
     if ((mouseInView && input->GetMouseButtonDown(MOUSEB_RIGHT)) || orbitting)
     if ((mouseInView && input->GetMouseButtonDown(MOUSEB_RIGHT)) || orbitting)
@@ -199,11 +219,12 @@ void SceneView3D::MoveCamera(float timeStep)
     // Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
     // Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
     Quaternion q(pitch_, yaw_, 0.0f);
     Quaternion q(pitch_, yaw_, 0.0f);
 
 
-    if (!zooming)
+    if (!zooming || !changingCameraSpeed)
         cameraNode_->SetRotation(q);
         cameraNode_->SetRotation(q);
 
 
     if (orbitting)
     if (orbitting)
     {
     {
+        zooming = false;
         BoundingBox bbox;
         BoundingBox bbox;
         sceneEditor_->GetSelection()->GetBounds(bbox);
         sceneEditor_->GetSelection()->GetBounds(bbox);
         if (bbox.defined_)
         if (bbox.defined_)
@@ -217,12 +238,23 @@ void SceneView3D::MoveCamera(float timeStep)
 
 
     if (zooming)
     if (zooming)
     {
     {
+        orbitting = false;
         Ray ray = GetCameraRay();
         Ray ray = GetCameraRay();
         Vector3 wpos = cameraNode_->GetWorldPosition();
         Vector3 wpos = cameraNode_->GetWorldPosition();
-        wpos += ray.direction_ * (float (input->GetMouseMoveWheel()) * (shiftDown ? 0.6f : 0.2f));
+        wpos += ray.direction_ * (float(input->GetMouseMoveWheel()) * ZOOM_TEMPO);
         cameraNode_->SetWorldPosition(wpos);
         cameraNode_->SetWorldPosition(wpos);
     }
     }
 
 
+    if (changingCameraSpeed)
+    {
+        if (input->GetMouseMoveWheel() > 0)
+            cameraMoveSpeed_ += input->GetMouseMoveWheel() * CAMERA_MOVE_TEMPO;
+        else
+            if (input->GetMouseMoveWheel() < 0)
+                cameraMoveSpeed_ += input->GetMouseMoveWheel() * CAMERA_MOVE_TEMPO;
+
+        CheckCameraSpeedBounds();
+    }
 
 
 #ifdef ATOMIC_PLATFORM_WINDOWS
 #ifdef ATOMIC_PLATFORM_WINDOWS
     bool superdown = input->GetKeyDown(KEY_LCTRL) || input->GetKeyDown(KEY_RCTRL);
     bool superdown = input->GetKeyDown(KEY_LCTRL) || input->GetKeyDown(KEY_RCTRL);
@@ -237,31 +269,32 @@ void SceneView3D::MoveCamera(float timeStep)
         if (input->GetKeyDown(KEY_W))
         if (input->GetKeyDown(KEY_W))
         {
         {
             SetFocus();
             SetFocus();
-            cameraNode_->Translate(Vector3::FORWARD * MOVE_SPEED * timeStep);
+            cameraNode_->Translate(Vector3::FORWARD * cameraMoveSpeed_ * timeStep);
         }
         }
         if (input->GetKeyDown(KEY_S))
         if (input->GetKeyDown(KEY_S))
         {
         {
             SetFocus();
             SetFocus();
-            cameraNode_->Translate(Vector3::BACK * MOVE_SPEED * timeStep);
+            cameraNode_->Translate(Vector3::BACK * cameraMoveSpeed_ * timeStep);
         }
         }
         if (input->GetKeyDown(KEY_A))
         if (input->GetKeyDown(KEY_A))
-        {   SetFocus();
-            cameraNode_->Translate(Vector3::LEFT * MOVE_SPEED * timeStep);
+        {
+            SetFocus();
+            cameraNode_->Translate(Vector3::LEFT * cameraMoveSpeed_ * timeStep);
         }
         }
         if (input->GetKeyDown(KEY_D))
         if (input->GetKeyDown(KEY_D))
         {
         {
             SetFocus();
             SetFocus();
-            cameraNode_->Translate(Vector3::RIGHT * MOVE_SPEED * timeStep);
+            cameraNode_->Translate(Vector3::RIGHT * cameraMoveSpeed_ * timeStep);
         }
         }
         if (input->GetKeyDown(KEY_E))
         if (input->GetKeyDown(KEY_E))
         {
         {
             SetFocus();
             SetFocus();
-            cameraNode_->Translate(Vector3::UP * MOVE_SPEED * timeStep);
+            cameraNode_->Translate(Vector3::UP * cameraMoveSpeed_ * timeStep);
         }
         }
         if (input->GetKeyDown(KEY_Q))
         if (input->GetKeyDown(KEY_Q))
         {
         {
             SetFocus();
             SetFocus();
-            cameraNode_->Translate(Vector3::DOWN * MOVE_SPEED * timeStep);
+            cameraNode_->Translate(Vector3::DOWN * cameraMoveSpeed_ * timeStep);
         }
         }
     }
     }
 
 

+ 4 - 0
Source/AtomicEditor/Editors/SceneEditor3D/SceneView3D.h

@@ -75,6 +75,8 @@ private:
     bool GetOrbitting();
     bool GetOrbitting();
     bool GetZooming();
     bool GetZooming();
 
 
+    bool GetChangingCameraSpeed();
+
     void HandleMouseMove(StringHash eventType, VariantMap& eventData);
     void HandleMouseMove(StringHash eventType, VariantMap& eventData);
 
 
     void UpdateDragNode(int mouseX, int mouseY);
     void UpdateDragNode(int mouseX, int mouseY);
@@ -90,6 +92,7 @@ private:
     void HandleUIUnhandledShortcut(StringHash eventType, VariantMap& eventData);
     void HandleUIUnhandledShortcut(StringHash eventType, VariantMap& eventData);
 
 
     void MoveCamera(float timeStep);
     void MoveCamera(float timeStep);
+    void CheckCameraSpeedBounds();
 
 
     WeakPtr<SceneEditor3D> sceneEditor_;
     WeakPtr<SceneEditor3D> sceneEditor_;
 
 
@@ -103,6 +106,7 @@ private:
 
 
     bool cameraMove_;
     bool cameraMove_;
     float cameraMoveTime_;
     float cameraMoveTime_;
+    float cameraMoveSpeed_;
     Vector3 cameraMoveStart_;
     Vector3 cameraMoveStart_;
     Vector3 cameraMoveTarget_;
     Vector3 cameraMoveTarget_;