Fixes the gimbal lock and rotation issues

This commit is contained in:
2025-02-27 12:06:22 -05:00
parent 16044154fb
commit 1d348e1071
27 changed files with 568 additions and 306 deletions

View File

@@ -14,12 +14,21 @@ namespace fgl::engine::gui
ImGui::InputText( "Name", &name_input_temp );
if ( game_object.getName() != name_input_temp ) game_object.setName( name_input_temp );
auto& transform { game_object.getTransform() };
// Transform - Position
dragFloat3( "Position", game_object.getTransform().translation.vec() );
dragFloat3( "Position", transform.translation.vec() );
dragFloat3Rot( "Rotation", game_object.getRotation() );
if ( transform.rotation.isEuler() )
{
dragFloat3Rot( "Rotation", transform.rotation.euler() );
}
else
{
ImGui::Text( "Rotation was in quaternion" );
}
dragFloat3( "Scale", game_object.getScale() );
dragFloat3( "Scale", transform.scale );
}
static GameObjectComponentPtr SELECTED_COMPONENT { nullptr };

View File

@@ -4,26 +4,24 @@
#include "helpers.hpp"
#include "primitives/Rotation.hpp"
#include "../../../engine/primitives/rotation/QuatRotation.hpp"
#include "primitives/rotation/EulerRotation.hpp"
namespace fgl::engine::gui
{
float clampEuler( const float value )
{
if ( value >= 180.0f )
{
// Wrap around.
return value - 360.0f;
}
else if ( value <= -180.0f )
{
return value + 360.0f;
}
constexpr float max { 180.0f };
constexpr float wrap { 360.0f };
if ( value >= max ) return clampEuler( value - wrap );
if ( value <= -max ) return clampEuler( value + wrap );
return value;
}
void dragFloat3Rot( const char* const label, Rotation& rot )
void dragFloat3Rot( const char* const label, EulerRotation& rot )
{
enum Axis
{
@@ -32,7 +30,7 @@ namespace fgl::engine::gui
Roll = 2
};
const glm::vec3 c_dat { rot.euler() };
const glm::vec3 c_dat { rot.vec() };
glm::vec3 dat { glm::degrees( c_dat ) };
ImGui::DragFloat3( label, &dat.x, 1.0f );
@@ -49,19 +47,19 @@ namespace fgl::engine::gui
if ( changed[ Pitch ] )
{
dat[ Pitch ] = clampEuler( dat[ Pitch ] );
rot.setX( dat[ Pitch ] );
}
if ( changed[ Roll ] )
{
dat[ Roll ] = clampEuler( dat[ Roll ] );
rot.setZ( dat[ Roll ] );
rot.x = dat[ Pitch ];
}
if ( changed[ Yaw ] )
{
dat[ Yaw ] = clampEuler( dat[ Yaw ] );
rot.setY( dat[ Yaw ] );
rot.y = dat[ Yaw ];
}
if ( changed[ Roll ] )
{
dat[ Roll ] = clampEuler( dat[ Roll ] );
rot.z = dat[ Roll ];
}
}
} // namespace fgl::engine::gui

View File

@@ -12,8 +12,9 @@
namespace fgl::engine
{
struct Rotation;
}
struct EulerRotation;
struct QuatRotation;
} // namespace fgl::engine
namespace fgl::engine::gui
{
@@ -22,6 +23,6 @@ namespace fgl::engine::gui
ImGui::DragFloat3( label, &vec.x );
}
void dragFloat3Rot( const char* label, Rotation& rot );
void dragFloat3Rot( const char* label, EulerRotation& rot );
} // namespace fgl::engine::gui