From 559a3b8b39b35a7f6542d0b567dc4559b421edbd Mon Sep 17 00:00:00 2001 From: Onek8 Date: Sun, 6 Apr 2025 14:30:52 +0000 Subject: [PATCH] Update leenkx/Sources/iron/math/Quat.hx --- leenkx/Sources/iron/math/Quat.hx | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/leenkx/Sources/iron/math/Quat.hx b/leenkx/Sources/iron/math/Quat.hx index e0d744f..3c23b89 100644 --- a/leenkx/Sources/iron/math/Quat.hx +++ b/leenkx/Sources/iron/math/Quat.hx @@ -66,12 +66,32 @@ class Quat { } public inline function fromAxisAngle(axis: Vec4, angle: FastFloat): Quat { - var s: FastFloat = Math.sin(angle * 0.5); - x = axis.x * s; - y = axis.y * s; - z = axis.z * s; - w = Math.cos(angle * 0.5); - return normalize(); + //var s: FastFloat = Math.sin(angle * 0.5); + //x = axis.x * s; + //y = axis.y * s; + //z = axis.z * s; + //w = Math.cos(angle * 0.5); + //return normalize(); + // Normalize the axis vector first + var axisLen = Math.sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); + if (axisLen > 0.00001) { + var aL = 1.0 / axisLen; + var nX = axis.x * aL; + var nY = axis.y * aL; + var nZ = axis.z * aL; + var halfAngle = angle * 0.5; + var s: FastFloat = Math.sin(halfAngle); + x = nX * s; + y = nY * s; + z = nZ * s; + w = Math.cos(halfAngle); + } else { + x = 0.0; + y = 0.0; + z = 0.0; + w = 1.0; + } + return this; } public inline function toAxisAngle(axis: Vec4): FastFloat {