feat: Quaternion#fromEulerXYZ
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user