|
@@ -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,12 +161,38 @@ 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;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
void SceneView3D::MoveCamera(float timeStep)
|
|
void SceneView3D::MoveCamera(float timeStep)
|
|
|
{
|
|
{
|
|
|
|
|
+ // Mouse sensitivity as degrees per pixel
|
|
|
|
|
+ const float MOUSE_SENSITIVITY = 0.2f;
|
|
|
|
|
+ // 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;
|
|
|
|
|
+
|
|
|
if (!enabled_ && !GetFocus())
|
|
if (!enabled_ && !GetFocus())
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
@@ -177,14 +204,7 @@ void SceneView3D::MoveCamera(float timeStep)
|
|
|
bool mouseInView = MouseInView();
|
|
bool mouseInView = MouseInView();
|
|
|
bool orbitting = GetOrbitting();
|
|
bool orbitting = GetOrbitting();
|
|
|
bool zooming = GetZooming();
|
|
bool zooming = GetZooming();
|
|
|
-
|
|
|
|
|
- // Movement speed as world units per second
|
|
|
|
|
- float MOVE_SPEED = 20.0f;
|
|
|
|
|
- // Mouse sensitivity as degrees per pixel
|
|
|
|
|
- const float MOUSE_SENSITIVITY = 0.2f;
|
|
|
|
|
-
|
|
|
|
|
- if (shiftDown)
|
|
|
|
|
- MOVE_SPEED *= 3.0f;
|
|
|
|
|
|
|
+ bool changingCameraSpeed = GetChangingCameraSpeed();
|
|
|
|
|
|
|
|
// 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,28 @@ 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)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ int mouseWheel = input->GetMouseMoveWheel();
|
|
|
|
|
+
|
|
|
|
|
+ // Apple decided to change the direction of mousewheel input to match touch devices
|
|
|
|
|
+#ifdef ATOMIC_PLATFORM_OSX
|
|
|
|
|
+ mouseWheel = -mouseWheel;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ if (mouseWheel)
|
|
|
|
|
+ cameraMoveSpeed_ += mouseWheel * 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 +274,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);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|