Update leenkx/Sources/iron/math/Quat.hx

This commit is contained in:
Onek8 2025-04-09 15:02:07 +00:00
parent 2cd91f598c
commit f8a08a41b1

View File

@ -399,17 +399,33 @@ class Quat {
@return This quaternion. @return This quaternion.
**/ **/
public inline function fromEulerOrdered(e: Vec4, order: String): Quat { public inline function fromEulerOrdered(e: Vec4, order: String): Quat {
var c1 = Math.cos(e.x / 2);
var c2 = Math.cos(e.y / 2);
var c3 = Math.cos(e.z / 2);
var s1 = Math.sin(e.x / 2);
var s2 = Math.sin(e.y / 2);
var s3 = Math.sin(e.z / 2);
var mappedAngles = new Vec4();
switch (order) {
case "XYZ":
mappedAngles.set(e.x, e.y, e.z);
case "XZY":
mappedAngles.set(e.x, e.z, e.y);
case "YXZ":
mappedAngles.set(e.y, e.x, e.z);
case "YZX":
mappedAngles.set(e.y, e.z, e.x);
case "ZXY":
mappedAngles.set(e.z, e.x, e.y);
case "ZYX":
mappedAngles.set(e.z, e.y, e.x);
}
var c1 = Math.cos(mappedAngles.x / 2);
var c2 = Math.cos(mappedAngles.y / 2);
var c3 = Math.cos(mappedAngles.z / 2);
var s1 = Math.sin(mappedAngles.x / 2);
var s2 = Math.sin(mappedAngles.y / 2);
var s3 = Math.sin(mappedAngles.z / 2);
var qx = new Quat(s1, 0, 0, c1); var qx = new Quat(s1, 0, 0, c1);
var qy = new Quat(0, s2, 0, c2); var qy = new Quat(0, s2, 0, c2);
var qz = new Quat(0, 0, s3, c3); var qz = new Quat(0, 0, s3, c3);
// Original multiplication sequence (implements reverse of 'order')
if (order.charAt(2) == 'X') if (order.charAt(2) == 'X')
this.setFrom(qx); this.setFrom(qx);
else if (order.charAt(2) == 'Y') else if (order.charAt(2) == 'Y')
@ -429,7 +445,7 @@ class Quat {
else else
this.mult(qz); this.mult(qz);
// TO DO quick fix doesnt make sense. // TO DO quick fix somethings wrong..
this.x = -this.x; this.x = -this.x;
this.y = -this.y; this.y = -this.y;
this.z = -this.z; this.z = -this.z;