@flighthq/geometry 0.1.0
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/dist/aabb.d.ts +88 -0
- package/dist/aabb.d.ts.map +1 -0
- package/dist/aabb.js +230 -0
- package/dist/aabb.js.map +1 -0
- package/dist/boundingSphere.d.ts +62 -0
- package/dist/boundingSphere.d.ts.map +1 -0
- package/dist/boundingSphere.js +188 -0
- package/dist/boundingSphere.js.map +1 -0
- package/dist/capsule.d.ts +38 -0
- package/dist/capsule.d.ts.map +1 -0
- package/dist/capsule.js +215 -0
- package/dist/capsule.js.map +1 -0
- package/dist/frustum.d.ts +49 -0
- package/dist/frustum.d.ts.map +1 -0
- package/dist/frustum.js +149 -0
- package/dist/frustum.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/matrix.d.ts +152 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +488 -0
- package/dist/matrix.js.map +1 -0
- package/dist/matrix3.d.ts +63 -0
- package/dist/matrix3.d.ts.map +1 -0
- package/dist/matrix3.js +408 -0
- package/dist/matrix3.js.map +1 -0
- package/dist/matrix3Pool.d.ts +6 -0
- package/dist/matrix3Pool.d.ts.map +1 -0
- package/dist/matrix3Pool.js +26 -0
- package/dist/matrix3Pool.js.map +1 -0
- package/dist/matrix4.d.ts +238 -0
- package/dist/matrix4.d.ts.map +1 -0
- package/dist/matrix4.js +931 -0
- package/dist/matrix4.js.map +1 -0
- package/dist/matrix4Pool.d.ts +6 -0
- package/dist/matrix4Pool.d.ts.map +1 -0
- package/dist/matrix4Pool.js +26 -0
- package/dist/matrix4Pool.js.map +1 -0
- package/dist/matrixPool.d.ts +6 -0
- package/dist/matrixPool.d.ts.map +1 -0
- package/dist/matrixPool.js +26 -0
- package/dist/matrixPool.js.map +1 -0
- package/dist/obb.d.ts +44 -0
- package/dist/obb.d.ts.map +1 -0
- package/dist/obb.js +248 -0
- package/dist/obb.js.map +1 -0
- package/dist/plane.d.ts +66 -0
- package/dist/plane.d.ts.map +1 -0
- package/dist/plane.js +140 -0
- package/dist/plane.js.map +1 -0
- package/dist/quaternion.d.ts +128 -0
- package/dist/quaternion.d.ts.map +1 -0
- package/dist/quaternion.js +508 -0
- package/dist/quaternion.js.map +1 -0
- package/dist/quaternionPool.d.ts +6 -0
- package/dist/quaternionPool.d.ts.map +1 -0
- package/dist/quaternionPool.js +29 -0
- package/dist/quaternionPool.js.map +1 -0
- package/dist/ray3d.d.ts +69 -0
- package/dist/ray3d.d.ts.map +1 -0
- package/dist/ray3d.js +264 -0
- package/dist/ray3d.js.map +1 -0
- package/dist/rectangle.d.ts +56 -0
- package/dist/rectangle.d.ts.map +1 -0
- package/dist/rectangle.js +235 -0
- package/dist/rectangle.js.map +1 -0
- package/dist/rectanglePool.d.ts +6 -0
- package/dist/rectanglePool.d.ts.map +1 -0
- package/dist/rectanglePool.js +29 -0
- package/dist/rectanglePool.js.map +1 -0
- package/dist/typedarray.d.ts +4 -0
- package/dist/typedarray.d.ts.map +1 -0
- package/dist/typedarray.js +25 -0
- package/dist/typedarray.js.map +1 -0
- package/dist/vector2.d.ts +130 -0
- package/dist/vector2.d.ts.map +1 -0
- package/dist/vector2.js +250 -0
- package/dist/vector2.js.map +1 -0
- package/dist/vector2Pool.d.ts +6 -0
- package/dist/vector2Pool.d.ts.map +1 -0
- package/dist/vector2Pool.js +20 -0
- package/dist/vector2Pool.js.map +1 -0
- package/dist/vector3.d.ts +220 -0
- package/dist/vector3.d.ts.map +1 -0
- package/dist/vector3.js +380 -0
- package/dist/vector3.js.map +1 -0
- package/dist/vector3Pool.d.ts +6 -0
- package/dist/vector3Pool.d.ts.map +1 -0
- package/dist/vector3Pool.js +28 -0
- package/dist/vector3Pool.js.map +1 -0
- package/dist/vector4.d.ts +180 -0
- package/dist/vector4.d.ts.map +1 -0
- package/dist/vector4.js +333 -0
- package/dist/vector4.js.map +1 -0
- package/dist/vector4Pool.d.ts +6 -0
- package/dist/vector4Pool.d.ts.map +1 -0
- package/dist/vector4Pool.js +29 -0
- package/dist/vector4Pool.js.map +1 -0
- package/package.json +38 -0
- package/src/aabb.test.ts +341 -0
- package/src/boundingSphere.test.ts +247 -0
- package/src/capsule.test.ts +157 -0
- package/src/frustum.test.ts +160 -0
- package/src/matrix.test.ts +1111 -0
- package/src/matrix3.test.ts +752 -0
- package/src/matrix3Pool.test.ts +73 -0
- package/src/matrix4.test.ts +1627 -0
- package/src/matrix4Pool.test.ts +71 -0
- package/src/matrixPool.test.ts +69 -0
- package/src/obb.test.ts +183 -0
- package/src/plane.test.ts +225 -0
- package/src/quaternion.test.ts +531 -0
- package/src/quaternionPool.test.ts +64 -0
- package/src/ray3d.test.ts +297 -0
- package/src/rectangle.test.ts +982 -0
- package/src/rectanglePool.test.ts +71 -0
- package/src/typedarray.test.ts +118 -0
- package/src/vector2.test.ts +958 -0
- package/src/vector2Pool.test.ts +65 -0
- package/src/vector3.test.ts +749 -0
- package/src/vector3Pool.test.ts +68 -0
- package/src/vector4.test.ts +660 -0
- package/src/vector4Pool.test.ts +71 -0
package/dist/plane.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity';
|
|
2
|
+
export function clonePlane(source) {
|
|
3
|
+
return createPlane(source.a, source.b, source.c, source.d);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Copies the coefficients of a plane (a, b, c, d).
|
|
7
|
+
*
|
|
8
|
+
* Safe when `out` aliases `source`.
|
|
9
|
+
*/
|
|
10
|
+
export function copyPlane(out, source) {
|
|
11
|
+
out.a = source.a;
|
|
12
|
+
out.b = source.b;
|
|
13
|
+
out.c = source.c;
|
|
14
|
+
out.d = source.d;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a plane in the form a·x + b·y + c·z + d = 0, where (a, b, c) is the plane normal
|
|
18
|
+
* and d is the signed distance from the origin along that normal. Defaults to all zeros (a
|
|
19
|
+
* degenerate plane), populated by the caller or by frustum extraction.
|
|
20
|
+
*/
|
|
21
|
+
export function createPlane(a, b, c, d) {
|
|
22
|
+
return createEntity({ a: a ?? 0, b: b ?? 0, c: c ?? 0, d: d ?? 0 });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Writes the point on a plane closest to `point` — `point` projected onto the plane along its
|
|
26
|
+
* normal. Requires the plane normal (a, b, c) to be unit length. This is the closest-point
|
|
27
|
+
* member of the collision-support suite; `projectVector3OntoPlane` performs the identical
|
|
28
|
+
* projection under the projection vocabulary.
|
|
29
|
+
*
|
|
30
|
+
* Safe when `out` aliases `point`.
|
|
31
|
+
*/
|
|
32
|
+
export function getClosestPointOnPlane(out, plane, point) {
|
|
33
|
+
const px = point.x, py = point.y, pz = point.z;
|
|
34
|
+
const dist = plane.a * px + plane.b * py + plane.c * pz + plane.d;
|
|
35
|
+
out.x = px - dist * plane.a;
|
|
36
|
+
out.y = py - dist * plane.b;
|
|
37
|
+
out.z = pz - dist * plane.c;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Writes the coplanar point on the plane closest to the origin.
|
|
41
|
+
* Requires the plane normal (a, b, c) to be unit length.
|
|
42
|
+
*/
|
|
43
|
+
export function getPlaneCoplanarPoint(out, plane) {
|
|
44
|
+
out.x = -plane.a * plane.d;
|
|
45
|
+
out.y = -plane.b * plane.d;
|
|
46
|
+
out.z = -plane.c * plane.d;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the signed distance from a point to a plane. Positive is the side the normal points
|
|
50
|
+
* toward; assumes the plane normal (a, b, c) is unit length.
|
|
51
|
+
*/
|
|
52
|
+
export function getPlaneSignedDistanceToPoint(plane, point) {
|
|
53
|
+
return plane.a * point.x + plane.b * point.y + plane.c * point.z + plane.d;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Normalizes a plane so its normal (a, b, c) has unit length. The `d` coefficient is scaled
|
|
57
|
+
* proportionally. A degenerate plane (zero-length normal) is written as-is.
|
|
58
|
+
*
|
|
59
|
+
* Safe when `out` aliases `source`.
|
|
60
|
+
*/
|
|
61
|
+
export function normalizePlane(out, source) {
|
|
62
|
+
const a = source.a, b = source.b, c = source.c, d = source.d;
|
|
63
|
+
const len = Math.sqrt(a * a + b * b + c * c);
|
|
64
|
+
if (len === 0) {
|
|
65
|
+
out.a = a;
|
|
66
|
+
out.b = b;
|
|
67
|
+
out.c = c;
|
|
68
|
+
out.d = d;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const inv = 1 / len;
|
|
72
|
+
out.a = a * inv;
|
|
73
|
+
out.b = b * inv;
|
|
74
|
+
out.c = c * inv;
|
|
75
|
+
out.d = d * inv;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Projects a point onto the plane, writing the closest point on the plane to `out`.
|
|
79
|
+
* Requires the plane normal (a, b, c) to be unit length.
|
|
80
|
+
*
|
|
81
|
+
* Safe when `out` aliases `point`.
|
|
82
|
+
*/
|
|
83
|
+
export function projectVector3OntoPlane(out, point, plane) {
|
|
84
|
+
const px = point.x, py = point.y, pz = point.z;
|
|
85
|
+
const dist = plane.a * px + plane.b * py + plane.c * pz + plane.d;
|
|
86
|
+
out.x = px - dist * plane.a;
|
|
87
|
+
out.y = py - dist * plane.b;
|
|
88
|
+
out.z = pz - dist * plane.c;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Sets the coefficients of a plane (a, b, c, d).
|
|
92
|
+
*/
|
|
93
|
+
export function setPlane(out, a, b, c, d) {
|
|
94
|
+
out.a = a;
|
|
95
|
+
out.b = b;
|
|
96
|
+
out.c = c;
|
|
97
|
+
out.d = d;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Builds a plane from a unit normal and a point that lies on the plane.
|
|
101
|
+
*/
|
|
102
|
+
export function setPlaneFromNormalAndPoint(out, normal, point) {
|
|
103
|
+
out.a = normal.x;
|
|
104
|
+
out.b = normal.y;
|
|
105
|
+
out.c = normal.z;
|
|
106
|
+
out.d = -(normal.x * point.x + normal.y * point.y + normal.z * point.z);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Builds a plane from three non-collinear points. The normal direction follows the
|
|
110
|
+
* right-hand rule: counter-clockwise winding when viewed from the positive-normal side.
|
|
111
|
+
*
|
|
112
|
+
* If the points are collinear (degenerate triangle), the plane normal will be zero; use
|
|
113
|
+
* `normalizePlane` to validate after construction if needed.
|
|
114
|
+
*
|
|
115
|
+
* Safe when `out` has no aliasing concerns.
|
|
116
|
+
*/
|
|
117
|
+
export function setPlaneFromPoints(out, a, b, c) {
|
|
118
|
+
// edge1 = b - a, edge2 = c - a
|
|
119
|
+
const e1x = b.x - a.x, e1y = b.y - a.y, e1z = b.z - a.z;
|
|
120
|
+
const e2x = c.x - a.x, e2y = c.y - a.y, e2z = c.z - a.z;
|
|
121
|
+
// normal = cross(e1, e2)
|
|
122
|
+
const nx = e1y * e2z - e1z * e2y;
|
|
123
|
+
const ny = e1z * e2x - e1x * e2z;
|
|
124
|
+
const nz = e1x * e2y - e1y * e2x;
|
|
125
|
+
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
126
|
+
if (len === 0) {
|
|
127
|
+
out.a = nx;
|
|
128
|
+
out.b = ny;
|
|
129
|
+
out.c = nz;
|
|
130
|
+
out.d = 0;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const inv = 1 / len;
|
|
134
|
+
out.a = nx * inv;
|
|
135
|
+
out.b = ny * inv;
|
|
136
|
+
out.c = nz * inv;
|
|
137
|
+
// d = -dot(normal, a)
|
|
138
|
+
out.d = -(out.a * a.x + out.b * a.y + out.c * a.z);
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=plane.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plane.js","sourceRoot":"","sources":["../src/plane.ts"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MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IACnD,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACd,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACV,OAAO;IACT,CAAC;IACD,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IACpB,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC;IACjB,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC;IACjB,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC;IACjB,sBAAsB;IACtB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { EulerOrder, Matrix4Like, Quaternion, QuaternionLike, Vector3Like } from '@flighthq/types';
|
|
2
|
+
export declare function cloneQuaternion(source: Readonly<QuaternionLike>): Quaternion;
|
|
3
|
+
/**
|
|
4
|
+
* Writes the conjugate of a quaternion, negating the vector part (x, y, z) and
|
|
5
|
+
* leaving the scalar part (w) unchanged. For a unit quaternion the conjugate is
|
|
6
|
+
* also its inverse.
|
|
7
|
+
*
|
|
8
|
+
* Safe when `out` aliases `source`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function conjugateQuaternion(out: QuaternionLike, source: Readonly<QuaternionLike>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Copies the x, y, z and w components of a quaternion.
|
|
13
|
+
*
|
|
14
|
+
* Safe when `out` aliases `source`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function copyQuaternion(out: QuaternionLike, source: Readonly<QuaternionLike>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a unit quaternion (x, y, z, w) representing a 3D rotation. Handedness is pinned
|
|
19
|
+
* across the 3D suite: right-handed coordinates, CCW front-face, glTF tangent w-sign.
|
|
20
|
+
*
|
|
21
|
+
* Defaults to the identity rotation (0, 0, 0, 1).
|
|
22
|
+
*/
|
|
23
|
+
export declare function createQuaternion(x?: number, y?: number, z?: number, w?: number): Quaternion;
|
|
24
|
+
export declare function equalsQuaternion(a: Readonly<QuaternionLike> | null | undefined, b: Readonly<QuaternionLike> | null | undefined): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the angle (in radians) between two unit quaternions. Returns 0 for identical
|
|
27
|
+
* rotations and up to π for opposite rotations. Takes the shorter arc.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getQuaternionAngleBetween(a: Readonly<QuaternionLike>, b: Readonly<QuaternionLike>): number;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the dot product of two quaternions: sum of component-wise products.
|
|
32
|
+
* Useful for measuring the similarity of two orientations; `|dot| === 1` means identical.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getQuaternionDot(a: Readonly<QuaternionLike>, b: Readonly<QuaternionLike>): number;
|
|
35
|
+
/**
|
|
36
|
+
* Extracts Euler angles (in radians) from a unit quaternion in the given `order`.
|
|
37
|
+
* Defaults to `'XYZ'`. Writes the result to `out` as (x=angle around X, y=around Y, z=around Z).
|
|
38
|
+
*
|
|
39
|
+
* Note: Euler angles have a gimbal-lock singularity when the middle axis reaches ±90°. At the
|
|
40
|
+
* singularity the decomposition is not unique; this implementation sets the third angle to 0
|
|
41
|
+
* and puts all the rotation into the first angle (a common convention).
|
|
42
|
+
*/
|
|
43
|
+
export declare function getQuaternionEuler(out: Vector3Like, source: Readonly<QuaternionLike>, order?: EulerOrder): void;
|
|
44
|
+
/**
|
|
45
|
+
* Writes the inverse of a quaternion. For unit quaternions this is the same as the conjugate;
|
|
46
|
+
* for non-unit quaternions this divides the conjugate by the squared length.
|
|
47
|
+
* A zero-length quaternion writes the identity rotation (0, 0, 0, 1).
|
|
48
|
+
*
|
|
49
|
+
* Safe when `out` aliases `source`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function inverseQuaternion(out: QuaternionLike, source: Readonly<QuaternionLike>): void;
|
|
52
|
+
/**
|
|
53
|
+
* Hamilton product of two quaternions: out = a · b. The result represents applying
|
|
54
|
+
* rotation `b` first, then rotation `a`.
|
|
55
|
+
*
|
|
56
|
+
* Safe when `out` aliases `a` and/or `b` (all inputs are read into locals first).
|
|
57
|
+
*/
|
|
58
|
+
export declare function multiplyQuaternion(out: QuaternionLike, a: Readonly<QuaternionLike>, b: Readonly<QuaternionLike>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Normalizes a quaternion to unit length. A zero-length quaternion is written as the
|
|
61
|
+
* identity rotation (0, 0, 0, 1).
|
|
62
|
+
*
|
|
63
|
+
* Returns the original length. Safe when `out` aliases `source`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function normalizeQuaternion(out: QuaternionLike, source: Readonly<QuaternionLike>): number;
|
|
66
|
+
/**
|
|
67
|
+
* Applies a quaternion rotation to a Vector3. Computes q * (0, v) * q^-1 using the
|
|
68
|
+
* sandwich product, which rotates the vector by the quaternion's rotation.
|
|
69
|
+
*
|
|
70
|
+
* Safe when `out` aliases `vector` (all inputs are read into locals first).
|
|
71
|
+
*/
|
|
72
|
+
export declare function rotateVector3ByQuaternion(out: Vector3Like, vector: Readonly<Vector3Like>, q: Readonly<QuaternionLike>): void;
|
|
73
|
+
/**
|
|
74
|
+
* Builds a quaternion from a rotation `axis` (assumed unit length) and an `angle` in
|
|
75
|
+
* radians. The rotation is right-handed (CCW when looking down the axis toward the origin).
|
|
76
|
+
*
|
|
77
|
+
* Safe when `out` aliases `axis`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function setQuaternionFromAxisAngle(out: QuaternionLike, axis: Readonly<Vector3Like>, angle: number): void;
|
|
80
|
+
/**
|
|
81
|
+
* Builds a quaternion from Euler angles (in radians) applied in the given `order`.
|
|
82
|
+
* Defaults to `'XYZ'` order (intrinsic rotations — each rotation is about the local,
|
|
83
|
+
* rotated axes).
|
|
84
|
+
*
|
|
85
|
+
* Safe when `out` has no aliasing concerns (scalars only).
|
|
86
|
+
*/
|
|
87
|
+
export declare function setQuaternionFromEuler(out: QuaternionLike, x: number, y: number, z: number, order?: EulerOrder): void;
|
|
88
|
+
/**
|
|
89
|
+
* Extracts the rotation of a Matrix4 (upper-left 3×3, assumed orthonormal) into a unit
|
|
90
|
+
* quaternion. Uses the numerically stable trace/largest-diagonal branch.
|
|
91
|
+
*/
|
|
92
|
+
export declare function setQuaternionFromMatrix4(out: QuaternionLike, source: Readonly<Matrix4Like>): void;
|
|
93
|
+
/**
|
|
94
|
+
* Builds the shortest-arc rotation quaternion from unit vector `from` to unit vector `to`.
|
|
95
|
+
*
|
|
96
|
+
* Handles the antiparallel case (from ≈ -to) by choosing an arbitrary perpendicular axis
|
|
97
|
+
* for a 180-degree rotation, so the result is always valid.
|
|
98
|
+
*
|
|
99
|
+
* Safe when `out` aliases `from` or `to`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function setQuaternionFromUnitVectors(out: QuaternionLike, from: Readonly<Vector3Like>, to: Readonly<Vector3Like>): void;
|
|
102
|
+
/**
|
|
103
|
+
* Resets a quaternion to the identity rotation (0, 0, 0, 1).
|
|
104
|
+
*/
|
|
105
|
+
export declare function setQuaternionIdentity(out: QuaternionLike): void;
|
|
106
|
+
/**
|
|
107
|
+
* Builds a "look rotation" quaternion from a `forward` and an `up` direction. Both vectors are
|
|
108
|
+
* assumed unit length. Convention: +Z forward with +Y up = identity quaternion (matches
|
|
109
|
+
* three.js / Unity).
|
|
110
|
+
*
|
|
111
|
+
* Internally computes `right = up × forward`, `correctedUp = forward × right`, and builds the
|
|
112
|
+
* rotation matrix from `[right, correctedUp, forward]` as column vectors.
|
|
113
|
+
*
|
|
114
|
+
* If `forward` and `up` are parallel or `forward` has zero length, the result is the
|
|
115
|
+
* identity quaternion.
|
|
116
|
+
*
|
|
117
|
+
* Safe when `out` has no aliasing concerns.
|
|
118
|
+
*/
|
|
119
|
+
export declare function setQuaternionLookRotation(out: QuaternionLike, forward: Readonly<Vector3Like>, up: Readonly<Vector3Like>): void;
|
|
120
|
+
/**
|
|
121
|
+
* Spherical linear interpolation between two unit quaternions at parameter `t` in [0, 1].
|
|
122
|
+
* Chooses the shorter arc (negating `b` if the dot product is negative) and falls back to
|
|
123
|
+
* normalized linear interpolation when the inputs are nearly collinear.
|
|
124
|
+
*
|
|
125
|
+
* Safe when `out` aliases `a` and/or `b` (all inputs are read into locals first).
|
|
126
|
+
*/
|
|
127
|
+
export declare function slerpQuaternion(out: QuaternionLike, a: Readonly<QuaternionLike>, b: Readonly<QuaternionLike>, t: number): void;
|
|
128
|
+
//# sourceMappingURL=quaternion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quaternion.d.ts","sourceRoot":"","sources":["../src/quaternion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAExG,wBAAgB,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,UAAU,CAE5E;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,IAAI,CAK/F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,IAAI,CAK1F;AAED;;;;;GAKG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