From d21c54f9786cf4ff92ef716e5ef40d95e33b8ec3 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Wed, 5 Jun 2024 11:57:12 -0400 Subject: [PATCH] Cleanup method for generating Tait Bryan Matricies from a rotation --- src/engine/math/taitBryanMatrix.cpp | 98 +++++++++-------------------- src/engine/math/taitBryanMatrix.hpp | 5 +- 2 files changed, 32 insertions(+), 71 deletions(-) diff --git a/src/engine/math/taitBryanMatrix.cpp b/src/engine/math/taitBryanMatrix.cpp index 403284d..2e85fbb 100644 --- a/src/engine/math/taitBryanMatrix.cpp +++ b/src/engine/math/taitBryanMatrix.cpp @@ -16,86 +16,42 @@ namespace fgl::engine { - template < int N > - inline std::tuple< float, float > extract( const glm::vec3 rotation, const RotationOrder order ) + using CosSinPair = std::tuple< float, float >; + + inline std::tuple< CosSinPair, CosSinPair, CosSinPair > + extract( const glm::vec3 rotation, const RotationOrder order ) { switch ( order ) { case XZY: - switch ( N ) - { - case 1: - return { glm::cos( rotation.x ), glm::sin( rotation.x ) }; - case 2: - return { glm::cos( rotation.z ), glm::sin( rotation.z ) }; - case 3: - return { glm::cos( rotation.y ), glm::sin( rotation.y ) }; - } - break; + return { { glm::cos( rotation.x ), glm::sin( rotation.x ) }, + { glm::cos( rotation.z ), glm::sin( rotation.z ) }, + { glm::cos( rotation.y ), glm::sin( rotation.y ) } }; case XYZ: // DEFAULT - switch ( N ) - { - case 1: - return { glm::cos( rotation.x ), glm::sin( rotation.x ) }; - case 2: - return { glm::cos( rotation.y ), glm::sin( rotation.y ) }; - case 3: - return { glm::cos( rotation.z ), glm::sin( rotation.z ) }; - } - break; + return { { glm::cos( rotation.x ), glm::sin( rotation.x ) }, + { glm::cos( rotation.y ), glm::sin( rotation.y ) }, + { glm::cos( rotation.z ), glm::sin( rotation.z ) } }; case YXZ: - switch ( N ) - { - case 1: - return { glm::cos( rotation.y ), glm::sin( rotation.y ) }; - case 2: - return { glm::cos( rotation.x ), glm::sin( rotation.x ) }; - case 3: - return { glm::cos( rotation.z ), glm::sin( rotation.z ) }; - } - break; + return { { glm::cos( rotation.y ), glm::sin( rotation.y ) }, + { glm::cos( rotation.x ), glm::sin( rotation.x ) }, + { glm::cos( rotation.z ), glm::sin( rotation.z ) } }; case YZX: - switch ( N ) - { - case 1: - return { glm::cos( rotation.y ), glm::sin( rotation.y ) }; - case 2: - return { glm::cos( rotation.z ), glm::sin( rotation.z ) }; - case 3: - return { glm::cos( rotation.x ), glm::sin( rotation.x ) }; - } - break; + return { { glm::cos( rotation.y ), glm::sin( rotation.y ) }, + { glm::cos( rotation.z ), glm::sin( rotation.z ) }, + { glm::cos( rotation.x ), glm::sin( rotation.x ) } }; case ZYX: - switch ( N ) - { - case 1: - return { glm::cos( rotation.z ), glm::sin( rotation.z ) }; - case 2: - return { glm::cos( rotation.y ), glm::sin( rotation.y ) }; - case 3: - return { glm::cos( rotation.x ), glm::sin( rotation.x ) }; - } - break; + return { { glm::cos( rotation.z ), glm::sin( rotation.z ) }, + { glm::cos( rotation.y ), glm::sin( rotation.y ) }, + { glm::cos( rotation.x ), glm::sin( rotation.x ) } }; case ZXY: - switch ( N ) - { - case 1: - return { glm::cos( rotation.z ), glm::sin( rotation.z ) }; - case 2: - return { glm::cos( rotation.x ), glm::sin( rotation.x ) }; - case 3: - return { glm::cos( rotation.y ), glm::sin( rotation.y ) }; - } - break; + return { { glm::cos( rotation.z ), glm::sin( rotation.z ) }, + { glm::cos( rotation.x ), glm::sin( rotation.x ) }, + { glm::cos( rotation.y ), glm::sin( rotation.y ) } }; case END_OF_ENUM: throw std::runtime_error( "Unimplemented rotation order" ); } - std::unreachable(); - } - glm::mat3 taitBryanMatrix( const float x, const float y, const float z, const RotationOrder order ) - { - return taitBryanMatrix( glm::vec3( x, y, z ), order ); + std::unreachable(); } glm::mat3 taitBryanMatrix( const glm::vec3 rotation, const RotationOrder order ) @@ -104,9 +60,11 @@ namespace fgl::engine //TODO: Debug with Entry, There has got to be a better fix then this. - const auto [ c1, s1 ] = extract< 1 >( rotation, order ); - const auto [ c2, s2 ] = extract< 2 >( rotation, order ); - const auto [ c3, s3 ] = extract< 3 >( rotation, order ); + const auto [ p1, p2, p3 ] = extract( rotation, order ); + + const auto [ c1, s1 ] = p1; + const auto [ c2, s2 ] = p2; + const auto [ c3, s3 ] = p3; switch ( order ) { diff --git a/src/engine/math/taitBryanMatrix.hpp b/src/engine/math/taitBryanMatrix.hpp index f73ff6f..2086edd 100644 --- a/src/engine/math/taitBryanMatrix.hpp +++ b/src/engine/math/taitBryanMatrix.hpp @@ -25,6 +25,9 @@ namespace fgl::engine glm::mat3 taitBryanMatrix( const glm::vec3 rotation, const RotationOrder order = DEFAULT ); - glm::mat3 taitBryanMatrix( const float x, const float y, const float z, const RotationOrder order = DEFAULT ); + inline glm::mat3 taitBryanMatrix( const float x, const float y, const float z, const RotationOrder order = DEFAULT ) + { + return taitBryanMatrix( glm::vec3( x, y, z ), order ); + } } // namespace fgl::engine