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", "name": "computercraft-mutil",
"version": "1.0.10", "version": "1.0.11",
"description": "", "description": "",
"license": "ISC", "license": "ISC",
"author": "", "author": "",

View File

@@ -10,7 +10,7 @@ export class Quaternion {
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;