From 5543e19531375b7cd9a97d765718172d357addb1 Mon Sep 17 00:00:00 2001 From: Anemunt <69436164+darkresident55@users.noreply.github.com> Date: Fri, 12 Dec 2025 22:50:41 -0500 Subject: [PATCH] =?UTF-8?q?fixed=20rotation=20uh,=20being=20really=20rotat?= =?UTF-8?q?y=20=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Engine.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Engine.cpp b/src/Engine.cpp index 7ee851e..535e0d9 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -139,6 +139,20 @@ Camera Engine::makeCameraFromObject(const SceneObject& obj) const { return cam; } +namespace { +// Equivalent to glm::extractEulerAngleXYZ without depending on the experimental header. +glm::vec3 ExtractEulerXYZ(const glm::mat3& m) { + float T1 = std::atan2(m[2][1], m[2][2]); + float C2 = std::sqrt(m[0][0] * m[0][0] + m[1][0] * m[1][0]); + float T2 = std::atan2(-m[2][0], C2); + float S1 = std::sin(T1); + float C1 = std::cos(T1); + float T3 = std::atan2(S1 * m[0][2] - C1 * m[0][1], C1 * m[1][1] - S1 * m[1][2]); + // GLM's extractEulerAngleXYZ returns (-T1, -T2, -T3) + return glm::vec3(-T1, -T2, -T3); +} +} + void Engine::DecomposeMatrix(const glm::mat4& matrix, glm::vec3& pos, glm::vec3& rot, glm::vec3& scale) { pos = glm::vec3(matrix[3]); scale.x = glm::length(glm::vec3(matrix[0])); @@ -150,7 +164,8 @@ void Engine::DecomposeMatrix(const glm::mat4& matrix, glm::vec3& pos, glm::vec3& if (scale.y != 0.0f) rotMat[1] /= scale.y; if (scale.z != 0.0f) rotMat[2] /= scale.z; - rot = glm::eulerAngles(glm::quat_cast(rotMat)); + // Use explicit XYZ extraction so yaw isn't clamped to [-90, 90] like glm::yaw/pitch/roll. + rot = ExtractEulerXYZ(rotMat); } void Engine::recordState(const char* /*reason*/) {