@defold-typescript/types 0.25.0 → 0.27.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/api-availability.json +333 -306
- package/api-signatures.json +1312 -0
- package/api-targets.json +351 -2
- package/examples/translations.json +1984 -0
- package/fixtures/messages_doc.json +880 -0
- package/generated/collectionproxy.d.ts +22 -0
- package/generated/editor-vm/http.d.ts +2 -2
- package/generated/editor-vm/image.d.ts +48 -0
- package/generated/editor.d.ts +27 -8
- package/generated/gui.d.ts +35 -6
- package/generated/kinds/editor-script.d.ts +1 -0
- package/generated/material.d.ts +4 -0
- package/generated/versions/defold-1.12.4/liveupdate.d.ts +22 -22
- package/generated/versions/defold-1.12.4/physics.d.ts +78 -75
- package/generated/versions/defold-1.12.4/render.d.ts +75 -55
- package/generated/versions/defold-1.12.4/resource.d.ts +187 -175
- package/generated/versions/defold-1.13.0/b2d.d.ts +33 -0
- package/generated/versions/defold-1.13.0/b2d_body.d.ts +676 -0
- package/generated/versions/defold-1.13.0/b2d_chain.d.ts +106 -0
- package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +155 -0
- package/generated/versions/defold-1.13.0/b2d_joint.d.ts +823 -0
- package/generated/versions/defold-1.13.0/b2d_shape.d.ts +215 -0
- package/generated/versions/defold-1.13.0/b2d_world.d.ts +314 -0
- package/generated/versions/defold-1.13.0/buffer.d.ts +176 -0
- package/generated/versions/defold-1.13.0/camera.d.ts +302 -0
- package/generated/versions/defold-1.13.0/collectionfactory.d.ts +146 -0
- package/generated/versions/defold-1.13.0/collectionproxy.d.ts +71 -0
- package/generated/versions/defold-1.13.0/compute.d.ts +306 -0
- package/generated/versions/defold-1.13.0/crash.d.ts +143 -0
- package/generated/versions/defold-1.13.0/editor-vm/http.d.ts +56 -0
- package/generated/versions/defold-1.13.0/editor-vm/json.d.ts +10 -0
- package/generated/versions/defold-1.13.0/editor-vm/localization.d.ts +42 -0
- package/generated/versions/defold-1.13.0/editor-vm/tilemap_tiles.d.ts +80 -0
- package/generated/versions/defold-1.13.0/editor-vm/zip.d.ts +10 -0
- package/generated/versions/defold-1.13.0/editor-vm/zlib.d.ts +24 -0
- package/generated/versions/defold-1.13.0/editor.d.ts +1092 -0
- package/generated/versions/defold-1.13.0/factory.d.ts +123 -0
- package/generated/versions/defold-1.13.0/font.d.ts +81 -0
- package/generated/versions/defold-1.13.0/go.d.ts +1054 -0
- package/generated/versions/defold-1.13.0/graphics.d.ts +321 -0
- package/generated/versions/defold-1.13.0/gui.d.ts +2370 -0
- package/generated/versions/defold-1.13.0/html5.d.ts +53 -0
- package/generated/versions/defold-1.13.0/http.d.ts +84 -0
- package/generated/versions/defold-1.13.0/iac.d.ts +18 -0
- package/generated/versions/defold-1.13.0/iap.d.ts +60 -0
- package/generated/versions/defold-1.13.0/image.d.ts +139 -0
- package/generated/versions/defold-1.13.0/index.d.ts +48 -0
- package/generated/versions/defold-1.13.0/json.d.ts +76 -0
- package/generated/versions/defold-1.13.0/kinds/editor-script.d.ts +13 -0
- package/generated/versions/defold-1.13.0/label.d.ts +94 -0
- package/generated/versions/defold-1.13.0/liveupdate.d.ts +140 -0
- package/generated/versions/defold-1.13.0/material.d.ts +444 -0
- package/generated/versions/defold-1.13.0/model.d.ts +246 -0
- package/generated/versions/defold-1.13.0/msg.d.ts +10 -0
- package/generated/versions/defold-1.13.0/particlefx.d.ts +166 -0
- package/generated/versions/defold-1.13.0/physics.d.ts +548 -0
- package/generated/versions/defold-1.13.0/profiler.d.ts +233 -0
- package/generated/versions/defold-1.13.0/push.d.ts +66 -0
- package/generated/versions/defold-1.13.0/render.d.ts +1185 -0
- package/generated/versions/defold-1.13.0/resource.d.ts +1530 -0
- package/generated/versions/defold-1.13.0/socket.d.ts +795 -0
- package/generated/versions/defold-1.13.0/sound.d.ts +291 -0
- package/generated/versions/defold-1.13.0/sprite.d.ts +157 -0
- package/generated/versions/defold-1.13.0/sys.d.ts +695 -0
- package/generated/versions/defold-1.13.0/tilemap.d.ts +195 -0
- package/generated/versions/defold-1.13.0/timer.d.ts +114 -0
- package/generated/versions/defold-1.13.0/types.d.ts +61 -0
- package/generated/versions/defold-1.13.0/vmath.d.ts +806 -0
- package/generated/versions/defold-1.13.0/webview.d.ts +68 -0
- package/generated/versions/defold-1.13.0/window.d.ts +198 -0
- package/generated/versions/defold-1.13.0/zlib.d.ts +40 -0
- package/index.d.ts +4 -81
- package/package.json +11 -3
- package/scripts/import-defold-release.ts +28 -1
- package/scripts/sync-api-docs.ts +4 -3
- package/src/api-availability.ts +0 -0
- package/src/emit-dts.ts +6 -0
- package/src/example-store.ts +5 -0
- package/src/index.ts +3 -0
- package/scripts/lua-types-signature-index.ts +0 -151
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import type { Matrix4, Quaternion, Vector, Vector3, Vector4 } from "../../../src/core-types";
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Functions for mathematical operations on vectors, matrices and quaternions.
|
|
7
|
+
*
|
|
8
|
+
* - The vector types (`vmath.vector3` and `vmath.vector4`) supports addition and subtraction
|
|
9
|
+
* with vectors of the same type. Vectors can be negated and multiplied (scaled) or divided by numbers.
|
|
10
|
+
* - The quaternion type (`vmath.quat`) supports multiplication with other quaternions.
|
|
11
|
+
* - The matrix type (`vmath.matrix4`) can be multiplied with numbers, other matrices
|
|
12
|
+
* and `vmath.vector4` values.
|
|
13
|
+
* - All types performs equality comparison by each component value.
|
|
14
|
+
*
|
|
15
|
+
* The following components are available for the various types:
|
|
16
|
+
*
|
|
17
|
+
* vector3
|
|
18
|
+
* : `x`, `y` and `z`. Example: `v.y`
|
|
19
|
+
*
|
|
20
|
+
* vector4
|
|
21
|
+
* : `x`, `y`, `z`, and `w`. Example: `v.w`
|
|
22
|
+
*
|
|
23
|
+
* quaternion
|
|
24
|
+
* : `x`, `y`, `z`, and `w`. Example: `q.w`
|
|
25
|
+
*
|
|
26
|
+
* matrix4
|
|
27
|
+
* : `m00` to `m33` where the first number is the row (starting from 0) and the second
|
|
28
|
+
* number is the column. Columns can be accessed with `c0` to `c3`, returning a `vector4`.
|
|
29
|
+
* Example: `m.m21` which is equal to `m.c1.z`
|
|
30
|
+
*
|
|
31
|
+
* vector
|
|
32
|
+
* : indexed by number 1 to the vector length. Example: `v[3]`
|
|
33
|
+
*/
|
|
34
|
+
namespace vmath {
|
|
35
|
+
/**
|
|
36
|
+
* Calculates the conjugate of a quaternion. The result is a
|
|
37
|
+
* quaternion with the same magnitudes but with the sign of
|
|
38
|
+
* the imaginary (vector) parts changed:
|
|
39
|
+
* `q* = [w, -v]`
|
|
40
|
+
*
|
|
41
|
+
* @param q1 - quaternion of which to calculate the conjugate
|
|
42
|
+
* @returns the conjugate
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const quat = vmath.quat(1, 2, 3, 4);
|
|
46
|
+
* print(vmath.conj(quat)); // => vmath.quat(-1, -2, -3, 4)
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
function conj(q1: Quaternion): Quaternion;
|
|
50
|
+
/**
|
|
51
|
+
* Given two linearly independent vectors P and Q, the cross product,
|
|
52
|
+
* P × Q, is a vector that is perpendicular to both P and Q and
|
|
53
|
+
* therefore normal to the plane containing them.
|
|
54
|
+
* If the two vectors have the same direction (or have the exact
|
|
55
|
+
* opposite direction from one another, i.e. are not linearly independent)
|
|
56
|
+
* or if either one has zero length, then their cross product is zero.
|
|
57
|
+
*
|
|
58
|
+
* @param v1 - first vector
|
|
59
|
+
* @param v2 - second vector
|
|
60
|
+
* @returns a new vector representing the cross product
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const vec1 = vmath.vector3(1, 0, 0);
|
|
64
|
+
* const vec2 = vmath.vector3(0, 1, 0);
|
|
65
|
+
* print(vmath.cross(vec1, vec2)); // => vmath.vector3(0, 0, 1)
|
|
66
|
+
* const vec3 = vmath.vector3(-1, 0, 0);
|
|
67
|
+
* print(vmath.cross(vec1, vec3)); // => vmath.vector3(0, -0, 0)
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
function cross(v1: Vector3, v2: Vector3): Vector3;
|
|
71
|
+
/**
|
|
72
|
+
* The returned value is a scalar defined as:
|
|
73
|
+
* `P ⋅ Q = |P| |Q| cos θ`
|
|
74
|
+
* where θ is the angle between the vectors P and Q.
|
|
75
|
+
*
|
|
76
|
+
* - If the dot product is positive then the angle between the vectors is below 90 degrees.
|
|
77
|
+
*
|
|
78
|
+
* - If the dot product is zero the vectors are perpendicular (at right-angles to each other).
|
|
79
|
+
*
|
|
80
|
+
* - If the dot product is negative then the angle between the vectors is more than 90 degrees.
|
|
81
|
+
*
|
|
82
|
+
* @param v1 - first vector
|
|
83
|
+
* @param v2 - second vector
|
|
84
|
+
* @returns dot product
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* if (vmath.dot(vector1, vector2) === 0) {
|
|
88
|
+
* // The two vectors are perpendicular (at right-angles to each other)
|
|
89
|
+
* // ...
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function dot(v1: Vector3 | Vector4, v2: Vector3 | Vector4): number;
|
|
94
|
+
/**
|
|
95
|
+
* Converts euler angles (x, y, z) in degrees into a quaternion
|
|
96
|
+
* The error is guaranteed to be less than 0.001.
|
|
97
|
+
* If the first argument is vector3, its values are used as x, y, z angles.
|
|
98
|
+
*
|
|
99
|
+
* @param x - rotation around x-axis in degrees or vector3 with euler angles in degrees
|
|
100
|
+
* @param y - rotation around y-axis in degrees
|
|
101
|
+
* @param z - rotation around z-axis in degrees
|
|
102
|
+
* @returns quaternion describing an equivalent rotation (231 (YZX) rotation sequence)
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const q = vmath.euler_to_quat(0, 45, 90);
|
|
106
|
+
* print(q); // => vmath.quat(0.27059805393219, 0.27059805393219, 0.65328145027161, 0.65328145027161)
|
|
107
|
+
*
|
|
108
|
+
* const v = vmath.vector3(0, 0, 90);
|
|
109
|
+
* print(vmath.euler_to_quat(v)); // => vmath.quat(0, 0, 0.70710676908493, 0.70710676908493)
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
function euler_to_quat(x: number | Vector3, y: number, z: number): Quaternion;
|
|
113
|
+
/**
|
|
114
|
+
* The resulting matrix is the inverse of the supplied matrix.
|
|
115
|
+
* For ortho-normal matrices, e.g. regular object transformation,
|
|
116
|
+
* use `vmath.ortho_inv()` instead.
|
|
117
|
+
* The specialized inverse for ortho-normalized matrices is much faster
|
|
118
|
+
* than the general inverse.
|
|
119
|
+
*
|
|
120
|
+
* @param m1 - matrix to invert
|
|
121
|
+
* @returns inverse of the supplied matrix
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const mat1 = vmath.matrix4_rotation_z(3.141592653);
|
|
125
|
+
* const mat2 = vmath.inv(mat1);
|
|
126
|
+
* // M * inv(M) = identity matrix
|
|
127
|
+
* print(mat1.mul(mat2)); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
function inv(m1: Matrix4): Matrix4;
|
|
131
|
+
/**
|
|
132
|
+
* Returns the length of the supplied vector or quaternion.
|
|
133
|
+
* If you are comparing the lengths of vectors or quaternions, you should compare
|
|
134
|
+
* the length squared instead as it is slightly more efficient to calculate
|
|
135
|
+
* (it eliminates a square root calculation).
|
|
136
|
+
*
|
|
137
|
+
* @param v - value of which to calculate the length
|
|
138
|
+
* @returns length
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* if (vmath.length(self.velocity) < max_velocity) {
|
|
142
|
+
* // The speed (velocity vector) is below max.
|
|
143
|
+
*
|
|
144
|
+
* // TODO: max_velocity can be expressed as squared
|
|
145
|
+
* // so we can compare with length_sqr() instead.
|
|
146
|
+
* // ...
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
function length(v: Vector3 | Vector4 | Quaternion): number;
|
|
151
|
+
/**
|
|
152
|
+
* Returns the squared length of the supplied vector or quaternion.
|
|
153
|
+
*
|
|
154
|
+
* @param v - value of which to calculate the squared length
|
|
155
|
+
* @returns squared length
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* if (vmath.length_sqr(vector1) < vmath.length_sqr(vector2)) {
|
|
159
|
+
* // Vector 1 has less magnitude than vector 2
|
|
160
|
+
* // ...
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
function length_sqr(v: Vector3 | Vector4 | Quaternion): number;
|
|
165
|
+
/**
|
|
166
|
+
* The resulting identity matrix describes a transform with
|
|
167
|
+
* no translation or rotation.
|
|
168
|
+
*
|
|
169
|
+
* @returns identity matrix
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const mat = vmath.matrix4();
|
|
173
|
+
* print(mat); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
|
174
|
+
* // get column 0:
|
|
175
|
+
* print(mat.c0); // => vmath.vector4(1, 0, 0, 0)
|
|
176
|
+
* // get the value in row 3 and column 2:
|
|
177
|
+
* print(mat.m32); // => 0
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
function matrix4(): Matrix4;
|
|
181
|
+
/**
|
|
182
|
+
* Creates a new matrix with all components set to the
|
|
183
|
+
* corresponding values from the supplied matrix. I.e.
|
|
184
|
+
* the function creates a copy of the given matrix.
|
|
185
|
+
*
|
|
186
|
+
* @param m1 - existing matrix
|
|
187
|
+
* @returns matrix which is a copy of the specified matrix
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const mat1 = vmath.matrix4_rotation_x(3.141592653);
|
|
191
|
+
* const mat2 = vmath.matrix4(mat1);
|
|
192
|
+
* if (mat1 === mat2) {
|
|
193
|
+
* // yes, they are equal
|
|
194
|
+
* print(mat2); // => vmath.matrix4(1, 0, 0, 0, 0, -1, 8.7422776573476e-08, 0, 0, -8.7422776573476e-08, -1, 0, 0, 0, 0, 1)
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
function matrix4(m1: Matrix4): Matrix4;
|
|
199
|
+
/**
|
|
200
|
+
* The resulting matrix describes a rotation around the axis by the specified angle.
|
|
201
|
+
*
|
|
202
|
+
* @param v - axis
|
|
203
|
+
* @param angle - angle in radians
|
|
204
|
+
* @returns matrix represented by axis and angle
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
208
|
+
* const axis = vmath.vector3(0, 0, 1); // z-axis
|
|
209
|
+
* const mat = vmath.matrix4_axis_angle(axis, 3.141592653);
|
|
210
|
+
* print(mat.mul(vec)); // => vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
function matrix4_axis_angle(v: Vector3, angle: number): Matrix4;
|
|
214
|
+
/**
|
|
215
|
+
* Creates a new matrix constructed from separate
|
|
216
|
+
* translation vector, roation quaternion and scale vector
|
|
217
|
+
*
|
|
218
|
+
* @param translation - translation
|
|
219
|
+
* @param rotation - rotation
|
|
220
|
+
* @param scale - scale
|
|
221
|
+
* @returns new matrix4
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const translation = vmath.vector3(103, -95, 14);
|
|
225
|
+
* const quat = vmath.quat(1, 2, 3, 4);
|
|
226
|
+
* const scale = vmath.vector3(1, 0.5, 0.5);
|
|
227
|
+
* const result = vmath.matrix4_compose(translation, quat, scale);
|
|
228
|
+
* print(result); // => vmath.matrix4(-25, -10, 11, 103, 28, -9.5, 2, -95, -10, 10, -4.5, 14, 0, 0, 0, 1)
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
function matrix4_compose(translation: Vector3 | Vector4, rotation: Quaternion, scale: Vector3): Matrix4;
|
|
232
|
+
/**
|
|
233
|
+
* Constructs a frustum matrix from the given values. The left, right,
|
|
234
|
+
* top and bottom coordinates of the view cone are expressed as distances
|
|
235
|
+
* from the center of the near clipping plane. The near and far coordinates
|
|
236
|
+
* are expressed as distances from the tip of the view frustum cone.
|
|
237
|
+
*
|
|
238
|
+
* @param left - coordinate for left clipping plane
|
|
239
|
+
* @param right - coordinate for right clipping plane
|
|
240
|
+
* @param bottom - coordinate for bottom clipping plane
|
|
241
|
+
* @param top - coordinate for top clipping plane
|
|
242
|
+
* @param near - coordinate for near clipping plane
|
|
243
|
+
* @param far - coordinate for far clipping plane
|
|
244
|
+
* @returns matrix representing the frustum
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* // Construct a projection frustum with a vertical and horizontal FOV of
|
|
248
|
+
* // 45 degrees. Useful for rendering a square view.
|
|
249
|
+
* const proj = vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000);
|
|
250
|
+
* render.set_projection(proj);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
function matrix4_frustum(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4;
|
|
254
|
+
/**
|
|
255
|
+
* The resulting matrix is created from the supplied look-at parameters.
|
|
256
|
+
* This is useful for constructing a view matrix for a camera or
|
|
257
|
+
* rendering in general.
|
|
258
|
+
*
|
|
259
|
+
* @param eye - eye position
|
|
260
|
+
* @param look_at - look-at position
|
|
261
|
+
* @param up - up vector
|
|
262
|
+
* @returns look-at matrix
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* // Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV, aspect ratio 4:3.
|
|
266
|
+
* const eye = vmath.vector3(0, 0, 100);
|
|
267
|
+
* const look_at = vmath.vector3(0, 0, 0);
|
|
268
|
+
* const up = vmath.vector3(0, 1, 0);
|
|
269
|
+
* const view = vmath.matrix4_look_at(eye, look_at, up);
|
|
270
|
+
* render.set_view(view);
|
|
271
|
+
* const proj = vmath.matrix4_perspective(3.141592 / 2, 4 / 3, 1, 1000);
|
|
272
|
+
* render.set_projection(proj);
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
function matrix4_look_at(eye: Vector3, look_at: Vector3, up: Vector3): Matrix4;
|
|
276
|
+
/**
|
|
277
|
+
* Creates an orthographic projection matrix.
|
|
278
|
+
* This is useful to construct a projection matrix for a camera or rendering in general.
|
|
279
|
+
*
|
|
280
|
+
* @param left - coordinate for left clipping plane
|
|
281
|
+
* @param right - coordinate for right clipping plane
|
|
282
|
+
* @param bottom - coordinate for bottom clipping plane
|
|
283
|
+
* @param top - coordinate for top clipping plane
|
|
284
|
+
* @param near - coordinate for near clipping plane
|
|
285
|
+
* @param far - coordinate for far clipping plane
|
|
286
|
+
* @returns orthographic projection matrix
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* // Set up an orthographic projection based on the width and height of the
|
|
290
|
+
* // game window.
|
|
291
|
+
* const w = render.get_width();
|
|
292
|
+
* const h = render.get_height();
|
|
293
|
+
* const proj = vmath.matrix4_orthographic(-w / 2, w / 2, -h / 2, h / 2, -1000, 1000);
|
|
294
|
+
* render.set_projection(proj);
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
function matrix4_orthographic(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4;
|
|
298
|
+
/**
|
|
299
|
+
* Creates a perspective projection matrix.
|
|
300
|
+
* This is useful to construct a projection matrix for a camera or rendering in general.
|
|
301
|
+
*
|
|
302
|
+
* @param fov - angle of the full vertical field of view in radians
|
|
303
|
+
* @param aspect - aspect ratio
|
|
304
|
+
* @param near - coordinate for near clipping plane
|
|
305
|
+
* @param far - coordinate for far clipping plane
|
|
306
|
+
* @returns perspective projection matrix
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* // Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV, aspect ratio 4:3.
|
|
310
|
+
* const eye = vmath.vector3(0, 0, 100);
|
|
311
|
+
* const look_at = vmath.vector3(0, 0, 0);
|
|
312
|
+
* const up = vmath.vector3(0, 1, 0);
|
|
313
|
+
* const view = vmath.matrix4_look_at(eye, look_at, up);
|
|
314
|
+
* render.set_view(view);
|
|
315
|
+
* const proj = vmath.matrix4_perspective(3.141592 / 2, 4 / 3, 1, 1000);
|
|
316
|
+
* render.set_projection(proj);
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
function matrix4_perspective(fov: number, aspect: number, near: number, far: number): Matrix4;
|
|
320
|
+
/**
|
|
321
|
+
* The resulting matrix describes the same rotation as the quaternion, but does not have any translation (also like the quaternion).
|
|
322
|
+
*
|
|
323
|
+
* @param q - quaternion to create matrix from
|
|
324
|
+
* @returns matrix represented by quaternion
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
328
|
+
* const quat = vmath.quat_rotation_z(3.141592653);
|
|
329
|
+
* const mat = vmath.matrix4_quat(quat);
|
|
330
|
+
* print(mat.mul(vec)); // => vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000)
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
function matrix4_quat(q: Quaternion): Matrix4;
|
|
334
|
+
/**
|
|
335
|
+
* The resulting matrix describes a rotation around the x-axis
|
|
336
|
+
* by the specified angle.
|
|
337
|
+
*
|
|
338
|
+
* @param angle - angle in radians around x-axis
|
|
339
|
+
* @returns matrix from rotation around x-axis
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
343
|
+
* const mat = vmath.matrix4_rotation_x(3.141592653);
|
|
344
|
+
* print(mat.mul(vec)); // => vmath.vector4(1, -1, -8.7422776573476e-08, 0)
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
function matrix4_rotation_x(angle: number): Matrix4;
|
|
348
|
+
/**
|
|
349
|
+
* The resulting matrix describes a rotation around the y-axis
|
|
350
|
+
* by the specified angle.
|
|
351
|
+
*
|
|
352
|
+
* @param angle - angle in radians around y-axis
|
|
353
|
+
* @returns matrix from rotation around y-axis
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
357
|
+
* const mat = vmath.matrix4_rotation_y(3.141592653);
|
|
358
|
+
* print(mat.mul(vec)); // => vmath.vector4(-1, 1, 8.7422776573476e-08, 0)
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
function matrix4_rotation_y(angle: number): Matrix4;
|
|
362
|
+
/**
|
|
363
|
+
* The resulting matrix describes a rotation around the z-axis
|
|
364
|
+
* by the specified angle.
|
|
365
|
+
*
|
|
366
|
+
* @param angle - angle in radians around z-axis
|
|
367
|
+
* @returns matrix from rotation around z-axis
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
371
|
+
* const mat = vmath.matrix4_rotation_z(3.141592653);
|
|
372
|
+
* print(mat.mul(vec)); // => vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
function matrix4_rotation_z(angle: number): Matrix4;
|
|
376
|
+
/**
|
|
377
|
+
* Creates a new matrix constructed from scale vector
|
|
378
|
+
*
|
|
379
|
+
* @param scale - scale
|
|
380
|
+
* @returns new matrix4
|
|
381
|
+
* @example
|
|
382
|
+
* ```ts
|
|
383
|
+
* const scale = vmath.vector3(1, 0.5, 0.5);
|
|
384
|
+
* const result = vmath.matrix4_scale(scale);
|
|
385
|
+
* print(result); // => vmath.matrix4(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
function matrix4_scale(scale: Vector3): Matrix4;
|
|
389
|
+
/**
|
|
390
|
+
* creates a new matrix4 from uniform scale
|
|
391
|
+
*
|
|
392
|
+
* @param scale - scale
|
|
393
|
+
* @returns new matrix4
|
|
394
|
+
* @example
|
|
395
|
+
* ```ts
|
|
396
|
+
* const result = vmath.matrix4_scale(0.5);
|
|
397
|
+
* print(result); // => vmath.matrix4(0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
function matrix4_scale(scale: number): Matrix4;
|
|
401
|
+
/**
|
|
402
|
+
* Creates a new matrix4 from three scale components
|
|
403
|
+
*
|
|
404
|
+
* @param scale_x - scale along X axis
|
|
405
|
+
* @param scale_y - sclae along Y axis
|
|
406
|
+
* @param scale_z - scale along Z asis
|
|
407
|
+
* @returns new matrix4
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts
|
|
410
|
+
* const result = vmath.matrix4_scale(1, 0.5, 0.5);
|
|
411
|
+
* print(result); // => vmath.matrix4(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
function matrix4_scale(scale_x: number, scale_y: number, scale_z: number): Matrix4;
|
|
415
|
+
/**
|
|
416
|
+
* The resulting matrix describes a translation of a point
|
|
417
|
+
* in euclidean space.
|
|
418
|
+
*
|
|
419
|
+
* @param position - position vector to create matrix from
|
|
420
|
+
* @returns matrix from the supplied position vector
|
|
421
|
+
* @example
|
|
422
|
+
* ```ts
|
|
423
|
+
* // Set camera view from custom view and translation matrices.
|
|
424
|
+
* const mat_trans = vmath.matrix4_translation(vmath.vector3(0, 10, 100));
|
|
425
|
+
* const mat_view = vmath.matrix4_rotation_y(-3.141592 / 4);
|
|
426
|
+
* render.set_view(mat_view.mul(mat_trans));
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
function matrix4_translation(position: Vector3 | Vector4): Matrix4;
|
|
430
|
+
/**
|
|
431
|
+
* The resulting matrix is the inverse of the supplied matrix.
|
|
432
|
+
* The supplied matrix has to be an ortho-normal matrix, e.g.
|
|
433
|
+
* describe a regular object transformation.
|
|
434
|
+
* For matrices that are not ortho-normal
|
|
435
|
+
* use the general inverse `vmath.inv()` instead.
|
|
436
|
+
*
|
|
437
|
+
* @param m1 - ortho-normalized matrix to invert
|
|
438
|
+
* @returns inverse of the supplied matrix
|
|
439
|
+
* @example
|
|
440
|
+
* ```ts
|
|
441
|
+
* const mat1 = vmath.matrix4_rotation_z(3.141592653);
|
|
442
|
+
* const mat2 = vmath.ortho_inv(mat1);
|
|
443
|
+
* // M * inv(M) = identity matrix
|
|
444
|
+
* print(mat1.mul(mat2)); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
function ortho_inv(m1: Matrix4): Matrix4;
|
|
448
|
+
/**
|
|
449
|
+
* Calculates the extent the projection of the first vector onto the second.
|
|
450
|
+
* The returned value is a scalar p defined as:
|
|
451
|
+
* `p = |P| cos θ / |Q|`
|
|
452
|
+
* where θ is the angle between the vectors P and Q.
|
|
453
|
+
*
|
|
454
|
+
* @param v1 - vector to be projected on the second
|
|
455
|
+
* @param v2 - vector onto which the first will be projected, must not have zero length
|
|
456
|
+
* @returns the projected extent of the first vector onto the second
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts
|
|
459
|
+
* const v1 = vmath.vector3(1, 1, 0);
|
|
460
|
+
* const v2 = vmath.vector3(2, 0, 0);
|
|
461
|
+
* print(vmath.project(v1, v2)); // => 0.5
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
function project(v1: Vector3, v2: Vector3): number;
|
|
465
|
+
/**
|
|
466
|
+
* Creates a new identity quaternion. The identity
|
|
467
|
+
* quaternion is equal to:
|
|
468
|
+
* `vmath.quat(0, 0, 0, 1)`
|
|
469
|
+
*
|
|
470
|
+
* @returns new identity quaternion
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* const quat = vmath.quat();
|
|
474
|
+
* print(quat); // => vmath.quat(0, 0, 0, 1)
|
|
475
|
+
* print(quat.w); // => 1
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
function quat(): Quaternion;
|
|
479
|
+
/**
|
|
480
|
+
* Creates a new quaternion with all components set to the
|
|
481
|
+
* corresponding values from the supplied quaternion. I.e.
|
|
482
|
+
* This function creates a copy of the given quaternion.
|
|
483
|
+
*
|
|
484
|
+
* @param q1 - existing quaternion
|
|
485
|
+
* @returns new quaternion
|
|
486
|
+
* @example
|
|
487
|
+
* ```ts
|
|
488
|
+
* const quat1 = vmath.quat(1, 2, 3, 4);
|
|
489
|
+
* const quat2 = vmath.quat(quat1);
|
|
490
|
+
* if (quat1 === quat2) {
|
|
491
|
+
* // yes, they are equal
|
|
492
|
+
* print(quat2); // => vmath.quat(1, 2, 3, 4)
|
|
493
|
+
* }
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
function quat(q1: Quaternion): Quaternion;
|
|
497
|
+
/**
|
|
498
|
+
* Creates a new quaternion with the components set
|
|
499
|
+
* according to the supplied parameter values.
|
|
500
|
+
*
|
|
501
|
+
* @param x - x coordinate
|
|
502
|
+
* @param y - y coordinate
|
|
503
|
+
* @param z - z coordinate
|
|
504
|
+
* @param w - w coordinate
|
|
505
|
+
* @returns new quaternion
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* const quat = vmath.quat(1, 2, 3, 4);
|
|
509
|
+
* print(quat); // => vmath.quat(1, 2, 3, 4)
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
function quat(x: number, y: number, z: number, w: number): Quaternion;
|
|
513
|
+
/**
|
|
514
|
+
* The resulting quaternion describes a rotation of `angle`
|
|
515
|
+
* radians around the axis described by the unit vector `v`.
|
|
516
|
+
*
|
|
517
|
+
* @param v - axis
|
|
518
|
+
* @param angle - angle
|
|
519
|
+
* @returns quaternion representing the axis-angle rotation
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* const axis = vmath.vector3(1, 0, 0);
|
|
523
|
+
* const rot = vmath.quat_axis_angle(axis, 3.141592653);
|
|
524
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
525
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(1, -1, -8.7422776573476e-08)
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
function quat_axis_angle(v: Vector3, angle: number): Quaternion;
|
|
529
|
+
/**
|
|
530
|
+
* The resulting quaternion describes the rotation from the
|
|
531
|
+
* identity quaternion (no rotation) to the coordinate system
|
|
532
|
+
* as described by the given x, y and z base unit vectors.
|
|
533
|
+
*
|
|
534
|
+
* @param x - x base vector
|
|
535
|
+
* @param y - y base vector
|
|
536
|
+
* @param z - z base vector
|
|
537
|
+
* @returns quaternion representing the rotation of the specified base vectors
|
|
538
|
+
* @example
|
|
539
|
+
* ```ts
|
|
540
|
+
* // Axis rotated 90 degrees around z.
|
|
541
|
+
* const rot_x = vmath.vector3(0, -1, 0);
|
|
542
|
+
* const rot_y = vmath.vector3(1, 0, 0);
|
|
543
|
+
* const z = vmath.vector3(0, 0, 1);
|
|
544
|
+
* const rot1 = vmath.quat_basis(rot_x, rot_y, z);
|
|
545
|
+
* const rot2 = vmath.quat_from_to(vmath.vector3(0, 1, 0), vmath.vector3(1, 0, 0));
|
|
546
|
+
* if (rot1 === rot2) {
|
|
547
|
+
* // These quaternions are equal!
|
|
548
|
+
* print(rot2); // => vmath.quat(0, 0, -0.70710676908493, 0.70710676908493)
|
|
549
|
+
* }
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
function quat_basis(x: Vector3, y: Vector3, z: Vector3): Quaternion;
|
|
553
|
+
/**
|
|
554
|
+
* The resulting quaternion describes the rotation that,
|
|
555
|
+
* if applied to the first vector, would rotate the first
|
|
556
|
+
* vector to the second. The two vectors must be unit
|
|
557
|
+
* vectors (of length 1).
|
|
558
|
+
* The result is undefined if the two vectors point in opposite directions
|
|
559
|
+
*
|
|
560
|
+
* @param v1 - first unit vector, before rotation
|
|
561
|
+
* @param v2 - second unit vector, after rotation
|
|
562
|
+
* @returns quaternion representing the rotation from first to second vector
|
|
563
|
+
* @example
|
|
564
|
+
* ```ts
|
|
565
|
+
* const v1 = vmath.vector3(1, 0, 0);
|
|
566
|
+
* const v2 = vmath.vector3(0, 1, 0);
|
|
567
|
+
* const rot = vmath.quat_from_to(v1, v2);
|
|
568
|
+
* print(vmath.rotate(rot, v1)); // => vmath.vector3(0, 0.99999994039536, 0)
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
function quat_from_to(v1: Vector3, v2: Vector3): Quaternion;
|
|
572
|
+
/**
|
|
573
|
+
* Creates a new quaternion with the components set
|
|
574
|
+
* according to the supplied parameter values.
|
|
575
|
+
*
|
|
576
|
+
* @param matrix - source matrix4
|
|
577
|
+
* @returns new quaternion
|
|
578
|
+
*/
|
|
579
|
+
function quat_matrix4(matrix: Matrix4): Quaternion;
|
|
580
|
+
/**
|
|
581
|
+
* The resulting quaternion describes a rotation of `angle`
|
|
582
|
+
* radians around the x-axis.
|
|
583
|
+
*
|
|
584
|
+
* @param angle - angle in radians around x-axis
|
|
585
|
+
* @returns quaternion representing the rotation around the x-axis
|
|
586
|
+
* @example
|
|
587
|
+
* ```ts
|
|
588
|
+
* const rot = vmath.quat_rotation_x(3.141592653);
|
|
589
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
590
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(1, -1, -8.7422776573476e-08)
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
function quat_rotation_x(angle: number): Quaternion;
|
|
594
|
+
/**
|
|
595
|
+
* The resulting quaternion describes a rotation of `angle`
|
|
596
|
+
* radians around the y-axis.
|
|
597
|
+
*
|
|
598
|
+
* @param angle - angle in radians around y-axis
|
|
599
|
+
* @returns quaternion representing the rotation around the y-axis
|
|
600
|
+
* @example
|
|
601
|
+
* ```ts
|
|
602
|
+
* const rot = vmath.quat_rotation_y(3.141592653);
|
|
603
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
604
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(-1, 1, 8.7422776573476e-08)
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
function quat_rotation_y(angle: number): Quaternion;
|
|
608
|
+
/**
|
|
609
|
+
* The resulting quaternion describes a rotation of `angle`
|
|
610
|
+
* radians around the z-axis.
|
|
611
|
+
*
|
|
612
|
+
* @param angle - angle in radians around z-axis
|
|
613
|
+
* @returns quaternion representing the rotation around the z-axis
|
|
614
|
+
* @example
|
|
615
|
+
* ```ts
|
|
616
|
+
* const rot = vmath.quat_rotation_z(3.141592653);
|
|
617
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
618
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(-0.99999988079071, -1, 0)
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
function quat_rotation_z(angle: number): Quaternion;
|
|
622
|
+
/**
|
|
623
|
+
* Converts a quaternion into euler angles (r0, r1, r2), based on YZX rotation order.
|
|
624
|
+
* To handle gimbal lock (singularity at r1 ~ +/- 90 degrees), the cut off is at r0 = +/- 88.85 degrees, which snaps to +/- 90.
|
|
625
|
+
* The provided quaternion is expected to be normalized.
|
|
626
|
+
* The error is guaranteed to be less than +/- 0.02 degrees
|
|
627
|
+
*
|
|
628
|
+
* @param q - source quaternion
|
|
629
|
+
* @example
|
|
630
|
+
* ```ts
|
|
631
|
+
* const q = vmath.quat_rotation_z(math.rad(90));
|
|
632
|
+
* print(vmath.quat_to_euler(q)); // => 0 0 90
|
|
633
|
+
*
|
|
634
|
+
* const q2 = vmath.quat_rotation_y(math.rad(45)).mul(vmath.quat_rotation_z(math.rad(90)));
|
|
635
|
+
* const [ex, ey, ez] = vmath.quat_to_euler(q2);
|
|
636
|
+
* const v = vmath.vector3(ex, ey, ez);
|
|
637
|
+
* print(v); // => vmath.vector3(0, 45, 90)
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
function quat_to_euler(q: Quaternion): LuaMultiReturn<[number, number, number]>;
|
|
641
|
+
/**
|
|
642
|
+
* Returns a new vector from the supplied vector that is
|
|
643
|
+
* rotated by the rotation described by the supplied
|
|
644
|
+
* quaternion.
|
|
645
|
+
*
|
|
646
|
+
* @param q - quaternion
|
|
647
|
+
* @param v1 - vector to rotate
|
|
648
|
+
* @returns the rotated vector
|
|
649
|
+
* @example
|
|
650
|
+
* ```ts
|
|
651
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
652
|
+
* const rot = vmath.quat_rotation_z(3.141592563);
|
|
653
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(-1.0000002384186, -0.99999988079071, 0)
|
|
654
|
+
* ```
|
|
655
|
+
*/
|
|
656
|
+
function rotate(q: Quaternion, v1: Vector3): Vector3;
|
|
657
|
+
/**
|
|
658
|
+
* Creates a vector of arbitrary size. The vector is initialized
|
|
659
|
+
* with numeric values from a table.
|
|
660
|
+
* The table values are converted to floating point
|
|
661
|
+
* values. If a value cannot be converted, a 0 is stored in that
|
|
662
|
+
* value position in the vector.
|
|
663
|
+
*
|
|
664
|
+
* @param t - table of numbers
|
|
665
|
+
* @returns new vector
|
|
666
|
+
* @example
|
|
667
|
+
* ```ts
|
|
668
|
+
* // How to create a vector with custom data to be used for animation easing:
|
|
669
|
+
* const values = [0, 0.5, 0];
|
|
670
|
+
* const vec = vmath.vector(values);
|
|
671
|
+
* print(vec); // => vmath.vector (size: 3)
|
|
672
|
+
* print(vec[2]); // => 0.5
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
function vector(t: number[]): Vector;
|
|
676
|
+
/**
|
|
677
|
+
* Creates a new zero vector with all components set to 0.
|
|
678
|
+
*
|
|
679
|
+
* @returns new zero vector
|
|
680
|
+
* @example
|
|
681
|
+
* ```ts
|
|
682
|
+
* const vec = vmath.vector3();
|
|
683
|
+
* pprint(vec); // => vmath.vector3(0, 0, 0)
|
|
684
|
+
* print(vec.x); // => 0
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
function vector3(): Vector3;
|
|
688
|
+
/**
|
|
689
|
+
* Creates a new vector with all components set to the
|
|
690
|
+
* supplied scalar value.
|
|
691
|
+
*
|
|
692
|
+
* @param n - scalar value to splat
|
|
693
|
+
* @returns new vector
|
|
694
|
+
* @example
|
|
695
|
+
* ```ts
|
|
696
|
+
* const vec = vmath.vector3(1.0);
|
|
697
|
+
* print(vec); // => vmath.vector3(1, 1, 1)
|
|
698
|
+
* print(vec.x); // => 1
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
function vector3(n: number): Vector3;
|
|
702
|
+
/**
|
|
703
|
+
* Creates a new vector with all components set to the
|
|
704
|
+
* corresponding values from the supplied vector. I.e.
|
|
705
|
+
* This function creates a copy of the given vector.
|
|
706
|
+
*
|
|
707
|
+
* @param v1 - existing vector
|
|
708
|
+
* @returns new vector
|
|
709
|
+
* @example
|
|
710
|
+
* ```ts
|
|
711
|
+
* const vec1 = vmath.vector3(1.0);
|
|
712
|
+
* const vec2 = vmath.vector3(vec1);
|
|
713
|
+
* if (vec1 === vec2) {
|
|
714
|
+
* // yes, they are equal
|
|
715
|
+
* print(vec2); // => vmath.vector3(1, 1, 1)
|
|
716
|
+
* }
|
|
717
|
+
* ```
|
|
718
|
+
*/
|
|
719
|
+
function vector3(v1: Vector3): Vector3;
|
|
720
|
+
/**
|
|
721
|
+
* Creates a new vector with the components set to the
|
|
722
|
+
* supplied values.
|
|
723
|
+
*
|
|
724
|
+
* @param x - x coordinate
|
|
725
|
+
* @param y - y coordinate
|
|
726
|
+
* @param z - z coordinate
|
|
727
|
+
* @returns new vector
|
|
728
|
+
* @example
|
|
729
|
+
* ```ts
|
|
730
|
+
* const vec = vmath.vector3(1.0, 2.0, 3.0);
|
|
731
|
+
* print(vec); // => vmath.vector3(1, 2, 3)
|
|
732
|
+
* print(vec.unm()); // => vmath.vector3(-1, -2, -3)
|
|
733
|
+
* print(vec.mul(2)); // => vmath.vector3(2, 4, 6)
|
|
734
|
+
* print(vec.add(vmath.vector3(2.0))); // => vmath.vector3(3, 4, 5)
|
|
735
|
+
* print(vec.sub(vmath.vector3(2.0))); // => vmath.vector3(-1, 0, 1)
|
|
736
|
+
* ```
|
|
737
|
+
*/
|
|
738
|
+
function vector3(x: number, y: number, z: number): Vector3;
|
|
739
|
+
/**
|
|
740
|
+
* Creates a new zero vector with all components set to 0.
|
|
741
|
+
*
|
|
742
|
+
* @returns new zero vector
|
|
743
|
+
* @example
|
|
744
|
+
* ```ts
|
|
745
|
+
* const vec = vmath.vector4();
|
|
746
|
+
* print(vec); // => vmath.vector4(0, 0, 0, 0)
|
|
747
|
+
* print(vec.w); // => 0
|
|
748
|
+
* ```
|
|
749
|
+
*/
|
|
750
|
+
function vector4(): Vector4;
|
|
751
|
+
/**
|
|
752
|
+
* Creates a new vector with all components set to the
|
|
753
|
+
* supplied scalar value.
|
|
754
|
+
*
|
|
755
|
+
* @param n - scalar value to splat
|
|
756
|
+
* @returns new vector
|
|
757
|
+
* @example
|
|
758
|
+
* ```ts
|
|
759
|
+
* const vec = vmath.vector4(1.0);
|
|
760
|
+
* print(vec); // => vmath.vector4(1, 1, 1, 1)
|
|
761
|
+
* print(vec.w); // => 1
|
|
762
|
+
* ```
|
|
763
|
+
*/
|
|
764
|
+
function vector4(n: number): Vector4;
|
|
765
|
+
/**
|
|
766
|
+
* Creates a new vector with all components set to the
|
|
767
|
+
* corresponding values from the supplied vector. I.e.
|
|
768
|
+
* This function creates a copy of the given vector.
|
|
769
|
+
*
|
|
770
|
+
* @param v1 - existing vector
|
|
771
|
+
* @returns new vector
|
|
772
|
+
* @example
|
|
773
|
+
* ```ts
|
|
774
|
+
* const vec1 = vmath.vector4(1.0);
|
|
775
|
+
* const vec2 = vmath.vector4(vec1);
|
|
776
|
+
* if (vec1 === vec2) {
|
|
777
|
+
* // yes, they are equal
|
|
778
|
+
* print(vec2); // => vmath.vector4(1, 1, 1, 1)
|
|
779
|
+
* }
|
|
780
|
+
* ```
|
|
781
|
+
*/
|
|
782
|
+
function vector4(v1: Vector4): Vector4;
|
|
783
|
+
/**
|
|
784
|
+
* Creates a new vector with the components set to the
|
|
785
|
+
* supplied values.
|
|
786
|
+
*
|
|
787
|
+
* @param x - x coordinate
|
|
788
|
+
* @param y - y coordinate
|
|
789
|
+
* @param z - z coordinate
|
|
790
|
+
* @param w - w coordinate
|
|
791
|
+
* @returns new vector
|
|
792
|
+
* @example
|
|
793
|
+
* ```ts
|
|
794
|
+
* const vec = vmath.vector4(1.0, 2.0, 3.0, 4.0);
|
|
795
|
+
* print(vec); // => vmath.vector4(1, 2, 3, 4)
|
|
796
|
+
* print(vec.unm()); // => vmath.vector4(-1, -2, -3, -4)
|
|
797
|
+
* print(vec.mul(2)); // => vmath.vector4(2, 4, 6, 8)
|
|
798
|
+
* print(vec.add(vmath.vector4(2.0))); // => vmath.vector4(3, 4, 5, 6)
|
|
799
|
+
* print(vec.sub(vmath.vector4(2.0))); // => vmath.vector4(-1, 0, 1, 2)
|
|
800
|
+
* ```
|
|
801
|
+
*/
|
|
802
|
+
function vector4(x: number, y: number, z: number, w: number): Vector4;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
export {};
|