UNPKG

ogl

Version:
74 lines (60 loc) 1.36 kB
import * as EulerFunc from './functions/EulerFunc.js'; import { Mat4 } from './Mat4.js'; const tmpMat4 = new Mat4(); export class Euler extends Array { constructor(x = 0, y = x, z = x, order = 'YXZ') { super(x, y, z); this.order = order; this.onChange = () => {}; return this; } get x() { return this[0]; } get y() { return this[1]; } get z() { return this[2]; } set x(v) { this[0] = v; this.onChange(); } set y(v) { this[1] = v; this.onChange(); } set z(v) { this[2] = v; this.onChange(); } set(x, y = x, z = x) { if (x.length) return this.copy(x); this[0] = x; this[1] = y; this[2] = z; this.onChange(); return this; } copy(v) { this[0] = v[0]; this[1] = v[1]; this[2] = v[2]; this.onChange(); return this; } reorder(order) { this.order = order; this.onChange(); return this; } fromRotationMatrix(m, order = this.order) { EulerFunc.fromRotationMatrix(this, m, order); return this; } fromQuaternion(q, order = this.order) { tmpMat4.fromQuaternion(q); return this.fromRotationMatrix(tmpMat4, order); } }