Merge pull request 'Transforms and rotations math' (#41) from Onek8/LNXSDK:main into main
Reviewed-on: #41
This commit is contained in:
commit
c798f122d0
@ -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 {
|
||||
@ -409,6 +429,12 @@ class Quat {
|
||||
else
|
||||
this.mult(qz);
|
||||
|
||||
// TO DO quick fix doesnt make sense.
|
||||
this.x = -this.x;
|
||||
this.y = -this.y;
|
||||
this.z = -this.z;
|
||||
this.w = -this.w;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ class TransformNode extends LogicNode {
|
||||
override function get(from: Int): Dynamic {
|
||||
var loc: Vec4 = inputs[0].get();
|
||||
var rot: Quat = new Quat().setFrom(inputs[1].get());
|
||||
rot.normalize();
|
||||
//rot.normalize();
|
||||
var scale: Vec4 = inputs[2].get();
|
||||
if (loc == null && rot == null && scale == null) return this.value;
|
||||
if (loc == null || rot == null || scale == null) return null;
|
||||
|
@ -201,19 +201,10 @@ class LnxRotationSocket(LnxCustomSocket):
|
||||
x *= pi/180
|
||||
y *= pi/180
|
||||
z *= pi/180
|
||||
cx, sx = cos(x/2), sin(x/2)
|
||||
cy, sy = cos(y/2), sin(y/2)
|
||||
cz, sz = cos(z/2), sin(z/2)
|
||||
|
||||
qw, qx, qy, qz = 1.0,0.0,0.0,0.0
|
||||
for direction in param3[::-1]:
|
||||
qwi, qxi,qyi,qzi = {'X': (cx,sx,0,0), 'Y': (cy,0,sy,0), 'Z': (cz,0,0,sz)}[direction]
|
||||
|
||||
qw = qw*qwi -qx*qxi -qy*qyi -qz*qzi
|
||||
qx = qx*qwi +qw*qxi +qy*qzi -qz*qyi
|
||||
qy = qy*qwi +qw*qyi +qz*qxi -qx*qzi
|
||||
qz = qz*qwi +qw*qzi +qx*qyi -qy*qxi
|
||||
return mathutils.Vector((qx,qy,qz,qw))
|
||||
euler = mathutils.Euler((x, y, z), param3)
|
||||
quat = euler.to_quaternion()
|
||||
return mathutils.Vector((quat.x, quat.y, quat.z, quat.w))
|
||||
|
||||
|
||||
def do_update_raw(self, context):
|
||||
|
Loading…
x
Reference in New Issue
Block a user