From 494ecad737b8fc9acaf177838e265a9271d53436 Mon Sep 17 00:00:00 2001 From: andzdroid Date: Thu, 23 Apr 2026 21:00:22 +0100 Subject: [PATCH] core/math/linalg: Fix negated quaternions in angle_from_quaternion --- core/math/linalg/specific.odin | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/math/linalg/specific.odin b/core/math/linalg/specific.odin index cfb1c2b0d..e90af23ed 100644 --- a/core/math/linalg/specific.odin +++ b/core/math/linalg/specific.odin @@ -512,7 +512,8 @@ quaternion_angle_axis :: proc{ @(require_results) angle_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> f16 { if abs(q.w) > math.SQRT_THREE*0.5 { - return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 + angle := math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 + return q.w < 0 ? math.TAU - angle : angle } return math.acos(q.w) * 2 @@ -520,7 +521,8 @@ angle_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> f16 { @(require_results) angle_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> f32 { if abs(q.w) > math.SQRT_THREE*0.5 { - return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 + angle := math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 + return q.w < 0 ? math.TAU - angle : angle } return math.acos(q.w) * 2 @@ -528,7 +530,8 @@ angle_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> f32 { @(require_results) angle_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> f64 { if abs(q.w) > math.SQRT_THREE*0.5 { - return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 + angle := math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2 + return q.w < 0 ? math.TAU - angle : angle } return math.acos(q.w) * 2