feat: Quaternion#fromEulerXYZ

This commit is contained in:
2025-06-12 16:18:53 +09:00
parent 7f4cb6daec
commit f566459afb
2 changed files with 24 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "computercraft-mutil",
"version": "1.0.10",
"version": "1.0.11",
"description": "",
"license": "ISC",
"author": "",

View File

@@ -8,9 +8,9 @@ export class Quaternion {
public y: number,
public z: number,
public w: number,
) { }
) {}
static fromXYZ({
public static fromXYZ({
x,
y,
z,
@@ -24,6 +24,27 @@ export class Quaternion {
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 {
const { x, y, z, w } = this;