linearly 0.0.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/LICENSE +21 -0
- package/README.md +3 -0
- package/lib/common.d.ts +11 -0
- package/lib/common.js +16 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +9 -0
- package/lib/mat2.d.ts +78 -0
- package/lib/mat2.js +155 -0
- package/lib/mat2d.d.ts +89 -0
- package/lib/mat2d.js +238 -0
- package/lib/mat2d.test.d.ts +1 -0
- package/lib/mat2d.test.js +88 -0
- package/lib/mat3.d.ts +117 -0
- package/lib/mat3.js +390 -0
- package/lib/mat4.d.ts +310 -0
- package/lib/mat4.js +1173 -0
- package/lib/quat.d.ts +218 -0
- package/lib/quat.js +459 -0
- package/lib/vec2.d.ts +58 -0
- package/lib/vec2.js +135 -0
- package/lib/vec2.test.d.ts +1 -0
- package/lib/vec2.test.js +105 -0
- package/lib/vec3.d.ts +159 -0
- package/lib/vec3.js +326 -0
- package/lib/vec3.test.d.ts +1 -0
- package/lib/vec3.test.js +105 -0
- package/lib/vec4.d.ts +108 -0
- package/lib/vec4.js +241 -0
- package/package.json +50 -0
package/lib/mat4.d.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { Quat } from './quat';
|
|
2
|
+
import { Vec3 } from './vec3';
|
|
3
|
+
export type Mat4 = readonly [
|
|
4
|
+
number,
|
|
5
|
+
number,
|
|
6
|
+
number,
|
|
7
|
+
number,
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
number,
|
|
11
|
+
number,
|
|
12
|
+
number,
|
|
13
|
+
number,
|
|
14
|
+
number,
|
|
15
|
+
number,
|
|
16
|
+
number,
|
|
17
|
+
number,
|
|
18
|
+
number,
|
|
19
|
+
number
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The identity matrix of mat4
|
|
26
|
+
*/
|
|
27
|
+
export declare const identity: Mat4;
|
|
28
|
+
/**
|
|
29
|
+
* Transpose the values of a mat4
|
|
30
|
+
*/
|
|
31
|
+
export declare function transpose(a: Mat4): Mat4;
|
|
32
|
+
/**
|
|
33
|
+
* Inverts a mat4
|
|
34
|
+
*/
|
|
35
|
+
export declare function invert(a: Mat4): Mat4 | null;
|
|
36
|
+
/**
|
|
37
|
+
* Calculates the adjugate of a mat4
|
|
38
|
+
*/
|
|
39
|
+
export declare function adjoint(a: Mat4): Mat4;
|
|
40
|
+
/**
|
|
41
|
+
* Calculates the determinant of a mat4
|
|
42
|
+
*/
|
|
43
|
+
export declare function determinant(a: Mat4): number;
|
|
44
|
+
/**
|
|
45
|
+
* Multiplies two mat4's
|
|
46
|
+
*/
|
|
47
|
+
export declare function multiply(a: Mat4, b: Mat4): Mat4;
|
|
48
|
+
/**
|
|
49
|
+
* Translate a mat4 by the given vector
|
|
50
|
+
*
|
|
51
|
+
* @param a the matrix to translate
|
|
52
|
+
* @param v vector to translate by
|
|
53
|
+
*/
|
|
54
|
+
export declare function translate(a: Mat4, v: Vec3): Mat4;
|
|
55
|
+
/**
|
|
56
|
+
* Scales the mat4 by the dimensions in the given vec3 not using vectorization
|
|
57
|
+
**/
|
|
58
|
+
export declare function scale(a: Mat4, v: Vec3): Mat4;
|
|
59
|
+
/**
|
|
60
|
+
* Rotates a mat4 by the given angle around the given axis
|
|
61
|
+
*/
|
|
62
|
+
export declare function rotate(a: Mat4, rad: number, axis: Vec3): Mat4 | null;
|
|
63
|
+
/**
|
|
64
|
+
* Rotates a matrix by the given angle around the X axis
|
|
65
|
+
*/
|
|
66
|
+
export declare function rotateX(a: Mat4, rad: number): Mat4;
|
|
67
|
+
/**
|
|
68
|
+
* Rotates a matrix by the given angle around the Y axis
|
|
69
|
+
*/
|
|
70
|
+
export declare function rotateY(a: Mat4, rad: number): Mat4;
|
|
71
|
+
/**
|
|
72
|
+
* Rotates a matrix by the given angle around the Z axis
|
|
73
|
+
*/
|
|
74
|
+
export declare function rotateZ(a: Mat4, rad: number): Mat4;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a matrix from a vector translation
|
|
77
|
+
*/
|
|
78
|
+
export declare function fromTranslation(v: Vec3): Mat4;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a matrix from a vector scaling
|
|
81
|
+
*/
|
|
82
|
+
export declare function fromScaling(v: Vec3): Mat4;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a matrix from a given angle around a given axis
|
|
85
|
+
*/
|
|
86
|
+
export declare function fromRotation(rad: number, axis: Vec3): Mat4 | null;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a matrix from the given angle around the X axis
|
|
89
|
+
*/
|
|
90
|
+
export declare function fromXRotation(rad: number): Mat4;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a matrix from the given angle around the Y axis
|
|
93
|
+
*/
|
|
94
|
+
export declare function fromYRotation(rad: number): Mat4;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a matrix from the given angle around the Z axis
|
|
97
|
+
*/
|
|
98
|
+
export declare function fromZRotation(rad: number): Mat4;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a matrix from a quaternion rotation and vector translation
|
|
101
|
+
*/
|
|
102
|
+
export declare function fromRotationTranslation(q: Quat, v: Vec3): Mat4;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the translation vector component of a transformation
|
|
105
|
+
* matrix. If a matrix is built with fromRotationTranslation,
|
|
106
|
+
* the returned vector will be the same as the translation vector
|
|
107
|
+
* originally supplied.
|
|
108
|
+
*/
|
|
109
|
+
export declare function getTranslation(mat: Mat4): Vec3;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the scaling factor component of a transformation
|
|
112
|
+
* matrix. If a matrix is built with fromRotationTranslationScale
|
|
113
|
+
* with a normalized Quaternion paramter, the returned vector will be
|
|
114
|
+
* the same as the scaling vector
|
|
115
|
+
* originally supplied.
|
|
116
|
+
*/
|
|
117
|
+
export declare function getScaling(mat: Mat4): Vec3;
|
|
118
|
+
/**
|
|
119
|
+
* Returns a quaternion representing the rotational component
|
|
120
|
+
* of a transformation matrix. If a matrix is built with
|
|
121
|
+
* fromRotationTranslation, the returned quaternion will be the
|
|
122
|
+
* same as the quaternion originally supplied.
|
|
123
|
+
*/
|
|
124
|
+
export declare function getRotation(mat: Mat4): Quat;
|
|
125
|
+
interface DecomposedTRS {
|
|
126
|
+
rot: Quat;
|
|
127
|
+
trans: Vec3;
|
|
128
|
+
scale: Vec3;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Decomposes a transformation matrix into its rotation, translation
|
|
132
|
+
* and scale components. Returns only the rotation component
|
|
133
|
+
*
|
|
134
|
+
* @param mat Matrix to be decomposed (input)
|
|
135
|
+
*/
|
|
136
|
+
export declare function decompose(mat: Mat4): DecomposedTRS;
|
|
137
|
+
/**
|
|
138
|
+
* Creates a matrix from a quaternion rotation, vector translation and vector scale
|
|
139
|
+
* This is equivalent to (but much faster than):
|
|
140
|
+
*
|
|
141
|
+
* mat4.identity(dest);
|
|
142
|
+
* mat4.translate(dest, vec);
|
|
143
|
+
* const quatMat = mat4.create();
|
|
144
|
+
* quat4.toMat4(quat, quatMat);
|
|
145
|
+
* mat4.multiply(dest, quatMat);
|
|
146
|
+
* mat4.scale(dest, scale)
|
|
147
|
+
*
|
|
148
|
+
* @param rot Rotation quaternion
|
|
149
|
+
* @param trans Translation vector
|
|
150
|
+
* @param scale Scaling vector
|
|
151
|
+
*/
|
|
152
|
+
export declare function fromRotationTranslationScale(rot: Quat, trans: Vec3, scale: Vec3): Mat4;
|
|
153
|
+
/**
|
|
154
|
+
* Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
|
|
155
|
+
* This is equivalent to (but much faster than):
|
|
156
|
+
*
|
|
157
|
+
* mat4.identity(dest);
|
|
158
|
+
* mat4.translate(dest, vec);
|
|
159
|
+
* mat4.translate(dest, origin);
|
|
160
|
+
* const quatMat = mat4.create();
|
|
161
|
+
* quat4.toMat4(quat, quatMat);
|
|
162
|
+
* mat4.multiply(dest, quatMat);
|
|
163
|
+
* mat4.scale(dest, scale)
|
|
164
|
+
* mat4.translate(dest, negativeOrigin);
|
|
165
|
+
*
|
|
166
|
+
* @param rot Rotation quaternion
|
|
167
|
+
* @param trans Translation vector
|
|
168
|
+
* @param scale Scaling vector
|
|
169
|
+
* @param origin The origin vector around which to scale and rotate
|
|
170
|
+
*/
|
|
171
|
+
export declare function fromRotationTranslationScaleOrigin(rot: Quat, trans: Vec3, scale: Vec3, origin: Vec3): number[];
|
|
172
|
+
/**
|
|
173
|
+
* Calculates a 4x4 matrix from the given quaternion
|
|
174
|
+
*
|
|
175
|
+
* @param q Quaternion to create matrix from
|
|
176
|
+
*/
|
|
177
|
+
export declare function fromQuat(q: Quat): Mat4;
|
|
178
|
+
/**
|
|
179
|
+
* Generates a frustum matrix with the given bounds
|
|
180
|
+
*
|
|
181
|
+
* @param left Left bound of the frustum
|
|
182
|
+
* @param right Right bound of the frustum
|
|
183
|
+
* @param bottom Bottom bound of the frustum
|
|
184
|
+
* @param top Top bound of the frustum
|
|
185
|
+
* @param near Near bound of the frustum
|
|
186
|
+
* @param far Far bound of the frustum
|
|
187
|
+
*/
|
|
188
|
+
export declare function frustum(left: number, right: number, bottom: number, top: number, near: number, far: number): number[];
|
|
189
|
+
/**
|
|
190
|
+
* Generates a perspective projection matrix with the given bounds.
|
|
191
|
+
* The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
|
|
192
|
+
* which matches WebGL/OpenGL's clip volume.
|
|
193
|
+
* Passing null/undefined/no value for far will generate infinite projection matrix.
|
|
194
|
+
*
|
|
195
|
+
* @param fovy Vertical field of view in radians
|
|
196
|
+
* @param aspect Aspect ratio. typically viewport width/height
|
|
197
|
+
* @param near Near bound of the frustum
|
|
198
|
+
* @param far Far bound of the frustum, can be null or Infinity
|
|
199
|
+
*/
|
|
200
|
+
export declare function perspectiveNO(fovy: number, aspect: number, near: number, far: number): Mat4;
|
|
201
|
+
/**
|
|
202
|
+
* Alias for {@link mat4.perspectiveNO}
|
|
203
|
+
* @function
|
|
204
|
+
*/
|
|
205
|
+
export declare const perspective: typeof perspectiveNO;
|
|
206
|
+
/**
|
|
207
|
+
* Generates a perspective projection matrix suitable for WebGPU with the given bounds.
|
|
208
|
+
* The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
|
|
209
|
+
* which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
|
|
210
|
+
* Passing null/undefined/no value for far will generate infinite projection matrix.
|
|
211
|
+
*
|
|
212
|
+
* @param fovy Vertical field of view in radians
|
|
213
|
+
* @param aspect Aspect ratio. typically viewport width/height
|
|
214
|
+
* @param near Near bound of the frustum
|
|
215
|
+
* @param far Far bound of the frustum, can be null or Infinity
|
|
216
|
+
*/
|
|
217
|
+
export declare function perspectiveZO(fovy: number, aspect: number, near: number, far: number | null): Mat4;
|
|
218
|
+
interface FovDegrees {
|
|
219
|
+
upDegrees: number;
|
|
220
|
+
downDegrees: number;
|
|
221
|
+
leftDegrees: number;
|
|
222
|
+
rightDegrees: number;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Generates a perspective projection matrix with the given field of view.
|
|
226
|
+
* This is primarily useful for generating projection matrices to be used
|
|
227
|
+
* with the still experiemental WebVR API.
|
|
228
|
+
*
|
|
229
|
+
* @param fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
|
|
230
|
+
* @param near Near bound of the frustum
|
|
231
|
+
* @param far Far bound of the frustum
|
|
232
|
+
*/
|
|
233
|
+
export declare function perspectiveFromFieldOfView(fov: FovDegrees, near: number, far: number): Mat4;
|
|
234
|
+
/**
|
|
235
|
+
* Generates a orthogonal projection matrix with the given bounds.
|
|
236
|
+
* The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
|
|
237
|
+
* which matches WebGL/OpenGL's clip volume.
|
|
238
|
+
*
|
|
239
|
+
* @param left Left bound of the frustum
|
|
240
|
+
* @param right Right bound of the frustum
|
|
241
|
+
* @param bottom Bottom bound of the frustum
|
|
242
|
+
* @param top Top bound of the frustum
|
|
243
|
+
* @param near Near bound of the frustum
|
|
244
|
+
* @param far Far bound of the frustum
|
|
245
|
+
*/
|
|
246
|
+
export declare function orthoNO(left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4;
|
|
247
|
+
/**
|
|
248
|
+
* Alias for {@link mat4.orthoNO}
|
|
249
|
+
* @function
|
|
250
|
+
*/
|
|
251
|
+
export declare const ortho: typeof orthoNO;
|
|
252
|
+
/**
|
|
253
|
+
* Generates a orthogonal projection matrix with the given bounds.
|
|
254
|
+
* The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
|
|
255
|
+
* which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
|
|
256
|
+
*
|
|
257
|
+
* @param left Left bound of the frustum
|
|
258
|
+
* @param right Right bound of the frustum
|
|
259
|
+
* @param bottom Bottom bound of the frustum
|
|
260
|
+
* @param top Top bound of the frustum
|
|
261
|
+
* @param near Near bound of the frustum
|
|
262
|
+
* @param far Far bound of the frustum
|
|
263
|
+
*/
|
|
264
|
+
export declare function orthoZO(left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4;
|
|
265
|
+
/**
|
|
266
|
+
* Generates a look-at matrix with the given eye position, focal point, and up axis.
|
|
267
|
+
* If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
|
|
268
|
+
*
|
|
269
|
+
* @param eye Position of the viewer
|
|
270
|
+
* @param center Point the viewer is looking at
|
|
271
|
+
* @param up vec3 pointing up
|
|
272
|
+
*/
|
|
273
|
+
export declare function lookAt(eye: Vec3, center: Vec3, up: Vec3): Mat4;
|
|
274
|
+
/**
|
|
275
|
+
* Generates a matrix that makes something look at something else.
|
|
276
|
+
*
|
|
277
|
+
* @param eye Position of the viewer
|
|
278
|
+
* @param center Point the viewer is looking at
|
|
279
|
+
* @param up vec3 pointing up
|
|
280
|
+
*/
|
|
281
|
+
export declare function targetTo(eye: Vec3, target: Vec3, up: Vec3): Mat4;
|
|
282
|
+
/**
|
|
283
|
+
* Returns Frobenius norm of a mat4
|
|
284
|
+
*/
|
|
285
|
+
export declare function frob(a: Mat4): number;
|
|
286
|
+
/**
|
|
287
|
+
* Adds two mat4's
|
|
288
|
+
*/
|
|
289
|
+
export declare function add(a: Mat4, b: Mat4): number[];
|
|
290
|
+
/**
|
|
291
|
+
* Subtracts matrix b from matrix a
|
|
292
|
+
*/
|
|
293
|
+
export declare function subtract(a: Mat4, b: Mat4): Mat4;
|
|
294
|
+
/**
|
|
295
|
+
* Multiply each element of the matrix by a scalar.
|
|
296
|
+
*/
|
|
297
|
+
export declare function multiplyScalar(a: Mat4, s: number): Mat4;
|
|
298
|
+
/**
|
|
299
|
+
* Adds two mat4's after multiplying each element of the second operand by a scalar value.
|
|
300
|
+
*/
|
|
301
|
+
export declare function multiplyScalarAndAdd(a: Mat4, b: Mat4, scale: number): Mat4;
|
|
302
|
+
/**
|
|
303
|
+
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
|
|
304
|
+
*/
|
|
305
|
+
export declare function exactEquals(a: Mat4, b: Mat4): boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Returns whether or not the matrices have approximately the same elements in the same position.
|
|
308
|
+
*/
|
|
309
|
+
export declare function equals(a: Mat4, b: Mat4): boolean;
|
|
310
|
+
export {};
|