From 79667be4582c75c3ceff0134b563710d362fcaa1 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Sun, 29 Sep 2024 15:46:59 -0400 Subject: [PATCH] Add world based axis modification to rotations --- src/editor/src/gui/camera.cpp | 4 ++-- src/engine/primitives/Rotation.cpp | 18 ++++++++++++++++++ src/engine/primitives/Rotation.hpp | 6 ++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/editor/src/gui/camera.cpp b/src/editor/src/gui/camera.cpp index 9b0c923..8793aff 100644 --- a/src/editor/src/gui/camera.cpp +++ b/src/editor/src/gui/camera.cpp @@ -42,12 +42,12 @@ namespace fgl::engine::gui if ( ImGui::IsKeyDown( ImGuiKey_RightArrow ) ) { - pitch_change.addZ( delta_time * yaw_rate ); + pitch_change.addZWorld( delta_time * yaw_rate ); } if ( ImGui::IsKeyDown( ImGuiKey_LeftArrow ) ) { - pitch_change.addZ( -( delta_time * yaw_rate ) ); + pitch_change.addZWorld( -( delta_time * yaw_rate ) ); } Vector move_dir { 0.0f }; diff --git a/src/engine/primitives/Rotation.cpp b/src/engine/primitives/Rotation.cpp index 6905567..aae8e79 100644 --- a/src/engine/primitives/Rotation.cpp +++ b/src/engine/primitives/Rotation.cpp @@ -119,4 +119,22 @@ namespace fgl::engine *this = *this * q; } + void Rotation::addXWorld( const float value ) + { + const glm::quat q { glm::angleAxis( value, constants::WORLD_X ) }; + *this = q * *this; + } + + void Rotation::addYWorld( const float value ) + { + const glm::quat q { glm::angleAxis( value, constants::WORLD_Y ) }; + *this = q * *this; + } + + void Rotation::addZWorld( const float value ) + { + const glm::quat q { glm::angleAxis( value, constants::WORLD_Z ) }; + *this = q * *this; + } + } // namespace fgl::engine diff --git a/src/engine/primitives/Rotation.hpp b/src/engine/primitives/Rotation.hpp index d60cad4..e56b198 100644 --- a/src/engine/primitives/Rotation.hpp +++ b/src/engine/primitives/Rotation.hpp @@ -54,10 +54,16 @@ namespace fgl::engine void setY( float ); void setZ( float ); + // These will add a rotation using the local axis void addX( float ); void addY( float ); void addZ( float ); + // These will add a rotation using the world axis + void addXWorld( float ); + void addYWorld( float ); + void addZWorld( float ); + // internal inline glm::quat internal_quat() const { return static_cast< glm::quat >( *this ); }