diff --git a/examples/ExampleApps/MovingCubeApp.cpp b/examples/ExampleApps/MovingCubeApp.cpp index ba970b6..9297ee5 100644 --- a/examples/ExampleApps/MovingCubeApp.cpp +++ b/examples/ExampleApps/MovingCubeApp.cpp @@ -39,7 +39,8 @@ namespace OpenVulkano { Scene::Scene m_scene; Scene::MorphableCamera m_camera; - Scene::MorphableCameraController m_cameraControl; + Scene::MorphableCameraController m_morphableCameraControl; + FreeCamCameraController m_cameraControl; Scene::Material m_material; Scene::Shader m_shader; @@ -113,7 +114,11 @@ namespace OpenVulkano } public: - MovingCubeAppImpl() : m_camera(90, 16, 9, 0.1, 1000) { m_cameraControl.Init(&m_camera); } + MovingCubeAppImpl() : m_camera(90, 16, 9, 0.1, 1000) + { + m_morphableCameraControl.Init(&m_camera); + m_cameraControl.Init(&m_camera); + } void Init() override { @@ -190,6 +195,7 @@ namespace OpenVulkano void Tick() override { m_cameraControl.Tick(); + m_morphableCameraControl.Tick(); m_simpleAnimationController.Tick(); m_sequenceAnimationController.Tick(); } diff --git a/openVulkanoCpp/Scene/MorphableCamera.cpp b/openVulkanoCpp/Scene/MorphableCamera.cpp index 40807b6..9397058 100644 --- a/openVulkanoCpp/Scene/MorphableCamera.cpp +++ b/openVulkanoCpp/Scene/MorphableCamera.cpp @@ -15,7 +15,7 @@ namespace OpenVulkano::Scene Math::Matrix4f result; for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { result[i][j] = glm::mix(mat1[i][j], mat2[i][j], t); } + result[i] = Math::Utils::mix(mat1[i], mat2[i], t); } return result; } @@ -25,8 +25,17 @@ namespace OpenVulkano::Scene PerspectiveCamera::UpdateProjectionMatrix(); float aspectH = m_aspect; float aspectV = 1; - m_orthoMatrix = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane); - m_projection = BlendMatrices(m_projection, m_orthoMatrix, m_morphState); - UpdateViewProjectionMatrix(); + if (m_morphState == 0) { UpdateViewProjectionMatrix(); } + else if (m_morphState == 1) + { + m_projection = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane); + UpdateViewProjectionMatrix(); + } + else + { + m_orthoMatrix = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane); + m_projection = BlendMatrices(m_projection, m_orthoMatrix, m_morphState); + UpdateViewProjectionMatrix(); + } } } \ No newline at end of file diff --git a/openVulkanoCpp/Scene/MorphableCameraController.cpp b/openVulkanoCpp/Scene/MorphableCameraController.cpp index cfce8fa..9ad569b 100644 --- a/openVulkanoCpp/Scene/MorphableCameraController.cpp +++ b/openVulkanoCpp/Scene/MorphableCameraController.cpp @@ -17,22 +17,16 @@ namespace OpenVulkano::Scene , m_animationDuration(1.0f) , m_currentTime(0.0f) , m_isMorphing(false) - , m_targetMorphState(false) + , m_targetMorphStatePerspective(false) { auto input = OpenVulkano::Input::InputManager::GetInstance(); m_actionMorph = input->GetAction("morph"); - m_actionForward = input->GetAction("forward"); - m_actionSide = input->GetAction("side"); - m_actionUp = input->GetAction("up"); - m_actionLookUp = input->GetAction("look up"); - m_actionLookSide = input->GetAction("look side"); - m_actionBoost = input->GetAction("boost"); } void MorphableCameraController::Init(MorphableCamera* camera) { CameraController::Init(camera); - SetDefaultKeybindings(); + m_actionMorph->BindKey(Input::InputKey::Keyboard::KEY_P); } void MorphableCameraController::Tick() @@ -44,7 +38,7 @@ namespace OpenVulkano::Scene { m_isMorphing = true; m_currentTime = 0.0f; - m_targetMorphState = !m_targetMorphState; + m_targetMorphStatePerspective = !m_targetMorphStatePerspective; } m_wasMorphingKeyDown = isMorphingDown; @@ -58,52 +52,8 @@ namespace OpenVulkano::Scene t = 1.0f; m_isMorphing = false; } - float newState = m_targetMorphState ? t : (1.0f - t); + float newState = m_targetMorphStatePerspective ? t : (1.0f - t); static_cast(GetCamera())->SetMorphState(newState); } - - // Movement logic - const float MOVEMENT_SPEED = 3.0f; - const float BOOST_MULT = 2.0f; - - Math::Vector3f_SIMD vec(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp), - -input->GetAxis(m_actionForward)); - if (Math::Utils::length2(vec) > 1.0f) { vec = Math::Utils::normalize(vec); } - - float dt = CURRENT_FRAME.frameTime; - vec = vec * dt * MOVEMENT_SPEED; - if (input->GetButton(m_actionBoost)) { vec *= BOOST_MULT; } - - m_yaw -= input->GetAxis(m_actionLookSide) * dt / 2.0f; - m_pitch -= input->GetAxis(m_actionLookUp) * dt / 2.0f; - m_pitch = std::min(1.4f, std::max(-1.4f, m_pitch)); - - const Math::QuaternionF rot(Math::Vector3f(m_pitch, m_yaw, 0)); - m_position += rot * vec; - Math::Matrix4f camTransformation = Math::Utils::toMat4(rot); - camTransformation[3] = Math::Vector4f(m_position, 1); - GetCamera()->SetMatrix(camTransformation); - } - - void MorphableCameraController::SetDefaultKeybindings() - { - m_actionMorph->BindKey(Input::InputKey::Keyboard::KEY_P); - - m_actionForward->BindKey(Input::InputKey::Controller::AXIS_LEFT_Y); - m_actionForward->BindAxisButtons(Input::InputKey::Keyboard::KEY_W, Input::InputKey::Keyboard::KEY_S); - m_actionForward->BindKey(Input::InputKey::Touch::AXIS_PAN_TWO_FINGERS_Y, -0.0025f); - m_actionSide->BindKey(Input::InputKey::Controller::AXIS_LEFT_X); - m_actionSide->BindAxisButtons(Input::InputKey::Keyboard::KEY_D, Input::InputKey::Keyboard::KEY_A); - m_actionSide->BindKey(Input::InputKey::Touch::AXIS_PAN_TWO_FINGERS_X, 0.0025f); - m_actionLookUp->BindKey(Input::InputKey::Controller::AXIS_RIGHT_Y); - m_actionLookUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_DOWN, Input::InputKey::Keyboard::KEY_UP); - m_actionLookUp->BindKey(Input::InputKey::Touch::AXIS_PAN_Y, 0.10f); - m_actionLookSide->BindKey(Input::InputKey::Controller::AXIS_RIGHT_X); - m_actionLookSide->BindAxisButtons(Input::InputKey::Keyboard::KEY_RIGHT, Input::InputKey::Keyboard::KEY_LEFT); - m_actionLookSide->BindKey(Input::InputKey::Touch::AXIS_PAN_X, 0.10f); - m_actionLookUp->BindKey(Input::InputKey::Mouse::AXIS_Y); - m_actionLookSide->BindKey(Input::InputKey::Mouse::AXIS_X); - m_actionUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_SPACE, Input::InputKey::Keyboard::KEY_LEFT_CONTROL); - m_actionBoost->BindKey(Input::InputKey::Keyboard::KEY_LEFT_SHIFT); } } \ No newline at end of file diff --git a/openVulkanoCpp/Scene/MorphableCameraController.hpp b/openVulkanoCpp/Scene/MorphableCameraController.hpp index 77f403c..f5c5084 100644 --- a/openVulkanoCpp/Scene/MorphableCameraController.hpp +++ b/openVulkanoCpp/Scene/MorphableCameraController.hpp @@ -18,17 +18,8 @@ namespace OpenVulkano::Scene double m_animationDuration; double m_currentTime; bool m_isMorphing; - bool m_targetMorphState; // true for perspective, false for orthographic + bool m_targetMorphStatePerspective; // true for perspective, false for orthographic - float m_yaw = 0, m_pitch = 0, m_boostFactor = 2; - Math::Vector3f_SIMD m_position = { 0, 0, 0 }; - - Input::InputAction* m_actionForward; - Input::InputAction* m_actionSide; - Input::InputAction* m_actionUp; - Input::InputAction* m_actionLookUp; - Input::InputAction* m_actionLookSide; - Input::InputAction* m_actionBoost; Input::InputAction* m_actionMorph; bool m_wasMorphingKeyDown = false; @@ -37,10 +28,10 @@ namespace OpenVulkano::Scene void Init(MorphableCamera* camera); void Tick() override; - void SetDefaultKeybindings(); void SetDuration(double duration) { m_animationDuration = duration; } double GetDuration() { return m_animationDuration; } + void SetTargetState(bool toPerspective) { m_targetMorphStatePerspective = toPerspective; } void Reset() { m_currentTime = 0; } }; } \ No newline at end of file