Skip to content

Commit 34dc1e9

Browse files
committed
feat(util): more features
1 parent 5ac3d93 commit 34dc1e9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/util.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
12
export function isArray(arr) {
23
return Array.isArray(arr) || ArrayBuffer.isView(arr);
34
}
5+
6+
export function multQuatVec(quat, vec) {
7+
const {
8+
x, y, z
9+
} = vec;
10+
const {
11+
x: qx, y: qy, z: qz, w: qw
12+
} = quat;
13+
14+
const ix = qw * x + qy * z - qz * y;
15+
const iy = qw * y + qz * x - qx * z;
16+
const iz = qw * z + qx * y - qy * x;
17+
const iw = -qx * x - qy * y - qz * z;
18+
const rx = ix * qw + iw * -qx + iy * -qz - iz * -qy;
19+
const ry = iy * qw + iw * -qy + iz * -qx - ix * -qz;
20+
const rz = iz * qw + iw * -qz + ix * -qy - iy * -qx;
21+
return new vec.constructor(rx, ry, rz);
22+
}
23+
24+
const angle180 = Math.PI;
25+
const angle360 = Math.PI * 2;
26+
27+
export function normRad(angle) {
28+
let mod = angle % angle360;
29+
if (mod < -angle180) {
30+
mod += angle360;
31+
} else if (mod > angle180) {
32+
mod -= angle360;
33+
}
34+
return mod;
35+
}

0 commit comments

Comments
 (0)