Skip to content

Commit

Permalink
feat(util): more features
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Sep 26, 2019
1 parent 5ac3d93 commit 34dc1e9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@

export function isArray(arr) {
return Array.isArray(arr) || ArrayBuffer.isView(arr);
}

export function multQuatVec(quat, vec) {
const {
x, y, z
} = vec;
const {
x: qx, y: qy, z: qz, w: qw
} = quat;

const ix = qw * x + qy * z - qz * y;
const iy = qw * y + qz * x - qx * z;
const iz = qw * z + qx * y - qy * x;
const iw = -qx * x - qy * y - qz * z;
const rx = ix * qw + iw * -qx + iy * -qz - iz * -qy;
const ry = iy * qw + iw * -qy + iz * -qx - ix * -qz;
const rz = iz * qw + iw * -qz + ix * -qy - iy * -qx;
return new vec.constructor(rx, ry, rz);
}

const angle180 = Math.PI;
const angle360 = Math.PI * 2;

export function normRad(angle) {
let mod = angle % angle360;
if (mod < -angle180) {
mod += angle360;
} else if (mod > angle180) {
mod -= angle360;
}
return mod;
}

0 comments on commit 34dc1e9

Please sign in to comment.