diff --git a/Engine/Source/Editor/UILayers/SceneView.cpp b/Engine/Source/Editor/UILayers/SceneView.cpp index 85c4138f..6c1e7d8b 100644 --- a/Engine/Source/Editor/UILayers/SceneView.cpp +++ b/Engine/Source/Editor/UILayers/SceneView.cpp @@ -340,10 +340,12 @@ void SceneView::Update() if (ImGui::IsWindowHovered()) { isMouseInsideSeneView = true; + m_pCameraController->SetIsMouseInViewScene(true); } else { isMouseInsideSeneView = false; + m_pCameraController->SetIsMouseInViewScene(false); } // Draw scene. ImGui::Image(reinterpret_cast(m_pRenderTarget->GetTextureHandle(0).idx), @@ -382,12 +384,12 @@ void SceneView::Update() m_isMouseDownFirstTime = false; if (isMouseInsideSeneView && !m_isTerrainEditMode) { - m_pCameraController->SetIsInViewScene(true); + m_pCameraController->SetIsFirstClickInViewScene(true); m_isMouseShow = false; } else { - m_pCameraController->SetIsInViewScene(false); + m_pCameraController->SetIsFirstClickInViewScene(false); } } else diff --git a/Engine/Source/Runtime/Display/CameraController.cpp b/Engine/Source/Runtime/Display/CameraController.cpp index 10bf3b51..fdaa73b7 100644 --- a/Engine/Source/Runtime/Display/CameraController.cpp +++ b/Engine/Source/Runtime/Display/CameraController.cpp @@ -163,13 +163,13 @@ void CameraController::Update(float deltaTime) MoveRight(m_movementSpeed * deltaTime); } - if (Input::Get().IsKeyPressed(KeyCode::e)) + if (Input::Get().IsKeyPressed(KeyCode::q)) { m_isTracking = false; MoveDown(m_movementSpeed * deltaTime); } - if (Input::Get().IsKeyPressed(KeyCode::q) && !m_isMoving) + if (Input::Get().IsKeyPressed(KeyCode::e) && !m_isMoving) { m_isTracking = false; MoveUp(m_movementSpeed * deltaTime); @@ -177,18 +177,25 @@ void CameraController::Update(float deltaTime) } - if (Input::Get().IsMouseRBPressed() && !m_isMoving) + if (Input::Get().IsMouseLBPressed() && !m_isMoving && m_isFirstClickInViewScene && !ImGuizmo::IsUsing()) { m_isTracking = false; + MoveFront(m_horizontalSensitivity * Input::Get().GetMousePositionOffsetY() * deltaTime); Yaw(m_horizontalSensitivity * Input::Get().GetMousePositionOffsetX() * deltaTime); } - if (Input::Get().IsMouseLBPressed() && m_isInViewScene && !ImGuizmo::IsUsing()) + if (Input::Get().IsMouseRBPressed() && !m_isMoving && m_isFirstClickInViewScene && !ImGuizmo::IsUsing()) { m_isTracking = false; PitchLocal(m_verticalSensitivity * Input::Get().GetMousePositionOffsetY() * deltaTime); Yaw(m_horizontalSensitivity * Input::Get().GetMousePositionOffsetX() * deltaTime); } + if (Input::Get().GetMouseScrollOffsetY() && !m_isMoving && m_isMouseInViewScene && !ImGuizmo::IsUsing()) + { + m_isTracking = false; + MoveForward(m_movementSpeed * Input::Get().GetMouseScrollOffsetY() * deltaTime * 10.0f); + } + } } @@ -261,6 +268,18 @@ void CameraController::MoveDown(float amount) MoveUp(-amount); } +void CameraController::MoveFront(float amount) +{ + cd::Vec3f direction = cd::Vec3f(m_lookAt.x(), 0.0f, m_lookAt.z()).Normalize(); + m_eye = m_eye - direction * amount; + ControllerToCamera(); +} + +void CameraController::MoveBack(float amount) +{ + MoveFront(-amount); +} + void CameraController::Rotate(const cd::Vec3f& axis, float angleDegrees) { cd::Quaternion rotation = cd::Quaternion::FromAxisAngle(axis, cd::Math::DegreeToRadian(angleDegrees)); diff --git a/Engine/Source/Runtime/Display/CameraController.h b/Engine/Source/Runtime/Display/CameraController.h index b95c49bd..d577be3f 100644 --- a/Engine/Source/Runtime/Display/CameraController.h +++ b/Engine/Source/Runtime/Display/CameraController.h @@ -38,6 +38,8 @@ class CameraController final void MoveRight(float amount); void MoveUp(float amount); void MoveDown(float amount); + void MoveFront(float amount); + void MoveBack(float amount); void Rotate(const cd::Vec3f& axis, float angleDegrees); void Rotate(float x, float y, float z, float angleDegrees); void Yaw(float angleDegrees); @@ -70,7 +72,9 @@ class CameraController final void MoveToPosition(cd::Point position, cd::Vec3f lookAt); // TODO : generic solution to process mouse / key input events for UI panels in different areas. - void SetIsInViewScene(bool isIn) { m_isInViewScene = isIn; } + void SetIsFirstClickInViewScene(bool isIn) { m_isFirstClickInViewScene = isIn; } + + void SetIsMouseInViewScene(bool isIn) { m_isMouseInViewScene = isIn; } bool GetViewIsMoved() { return m_isMouseMovedInView; } @@ -103,7 +107,8 @@ class CameraController final bool m_isTracking = false; bool m_isMoving = false; - bool m_isInViewScene = false; + bool m_isFirstClickInViewScene = false; + bool m_isMouseInViewScene = true; bool m_isMouseMovedInView = false; };