feat: Quaternion#fromEulerXYZ
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "computercraft-mutil",
|
"name": "computercraft-mutil",
|
||||||
"version": "1.0.10",
|
"version": "1.0.11",
|
||||||
"description": "",
|
"description": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ export class Quaternion {
|
|||||||
public y: number,
|
public y: number,
|
||||||
public z: number,
|
public z: number,
|
||||||
public w: number,
|
public w: number,
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
static fromXYZ({
|
public static fromXYZ({
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
z,
|
z,
|
||||||
@@ -24,6 +24,27 @@ export class Quaternion {
|
|||||||
return new Quaternion(x, y, z, w);
|
return new Quaternion(x, y, z, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static fromEulerXYZ(
|
||||||
|
roll: number,
|
||||||
|
pitch: number,
|
||||||
|
yaw: number,
|
||||||
|
): Quaternion {
|
||||||
|
const cx = math.cos(roll * 0.5);
|
||||||
|
const sx = math.sin(roll * 0.5);
|
||||||
|
const cy = math.cos(pitch * 0.5);
|
||||||
|
const sy = math.sin(pitch * 0.5);
|
||||||
|
const cz = math.cos(yaw * 0.5);
|
||||||
|
const sz = math.sin(yaw * 0.5);
|
||||||
|
|
||||||
|
// Quaternion multiplication order: q = qx * qy * qz (X → Y → Z)
|
||||||
|
const w = cx * cy * cz + sx * sy * sz;
|
||||||
|
const x = sx * cy * cz - cx * sy * sz;
|
||||||
|
const y = cx * sy * cz + sx * cy * sz;
|
||||||
|
const z = cx * cy * sz - sx * sy * cz;
|
||||||
|
|
||||||
|
return new Quaternion(x, y, z, w);
|
||||||
|
}
|
||||||
|
|
||||||
public toEuler(): Vec3 {
|
public toEuler(): Vec3 {
|
||||||
const { x, y, z, w } = this;
|
const { x, y, z, w } = this;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user