linearly 0.20.2 → 0.20.3

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