From 0cd161184eaf0a764715369da1589f3723b64d66 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Mon, 14 Mar 2016 06:00:12 +0100 Subject: [PATCH 1/2] Smoother movement for editor camera. --- include/Engine/Editor/EditorSystem.h | 1 + src/Engine/Editor/EditorSystem.cpp | 39 +++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/Engine/Editor/EditorSystem.h b/include/Engine/Editor/EditorSystem.h index 7fe8ce6f..0fc14cb4 100644 --- a/include/Engine/Editor/EditorSystem.h +++ b/include/Engine/Editor/EditorSystem.h @@ -43,6 +43,7 @@ private: EditorGUI::WidgetSpace m_WidgetSpace = EditorGUI::WidgetSpace::Global; EntityWrapper m_Widget = EntityWrapper::Invalid; EntityWrapper m_CurrentSelection = EntityWrapper::Invalid; + glm::vec3 m_CamVelocity; // Utility functions EntityWrapper importEntity(EntityWrapper parent, boost::filesystem::path filePath); diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 27576d5d..de5b14d9 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -8,6 +8,7 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame : System(params) , m_Renderer(renderer) , m_RenderFrame(renderFrame) + , m_CamVelocity(0.f) { m_EditorWorld = new World(); m_EditorWorldSystemPipeline = new SystemPipeline(m_EditorWorld, m_EventBroker, IsClient, IsServer); @@ -94,7 +95,43 @@ void EditorSystem::Update(double dt) ori.x(newOri.x); ori.y(newOri.y); Field pos = cameraTransform["Position"]; - pos += m_EditorCameraInputController->Movement() * glm::inverse(glm::quat(ori)) * (float)actualDelta; + auto move = m_EditorCameraInputController->Movement(); + const float decreaseAccelleration = 3.75f; + const float increaseAccelleration = 5.25f; + if (move.x == 0) { + m_CamVelocity.x -= m_CamVelocity.x * (float)actualDelta * decreaseAccelleration; + //m_CamVelocity.x -= glm::sign(m_CamVelocity.x) * (float)actualDelta * decreaseAccelleration; + if (glm::abs(m_CamVelocity.x) < 0.01f) { + m_CamVelocity.x = 0; + } + } else { + m_CamVelocity.x += glm::sign(move.x) * (float)actualDelta * increaseAccelleration; + m_CamVelocity.x = glm::max(m_CamVelocity.x, -glm::abs(move.x)); + m_CamVelocity.x = glm::min(m_CamVelocity.x, glm::abs(move.x)); + } + if (move.y == 0) { + m_CamVelocity.y -= m_CamVelocity.y * (float)actualDelta * decreaseAccelleration; + //m_CamVelocity.y -= glm::sign(m_CamVelocity.y) * (float)actualDelta * decreaseAccelleration; + if (glm::abs(m_CamVelocity.y) < 0.01f) { + m_CamVelocity.y = 0; + } + } else { + m_CamVelocity.y += glm::sign(move.y) * (float)actualDelta * increaseAccelleration; + m_CamVelocity.y = glm::max(m_CamVelocity.y, -glm::abs(move.y)); + m_CamVelocity.y = glm::min(m_CamVelocity.y, glm::abs(move.y)); + } + if (move.z == 0) { + m_CamVelocity.z -= m_CamVelocity.z * (float)actualDelta * decreaseAccelleration; + //m_CamVelocity.z -= glm::sign(m_CamVelocity.z) * (float)actualDelta * decreaseAccelleration; + if (glm::abs(m_CamVelocity.z) < 0.01f) { + m_CamVelocity.z = 0; + } + } else { + m_CamVelocity.z += glm::sign(move.z) * (float)actualDelta * increaseAccelleration; + m_CamVelocity.z = glm::max(m_CamVelocity.z, -glm::abs(move.z)); + m_CamVelocity.z = glm::min(m_CamVelocity.z, glm::abs(move.z)); + } + pos += m_CamVelocity * glm::inverse(glm::quat(ori)) * (float)actualDelta; } } From fb3842ba5b7d608bf68d332eb18c52659bede578 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Mon, 14 Mar 2016 06:05:11 +0100 Subject: [PATCH 2/2] Indentation. --- src/Engine/Editor/EditorSystem.cpp | 88 +++++++++++++++--------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 032fddb1..6ef2b34e 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -86,53 +86,53 @@ void EditorSystem::Update(double dt) m_EditorWorldSystemPipeline->Update(actualDelta); } - ComponentWrapper& cameraTransform = m_EditorCamera["Transform"]; - Field ori = cameraTransform["Orientation"]; - glm::vec3 newOri; - newOri.x = glm::mix(ori.x(), m_EditorCameraInputController->Rotation().x, 0.05f); - newOri.y = glm::mix(ori.y(), m_EditorCameraInputController->Rotation().y, 0.05f); - //ori.x(m_EditorCameraInputController->Rotation().x); - //ori.y(m_EditorCameraInputController->Rotation().y); - ori.x(newOri.x); - ori.y(newOri.y); - Field pos = cameraTransform["Position"]; - auto move = m_EditorCameraInputController->Movement(); - const float decreaseAccelleration = 3.75f; - const float increaseAccelleration = 5.25f; - if (move.x == 0) { - m_CamVelocity.x -= m_CamVelocity.x * (float)actualDelta * decreaseAccelleration; - //m_CamVelocity.x -= glm::sign(m_CamVelocity.x) * (float)actualDelta * decreaseAccelleration; - if (glm::abs(m_CamVelocity.x) < 0.01f) { - m_CamVelocity.x = 0; - } - } else { - m_CamVelocity.x += glm::sign(move.x) * (float)actualDelta * increaseAccelleration; - m_CamVelocity.x = glm::max(m_CamVelocity.x, -glm::abs(move.x)); - m_CamVelocity.x = glm::min(m_CamVelocity.x, glm::abs(move.x)); + ComponentWrapper& cameraTransform = m_EditorCamera["Transform"]; + Field ori = cameraTransform["Orientation"]; + glm::vec3 newOri; + newOri.x = glm::mix(ori.x(), m_EditorCameraInputController->Rotation().x, 0.05f); + newOri.y = glm::mix(ori.y(), m_EditorCameraInputController->Rotation().y, 0.05f); + //ori.x(m_EditorCameraInputController->Rotation().x); + //ori.y(m_EditorCameraInputController->Rotation().y); + ori.x(newOri.x); + ori.y(newOri.y); + Field pos = cameraTransform["Position"]; + auto move = m_EditorCameraInputController->Movement(); + const float decreaseAccelleration = 3.75f; + const float increaseAccelleration = 5.25f; + if (move.x == 0) { + m_CamVelocity.x -= m_CamVelocity.x * (float)actualDelta * decreaseAccelleration; + //m_CamVelocity.x -= glm::sign(m_CamVelocity.x) * (float)actualDelta * decreaseAccelleration; + if (glm::abs(m_CamVelocity.x) < 0.01f) { + m_CamVelocity.x = 0; } - if (move.y == 0) { - m_CamVelocity.y -= m_CamVelocity.y * (float)actualDelta * decreaseAccelleration; - //m_CamVelocity.y -= glm::sign(m_CamVelocity.y) * (float)actualDelta * decreaseAccelleration; - if (glm::abs(m_CamVelocity.y) < 0.01f) { - m_CamVelocity.y = 0; - } - } else { - m_CamVelocity.y += glm::sign(move.y) * (float)actualDelta * increaseAccelleration; - m_CamVelocity.y = glm::max(m_CamVelocity.y, -glm::abs(move.y)); - m_CamVelocity.y = glm::min(m_CamVelocity.y, glm::abs(move.y)); + } else { + m_CamVelocity.x += glm::sign(move.x) * (float)actualDelta * increaseAccelleration; + m_CamVelocity.x = glm::max(m_CamVelocity.x, -glm::abs(move.x)); + m_CamVelocity.x = glm::min(m_CamVelocity.x, glm::abs(move.x)); + } + if (move.y == 0) { + m_CamVelocity.y -= m_CamVelocity.y * (float)actualDelta * decreaseAccelleration; + //m_CamVelocity.y -= glm::sign(m_CamVelocity.y) * (float)actualDelta * decreaseAccelleration; + if (glm::abs(m_CamVelocity.y) < 0.01f) { + m_CamVelocity.y = 0; } - if (move.z == 0) { - m_CamVelocity.z -= m_CamVelocity.z * (float)actualDelta * decreaseAccelleration; - //m_CamVelocity.z -= glm::sign(m_CamVelocity.z) * (float)actualDelta * decreaseAccelleration; - if (glm::abs(m_CamVelocity.z) < 0.01f) { - m_CamVelocity.z = 0; - } - } else { - m_CamVelocity.z += glm::sign(move.z) * (float)actualDelta * increaseAccelleration; - m_CamVelocity.z = glm::max(m_CamVelocity.z, -glm::abs(move.z)); - m_CamVelocity.z = glm::min(m_CamVelocity.z, glm::abs(move.z)); + } else { + m_CamVelocity.y += glm::sign(move.y) * (float)actualDelta * increaseAccelleration; + m_CamVelocity.y = glm::max(m_CamVelocity.y, -glm::abs(move.y)); + m_CamVelocity.y = glm::min(m_CamVelocity.y, glm::abs(move.y)); + } + if (move.z == 0) { + m_CamVelocity.z -= m_CamVelocity.z * (float)actualDelta * decreaseAccelleration; + //m_CamVelocity.z -= glm::sign(m_CamVelocity.z) * (float)actualDelta * decreaseAccelleration; + if (glm::abs(m_CamVelocity.z) < 0.01f) { + m_CamVelocity.z = 0; } - pos += m_CamVelocity * glm::inverse(glm::quat(ori)) * (float)actualDelta; + } else { + m_CamVelocity.z += glm::sign(move.z) * (float)actualDelta * increaseAccelleration; + m_CamVelocity.z = glm::max(m_CamVelocity.z, -glm::abs(move.z)); + m_CamVelocity.z = glm::min(m_CamVelocity.z, glm::abs(move.z)); + } + pos += m_CamVelocity * glm::inverse(glm::quat(ori)) * (float)actualDelta; } void EditorSystem::Enable()