@thi.ng/matrices 2.2.11 → 2.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/add.js +10 -13
- package/addn.js +10 -13
- package/alignment-quat.js +10 -16
- package/api.js +0 -1
- package/column.js +21 -13
- package/compile/emit.js +20 -3
- package/concat.js +4 -11
- package/conjugate.js +4 -1
- package/constants.js +35 -13
- package/determinant.js +51 -27
- package/diag.js +12 -11
- package/div.js +10 -13
- package/divn.js +10 -13
- package/fit.js +16 -24
- package/frustum.js +38 -28
- package/identity.js +12 -8
- package/invert.js +100 -45
- package/lookat.js +26 -15
- package/m22-m23.js +4 -8
- package/m23-m22.js +4 -8
- package/m23-m44.js +26 -16
- package/m33-m44.js +26 -16
- package/m44-m33.js +4 -11
- package/matn.js +10 -4
- package/matv.js +10 -36
- package/mixq.js +18 -28
- package/mul.js +10 -15
- package/mulm.js +67 -45
- package/muln.js +10 -13
- package/mulq.js +13 -12
- package/mulv.js +58 -77
- package/mulvm.js +16 -46
- package/normal-mat.js +10 -23
- package/orthagonal.js +17 -25
- package/ortho.js +26 -17
- package/outer-product.js +48 -10
- package/package.json +10 -8
- package/perspective.js +6 -13
- package/project.js +20 -51
- package/quat-axis-angle.js +13 -23
- package/quat-euler.js +16 -18
- package/quat-m33.js +29 -21
- package/quat-m44.js +36 -22
- package/rotation-around-axis.js +27 -32
- package/rotation.js +41 -79
- package/row.js +12 -13
- package/scale-center.js +16 -16
- package/scale.js +32 -42
- package/set.js +13 -6
- package/shear.js +35 -18
- package/skew.js +52 -17
- package/sub.js +10 -13
- package/subn.js +10 -13
- package/trace.js +4 -6
- package/transform.js +19 -23
- package/translation.js +6 -14
- package/transpose.js +26 -24
- package/viewport.js +9 -16
package/mulv.js
CHANGED
|
@@ -1,82 +1,63 @@
|
|
|
1
1
|
import { dotS2, dotS3, dotS4 } from "@thi.ng/vectors/dots";
|
|
2
2
|
import { setC2, setC3, setC4 } from "@thi.ng/vectors/setc";
|
|
3
3
|
import { vop } from "@thi.ng/vectors/vop";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Multiplies 4x4 matrix `m` with 4D vector `v`. Supports in-place
|
|
42
|
-
* modification, i.e. if `out === v`.
|
|
43
|
-
*
|
|
44
|
-
* @param out -
|
|
45
|
-
* @param m -
|
|
46
|
-
* @param v -
|
|
47
|
-
*/
|
|
48
|
-
export const mulV44 = mulV.add(16, (out, m, v) => setC4(out || v, dotS4(m, v, 0, 0, 4), dotS4(m, v, 1, 0, 4), dotS4(m, v, 2, 0, 4), dotS4(m, v, 3, 0, 4)));
|
|
49
|
-
/**
|
|
50
|
-
* Multiplies 4x4 matrix `m` with 3D vector `v` and assumes initial
|
|
51
|
-
* `w=1`, i.e. the vector is interpreted as `[x,y,z,1]`. After
|
|
52
|
-
* transformation applies perspective divide of the resulting XYZ
|
|
53
|
-
* components. Returns `undefined` if the computed perspective divisor
|
|
54
|
-
* is zero (and would cause `NaN` results).
|
|
55
|
-
*
|
|
56
|
-
* @param out -
|
|
57
|
-
* @param m -
|
|
58
|
-
* @param v -
|
|
59
|
-
*/
|
|
60
|
-
export const mulV344 = (out, m, v) => {
|
|
61
|
-
const w = dotS3(m, v, 3, 0, 4) + m[15];
|
|
62
|
-
return w !== 0
|
|
63
|
-
? setC3(out || v, (dotS3(m, v, 0, 0, 4) + m[12]) / w, (dotS3(m, v, 1, 0, 4) + m[13]) / w, (dotS3(m, v, 2, 0, 4) + m[14]) / w)
|
|
64
|
-
: undefined;
|
|
4
|
+
const mulV = vop(1);
|
|
5
|
+
const mulV22 = mulV.add(
|
|
6
|
+
4,
|
|
7
|
+
(out, m, v) => setC2(out || v, dotS2(m, v, 0, 0, 2), dotS2(m, v, 1, 0, 2))
|
|
8
|
+
);
|
|
9
|
+
const mulV23 = mulV.add(
|
|
10
|
+
6,
|
|
11
|
+
(out, m, v) => setC2(out || v, dotS2(m, v, 0, 0, 2) + m[4], dotS2(m, v, 1, 0, 2) + m[5])
|
|
12
|
+
);
|
|
13
|
+
const mulV33 = mulV.add(
|
|
14
|
+
9,
|
|
15
|
+
(out, m, v) => setC3(
|
|
16
|
+
out || v,
|
|
17
|
+
dotS3(m, v, 0, 0, 3),
|
|
18
|
+
dotS3(m, v, 1, 0, 3),
|
|
19
|
+
dotS3(m, v, 2, 0, 3)
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
const mulV44 = mulV.add(
|
|
23
|
+
16,
|
|
24
|
+
(out, m, v) => setC4(
|
|
25
|
+
out || v,
|
|
26
|
+
dotS4(m, v, 0, 0, 4),
|
|
27
|
+
dotS4(m, v, 1, 0, 4),
|
|
28
|
+
dotS4(m, v, 2, 0, 4),
|
|
29
|
+
dotS4(m, v, 3, 0, 4)
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
const mulV344 = (out, m, v) => {
|
|
33
|
+
const w = dotS3(m, v, 3, 0, 4) + m[15];
|
|
34
|
+
return w !== 0 ? setC3(
|
|
35
|
+
out || v,
|
|
36
|
+
(dotS3(m, v, 0, 0, 4) + m[12]) / w,
|
|
37
|
+
(dotS3(m, v, 1, 0, 4) + m[13]) / w,
|
|
38
|
+
(dotS3(m, v, 2, 0, 4) + m[14]) / w
|
|
39
|
+
) : void 0;
|
|
65
40
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
41
|
+
const mulVQ = (out, q, v) => {
|
|
42
|
+
const { 0: px, 1: py, 2: pz } = v;
|
|
43
|
+
const { 0: qx, 1: qy, 2: qz, 3: qw } = q;
|
|
44
|
+
const ix = qw * px + qy * pz - qz * py;
|
|
45
|
+
const iy = qw * py + qz * px - qx * pz;
|
|
46
|
+
const iz = qw * pz + qx * py - qy * px;
|
|
47
|
+
const iw = -qx * px - qy * py - qz * pz;
|
|
48
|
+
return setC3(
|
|
49
|
+
out || v,
|
|
50
|
+
ix * qw + iw * -qx + iy * -qz - iz * -qy,
|
|
51
|
+
iy * qw + iw * -qy + iz * -qx - ix * -qz,
|
|
52
|
+
iz * qw + iw * -qz + ix * -qy - iy * -qx
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
mulV,
|
|
57
|
+
mulV22,
|
|
58
|
+
mulV23,
|
|
59
|
+
mulV33,
|
|
60
|
+
mulV344,
|
|
61
|
+
mulV44,
|
|
62
|
+
mulVQ
|
|
82
63
|
};
|
package/mulvm.js
CHANGED
|
@@ -1,49 +1,19 @@
|
|
|
1
1
|
import { dot2, dot3, dot4 } from "@thi.ng/vectors/dot";
|
|
2
2
|
import { dotS2, dotS3, dotS4 } from "@thi.ng/vectors/dots";
|
|
3
3
|
import { setC2, setC3, setC4 } from "@thi.ng/vectors/setc";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* Same as:
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* out[0] = dot(v, column(m, 0))
|
|
25
|
-
* out[1] = dot(v, column(m, 1))
|
|
26
|
-
* out[2] = dot(v, column(m, 2))
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param out -
|
|
30
|
-
* @param v -
|
|
31
|
-
* @param m -
|
|
32
|
-
*/
|
|
33
|
-
export const mulVM33 = (out, v, m) => setC3(out, dot3(v, m), dotS3(v, m, 0, 3), dotS3(v, m, 0, 6));
|
|
34
|
-
/**
|
|
35
|
-
* Same as:
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* out[0] = dot(v, column(m, 0))
|
|
40
|
-
* out[1] = dot(v, column(m, 1))
|
|
41
|
-
* out[2] = dot(v, column(m, 2))
|
|
42
|
-
* out[3] = dot(v, column(m, 3))
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* @param out -
|
|
46
|
-
* @param v -
|
|
47
|
-
* @param m -
|
|
48
|
-
*/
|
|
49
|
-
export const mulVM44 = (out, v, m) => setC4(out, dot4(v, m), dotS4(v, m, 0, 4), dotS4(v, m, 0, 8), dotS4(v, m, 0, 12));
|
|
4
|
+
const mulVM22 = (out, v, m) => setC2(out, dot2(v, m), dotS2(v, m, 0, 2));
|
|
5
|
+
const mulVM23 = mulVM22;
|
|
6
|
+
const mulVM33 = (out, v, m) => setC3(out, dot3(v, m), dotS3(v, m, 0, 3), dotS3(v, m, 0, 6));
|
|
7
|
+
const mulVM44 = (out, v, m) => setC4(
|
|
8
|
+
out,
|
|
9
|
+
dot4(v, m),
|
|
10
|
+
dotS4(v, m, 0, 4),
|
|
11
|
+
dotS4(v, m, 0, 8),
|
|
12
|
+
dotS4(v, m, 0, 12)
|
|
13
|
+
);
|
|
14
|
+
export {
|
|
15
|
+
mulVM22,
|
|
16
|
+
mulVM23,
|
|
17
|
+
mulVM33,
|
|
18
|
+
mulVM44
|
|
19
|
+
};
|
package/normal-mat.js
CHANGED
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
import { invert33, invert44 } from "./invert.js";
|
|
2
2
|
import { mat44to33 } from "./m44-m33.js";
|
|
3
3
|
import { transpose33, transpose44 } from "./transpose.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* matrix will be created. Returns `undefined` if matrix inversion
|
|
8
|
-
* failed.
|
|
9
|
-
*
|
|
10
|
-
* @param out -
|
|
11
|
-
* @param m -
|
|
12
|
-
*/
|
|
13
|
-
export const normal33 = (out, m) => {
|
|
14
|
-
out = invert33(null, mat44to33(out, m));
|
|
15
|
-
return out ? transpose33(null, out) : undefined;
|
|
4
|
+
const normal33 = (out, m) => {
|
|
5
|
+
out = invert33(null, mat44to33(out, m));
|
|
6
|
+
return out ? transpose33(null, out) : void 0;
|
|
16
7
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
export const normal44 = (out, m) => {
|
|
26
|
-
out = invert44(out, m);
|
|
27
|
-
return out ? transpose44(null, out) : undefined;
|
|
8
|
+
const normal44 = (out, m) => {
|
|
9
|
+
out = invert44(out, m);
|
|
10
|
+
return out ? transpose44(null, out) : void 0;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
normal33,
|
|
14
|
+
normal44
|
|
28
15
|
};
|
package/orthagonal.js
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import { EPS } from "@thi.ng/math/api";
|
|
2
2
|
import { eqDelta } from "@thi.ng/math/eqdelta";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const ii = i * n;
|
|
16
|
-
for (let j = 0; j < n; j++) {
|
|
17
|
-
const jj = j * n;
|
|
18
|
-
let acc = 0;
|
|
19
|
-
for (let k = 0; k < n; k++) {
|
|
20
|
-
acc += m[ii + k] * m[jj + k];
|
|
21
|
-
}
|
|
22
|
-
if ((i == j && !eqDelta(acc, 1, eps)) ||
|
|
23
|
-
(i != j && !eqDelta(acc, 0, eps))) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
3
|
+
const isOrthagonal = (m, n, eps = EPS) => {
|
|
4
|
+
for (let i = 0; i < n; i++) {
|
|
5
|
+
const ii = i * n;
|
|
6
|
+
for (let j = 0; j < n; j++) {
|
|
7
|
+
const jj = j * n;
|
|
8
|
+
let acc = 0;
|
|
9
|
+
for (let k = 0; k < n; k++) {
|
|
10
|
+
acc += m[ii + k] * m[jj + k];
|
|
11
|
+
}
|
|
12
|
+
if (i == j && !eqDelta(acc, 1, eps) || i != j && !eqDelta(acc, 0, eps)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
27
15
|
}
|
|
28
|
-
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
isOrthagonal
|
|
29
21
|
};
|
package/ortho.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { setC } from "@thi.ng/vectors/setc";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
const ortho = (out, left, right, bottom, top, near, far) => {
|
|
3
|
+
const dx = 1 / (right - left);
|
|
4
|
+
const dy = 1 / (top - bottom);
|
|
5
|
+
const dz = 1 / (far - near);
|
|
6
|
+
return setC(
|
|
7
|
+
out || [],
|
|
8
|
+
2 * dx,
|
|
9
|
+
0,
|
|
10
|
+
0,
|
|
11
|
+
0,
|
|
12
|
+
0,
|
|
13
|
+
2 * dy,
|
|
14
|
+
0,
|
|
15
|
+
0,
|
|
16
|
+
0,
|
|
17
|
+
0,
|
|
18
|
+
-2 * dz,
|
|
19
|
+
0,
|
|
20
|
+
-(left + right) * dx,
|
|
21
|
+
-(top + bottom) * dy,
|
|
22
|
+
-(far + near) * dz,
|
|
23
|
+
1
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
ortho
|
|
19
28
|
};
|
package/outer-product.js
CHANGED
|
@@ -1,12 +1,50 @@
|
|
|
1
1
|
import { setC, setC4 } from "@thi.ng/vectors/setc";
|
|
2
2
|
import { vop } from "@thi.ng/vectors/vop";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
const outerProduct = vop(1);
|
|
4
|
+
const outerProduct2 = outerProduct.add(
|
|
5
|
+
2,
|
|
6
|
+
(out, [ux, uy], [vx, vy]) => setC4(out || [], ux * vx, uy * vx, ux * vy, uy * vy)
|
|
7
|
+
);
|
|
8
|
+
const outerProduct3 = outerProduct.add(
|
|
9
|
+
3,
|
|
10
|
+
(out, [ux, uy, uz], [vx, vy, vz]) => setC(
|
|
11
|
+
out || [],
|
|
12
|
+
ux * vx,
|
|
13
|
+
uy * vx,
|
|
14
|
+
uz * vx,
|
|
15
|
+
ux * vy,
|
|
16
|
+
uy * vy,
|
|
17
|
+
uz * vy,
|
|
18
|
+
ux * vz,
|
|
19
|
+
uy * vz,
|
|
20
|
+
uz * vz
|
|
21
|
+
)
|
|
22
|
+
);
|
|
23
|
+
const outerProduct4 = outerProduct.add(
|
|
24
|
+
4,
|
|
25
|
+
(out, [ux, uy, uz, uw], [vx, vy, vz, vw]) => setC(
|
|
26
|
+
out || [],
|
|
27
|
+
ux * vx,
|
|
28
|
+
uy * vx,
|
|
29
|
+
uz * vx,
|
|
30
|
+
uw * vx,
|
|
31
|
+
ux * vy,
|
|
32
|
+
uy * vy,
|
|
33
|
+
uz * vy,
|
|
34
|
+
uw * vy,
|
|
35
|
+
ux * vz,
|
|
36
|
+
uy * vz,
|
|
37
|
+
uz * vz,
|
|
38
|
+
uw * vz,
|
|
39
|
+
ux * vw,
|
|
40
|
+
uy * vw,
|
|
41
|
+
uz * vw,
|
|
42
|
+
uw * vw
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
export {
|
|
46
|
+
outerProduct,
|
|
47
|
+
outerProduct2,
|
|
48
|
+
outerProduct3,
|
|
49
|
+
outerProduct4
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/matrices",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.13",
|
|
4
4
|
"description": "Matrix & quaternion operations for 2D/3D geometry processing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc compile",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,14 +35,14 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/math": "^5.7.
|
|
39
|
-
"@thi.ng/vectors": "^7.8.
|
|
38
|
+
"@thi.ng/api": "^8.9.12",
|
|
39
|
+
"@thi.ng/checks": "^3.4.12",
|
|
40
|
+
"@thi.ng/math": "^5.7.7",
|
|
41
|
+
"@thi.ng/vectors": "^7.8.9"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@microsoft/api-extractor": "^7.38.3",
|
|
43
|
-
"
|
|
45
|
+
"esbuild": "^0.19.8",
|
|
44
46
|
"rimraf": "^5.0.5",
|
|
45
47
|
"tools": "^0.0.1",
|
|
46
48
|
"typedoc": "^0.25.4",
|
|
@@ -271,5 +273,5 @@
|
|
|
271
273
|
],
|
|
272
274
|
"year": 2018
|
|
273
275
|
},
|
|
274
|
-
"gitHead": "
|
|
276
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
275
277
|
}
|
package/perspective.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { frustum, frustumBounds } from "./frustum.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @param aspect -
|
|
9
|
-
* @param near -
|
|
10
|
-
* @param far -
|
|
11
|
-
*/
|
|
12
|
-
export const perspective = (out, fov, aspect, near, far) => {
|
|
13
|
-
const f = frustumBounds(fov, aspect, near, far);
|
|
14
|
-
return frustum(out, f.left, f.right, f.bottom, f.top, f.near, f.far);
|
|
2
|
+
const perspective = (out, fov, aspect, near, far) => {
|
|
3
|
+
const f = frustumBounds(fov, aspect, near, far);
|
|
4
|
+
return frustum(out, f.left, f.right, f.bottom, f.top, f.near, f.far);
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
perspective
|
|
15
8
|
};
|
package/project.js
CHANGED
|
@@ -1,56 +1,25 @@
|
|
|
1
1
|
import { fromHomogeneous4 } from "@thi.ng/vectors/homogeneous";
|
|
2
2
|
import { invert23, invert44 } from "./invert.js";
|
|
3
3
|
import { mulV23, mulV344, mulV44 } from "./mulv.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* @param out -
|
|
11
|
-
* @param mvp - 4x4 matrix
|
|
12
|
-
* @param view - 2x3 matrix
|
|
13
|
-
* @param p -
|
|
14
|
-
*/
|
|
15
|
-
export const project = (out, mvp, view, p) => (!out && (out = []),
|
|
16
|
-
mulV23(out, view, fromHomogeneous4(out, mulV44([], mvp, p))));
|
|
17
|
-
/**
|
|
18
|
-
* Same as {@link project}, but slightly faster and more convenient for
|
|
19
|
-
* the most common use case of projecting a 3D input point (assumes
|
|
20
|
-
* `w=1` for its homogeneous coordinate, i.e. `[x,y,z,1]`). Returns
|
|
21
|
-
* `undefined` if the computed perspective divisor is zero (and would
|
|
22
|
-
* cause in `NaN` results).
|
|
23
|
-
*
|
|
24
|
-
* @param out -
|
|
25
|
-
* @param mvp - 4x4 matrix
|
|
26
|
-
* @param view - 2x3 matrix
|
|
27
|
-
* @param p -
|
|
28
|
-
*/
|
|
29
|
-
export const project3 = (out, mvp, view, p) => {
|
|
30
|
-
!out && (out = []);
|
|
31
|
-
const q = mulV344(out, mvp, p);
|
|
32
|
-
return q ? mulV23(q, view, q) : undefined;
|
|
4
|
+
const project = (out, mvp, view, p) => (!out && (out = []), mulV23(out, view, fromHomogeneous4(out, mulV44([], mvp, p))));
|
|
5
|
+
const project3 = (out, mvp, view, p) => {
|
|
6
|
+
!out && (out = []);
|
|
7
|
+
const q = mulV344(out, mvp, p);
|
|
8
|
+
return q ? mulV23(q, view, q) : void 0;
|
|
33
9
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const _view = invert23([], view);
|
|
50
|
-
if (!_mvp || !_view)
|
|
51
|
-
return;
|
|
52
|
-
mvp = _mvp;
|
|
53
|
-
view = _view;
|
|
54
|
-
}
|
|
55
|
-
return mulV344(out, mvp, mulV23([0, 0, p[2] * 2 - 1], view, p));
|
|
10
|
+
const unproject = (out, mvp, view, p, doInvert = false) => {
|
|
11
|
+
if (doInvert) {
|
|
12
|
+
const _mvp = invert44([], mvp);
|
|
13
|
+
const _view = invert23([], view);
|
|
14
|
+
if (!_mvp || !_view)
|
|
15
|
+
return;
|
|
16
|
+
mvp = _mvp;
|
|
17
|
+
view = _view;
|
|
18
|
+
}
|
|
19
|
+
return mulV344(out, mvp, mulV23([0, 0, p[2] * 2 - 1], view, p));
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
project,
|
|
23
|
+
project3,
|
|
24
|
+
unproject
|
|
56
25
|
};
|
package/quat-axis-angle.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import { EPS } from "@thi.ng/math/api";
|
|
2
2
|
import { normalize3, normalize4 } from "@thi.ng/vectors/normalize";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @param axis -
|
|
8
|
-
* @param theta -
|
|
9
|
-
*/
|
|
10
|
-
export const quatFromAxisAngle = (axis, theta) => {
|
|
11
|
-
theta *= 0.5;
|
|
12
|
-
return normalize3([0, 0, 0, Math.cos(theta)], axis, Math.sin(theta));
|
|
3
|
+
const quatFromAxisAngle = (axis, theta) => {
|
|
4
|
+
theta *= 0.5;
|
|
5
|
+
return normalize3([0, 0, 0, Math.cos(theta)], axis, Math.sin(theta));
|
|
13
6
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return m > EPS
|
|
25
|
-
? [[n[0] / m, n[1] / m, n[2] / m], theta]
|
|
26
|
-
: [[n[0], n[1], n[2]], theta];
|
|
7
|
+
const quatToAxisAngle = (quat) => {
|
|
8
|
+
const n = normalize4([], quat);
|
|
9
|
+
const w = n[3];
|
|
10
|
+
const m = Math.sqrt(1 - w * w);
|
|
11
|
+
const theta = 2 * Math.acos(w);
|
|
12
|
+
return m > EPS ? [[n[0] / m, n[1] / m, n[2] / m], theta] : [[n[0], n[1], n[2]], theta];
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
quatFromAxisAngle,
|
|
16
|
+
quatToAxisAngle
|
|
27
17
|
};
|
package/quat-euler.js
CHANGED
|
@@ -2,23 +2,21 @@ import { X3, Y3, Z3 } from "@thi.ng/vectors/api";
|
|
|
2
2
|
import { mulQ } from "./mulq.js";
|
|
3
3
|
import { quatFromAxisAngle } from "./quat-axis-angle.js";
|
|
4
4
|
const axisOrder = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
xyz: [X3, Y3, Z3],
|
|
6
|
+
yxz: [Y3, X3, Z3],
|
|
7
|
+
xzy: [X3, Z3, Y3],
|
|
8
|
+
zxy: [Z3, X3, Y3],
|
|
9
|
+
yzx: [Y3, Z3, X3],
|
|
10
|
+
zyx: [Z3, Y3, X3]
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const [aa, ab, ac] = axisOrder[order];
|
|
23
|
-
return mulQ(null, mulQ([], quatFromAxisAngle(aa, a), quatFromAxisAngle(ab, b)), quatFromAxisAngle(ac, c));
|
|
12
|
+
const quatFromEuler = (order, a, b, c) => {
|
|
13
|
+
const [aa, ab, ac] = axisOrder[order];
|
|
14
|
+
return mulQ(
|
|
15
|
+
null,
|
|
16
|
+
mulQ([], quatFromAxisAngle(aa, a), quatFromAxisAngle(ab, b)),
|
|
17
|
+
quatFromAxisAngle(ac, c)
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
quatFromEuler
|
|
24
22
|
};
|