This commit is contained in:
2026-08-27 22:41:52 -07:00
parent 7319040624
commit ce09e510e9
4 changed files with 22 additions and 75 deletions

View File

@ -66,32 +66,12 @@ 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();
// 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;
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();
}
public inline function toAxisAngle(axis: Vec4): FastFloat {
@ -399,33 +379,17 @@ class Quat {
@return This quaternion.
**/
public inline function fromEulerOrdered(e: Vec4, order: String): Quat {
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 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 qx = new Quat(s1, 0, 0, c1);
var qy = new Quat(0, s2, 0, c2);
var qz = new Quat(0, 0, s3, c3);
// Original multiplication sequence (implements reverse of 'order')
if (order.charAt(2) == 'X')
this.setFrom(qx);
else if (order.charAt(2) == 'Y')
@ -445,12 +409,6 @@ class Quat {
else
this.mult(qz);
// TO DO quick fix somethings wrong..
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
this.w = -this.w;
return this;
}

View File

@ -132,15 +132,11 @@ class Transform {
function composeDelta() {
// Delta transform
var dl = new Vec4().addvecs(loc, dloc);
var ds = new Vec4().setFrom(scale);
ds.x *= dscale.x;
ds.y *= dscale.y;
ds.z *= dscale.z;
var dr = new Quat().fromEuler(_deulerX, _deulerY, _deulerZ);
dr.multquats(dr, rot);
dr.multquats(drot, dr);
local.compose(dl, dr, ds);
dloc.addvecs(loc, dloc);
dscale.addvecs(dscale, scale);
drot.fromEuler(_deulerX, _deulerY, _deulerZ);
drot.multquats(rot, drot);
local.compose(dloc, drot, dscale);
}
/**