-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |