@defold-typescript/types 0.5.4 → 0.6.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-targets.json +1 -1
- package/generated/b2d.d.ts +3 -0
- package/generated/buffer.d.ts +44 -38
- package/generated/builtin-messages.d.ts +1 -1
- package/generated/camera.d.ts +3 -0
- package/generated/collectionfactory.d.ts +47 -40
- package/generated/collectionproxy.d.ts +23 -18
- package/generated/crash.d.ts +3 -0
- package/generated/factory.d.ts +32 -24
- package/generated/go.d.ts +293 -293
- package/generated/graphics.d.ts +3 -0
- package/generated/gui.d.ts +303 -283
- package/generated/http.d.ts +26 -16
- package/generated/iac.d.ts +3 -0
- package/generated/iap.d.ts +6 -3
- package/generated/image.d.ts +30 -26
- package/generated/json.d.ts +36 -32
- package/generated/kinds/gui-script.d.ts +7 -5
- package/generated/kinds/render-script.d.ts +7 -5
- package/generated/kinds/script.d.ts +7 -5
- package/generated/label.d.ts +16 -9
- package/generated/liveupdate.d.ts +29 -26
- package/generated/model.d.ts +57 -45
- package/generated/msg.d.ts +12 -9
- package/generated/particlefx.d.ts +50 -34
- package/generated/physics.d.ts +153 -133
- package/generated/profiler.d.ts +45 -41
- package/generated/push.d.ts +5 -2
- package/generated/render.d.ts +410 -349
- package/generated/resource.d.ts +619 -572
- package/generated/socket.d.ts +49 -33
- package/generated/sound.d.ts +83 -72
- package/generated/sprite.d.ts +36 -32
- package/generated/sys.d.ts +198 -189
- package/generated/tilemap.d.ts +43 -39
- package/generated/timer.d.ts +42 -36
- package/generated/vmath.d.ts +254 -229
- package/generated/webview.d.ts +3 -0
- package/generated/window.d.ts +23 -17
- package/generated/zlib.d.ts +15 -12
- package/index.d.ts +3 -1
- package/package.json +6 -2
- package/scripts/example-store-io.ts +18 -0
- package/scripts/fidelity-audit.ts +61 -1
- package/scripts/fidelity-baseline.json +10 -10
- package/scripts/ref-doc-delta.ts +143 -0
- package/scripts/regen.ts +23 -10
- package/src/core-types.ts +14 -0
- package/src/doc-comment.ts +2 -1
- package/src/emit-dts.ts +238 -18
- package/src/engine-globals.d.ts +2 -0
- package/src/example-store.ts +44 -0
- package/src/go-overloads.d.ts +73 -0
- package/src/index.ts +5 -0
- package/src/lifecycle.ts +157 -16
- package/src/message-dispatch.d.ts +21 -0
- package/src/message-guard.d.ts +19 -0
- package/src/msg-overloads.d.ts +20 -0
- package/src/publish-dts.ts +1 -1
package/generated/vmath.d.ts
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
import type { Matrix4, Quaternion, Vector, Vector3, Vector4 } from "../src/core-types";
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
|
+
/**
|
|
6
|
+
* Functions for mathematical operations on vectors, matrices and quaternions.
|
|
7
|
+
* - The vector types (`vmath.vector3` and `vmath.vector4`) supports addition and subtraction
|
|
8
|
+
* with vectors of the same type. Vectors can be negated and multiplied (scaled) or divided by numbers.
|
|
9
|
+
* - The quaternion type (`vmath.quat`) supports multiplication with other quaternions.
|
|
10
|
+
* - The matrix type (`vmath.matrix4`) can be multiplied with numbers, other matrices
|
|
11
|
+
* and `vmath.vector4` values.
|
|
12
|
+
* - All types performs equality comparison by each component value.
|
|
13
|
+
* The following components are available for the various types:
|
|
14
|
+
* vector3
|
|
15
|
+
* : `x`, `y` and `z`. Example: `v.y`
|
|
16
|
+
* vector4
|
|
17
|
+
* : `x`, `y`, `z`, and `w`. Example: `v.w`
|
|
18
|
+
* quaternion
|
|
19
|
+
* : `x`, `y`, `z`, and `w`. Example: `q.w`
|
|
20
|
+
* matrix4
|
|
21
|
+
* : `m00` to `m33` where the first number is the row (starting from 0) and the second
|
|
22
|
+
* number is the column. Columns can be accessed with `c0` to `c3`, returning a `vector4`.
|
|
23
|
+
* Example: `m.m21` which is equal to `m.c1.z`
|
|
24
|
+
* vector
|
|
25
|
+
* : indexed by number 1 to the vector length. Example: `v[3]`
|
|
26
|
+
*/
|
|
5
27
|
namespace vmath {
|
|
6
28
|
/**
|
|
7
29
|
* Clamp input value to be in range of [min, max]. In case if input value has vector3|vector4 type
|
|
@@ -13,16 +35,16 @@ declare global {
|
|
|
13
35
|
* @param max - Max value(s) border
|
|
14
36
|
* @returns Clamped value or vector
|
|
15
37
|
* @example
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* print(vmath.clamp(value1, 89, 134))
|
|
19
|
-
*
|
|
20
|
-
* print(vmath.clamp(v2, -50, 150))
|
|
21
|
-
*
|
|
22
|
-
* print(vmath.clamp(v3, 0, 20))
|
|
38
|
+
* ```ts
|
|
39
|
+
* const value1 = 56;
|
|
40
|
+
* print(vmath.clamp(value1, 89, 134)); // => 89
|
|
41
|
+
* const v2 = vmath.vector3(190, 190, -10);
|
|
42
|
+
* print(vmath.clamp(v2, -50, 150)); // => vmath.vector3(150, 150, -10)
|
|
43
|
+
* const v3 = vmath.vector4(30, -30, 45, 1);
|
|
44
|
+
* print(vmath.clamp(v3, 0, 20)); // => vmath.vector4(20, 0, 20, 1)
|
|
23
45
|
*
|
|
24
|
-
*
|
|
25
|
-
* print(vmath.clamp(v3, min_v, 20))
|
|
46
|
+
* const min_v = vmath.vector4(0, -10, -10, 1);
|
|
47
|
+
* print(vmath.clamp(v3, min_v, 20)); // => vmath.vector4(20, -10, 20, 1)
|
|
26
48
|
* ```
|
|
27
49
|
*/
|
|
28
50
|
function clamp(value: number | Vector3 | Vector4, min: number | Vector3 | Vector4, max: number | Vector3 | Vector4): number | Vector3 | Vector4;
|
|
@@ -35,9 +57,9 @@ declare global {
|
|
|
35
57
|
* @param q1 - quaternion of which to calculate the conjugate
|
|
36
58
|
* @returns the conjugate
|
|
37
59
|
* @example
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* print(vmath.conj(quat))
|
|
60
|
+
* ```ts
|
|
61
|
+
* const quat = vmath.quat(1, 2, 3, 4);
|
|
62
|
+
* print(vmath.conj(quat)); // => vmath.quat(-1, -2, -3, 4)
|
|
41
63
|
* ```
|
|
42
64
|
*/
|
|
43
65
|
function conj(q1: Quaternion): Quaternion;
|
|
@@ -53,12 +75,12 @@ declare global {
|
|
|
53
75
|
* @param v2 - second vector
|
|
54
76
|
* @returns a new vector representing the cross product
|
|
55
77
|
* @example
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* print(vmath.cross(vec1, vec2))
|
|
60
|
-
*
|
|
61
|
-
* print(vmath.cross(vec1, vec3))
|
|
78
|
+
* ```ts
|
|
79
|
+
* const vec1 = vmath.vector3(1, 0, 0);
|
|
80
|
+
* const vec2 = vmath.vector3(0, 1, 0);
|
|
81
|
+
* print(vmath.cross(vec1, vec2)); // => vmath.vector3(0, 0, 1)
|
|
82
|
+
* const vec3 = vmath.vector3(-1, 0, 0);
|
|
83
|
+
* print(vmath.cross(vec1, vec3)); // => vmath.vector3(0, -0, 0)
|
|
62
84
|
* ```
|
|
63
85
|
*/
|
|
64
86
|
function cross(v1: Vector3, v2: Vector3): Vector3;
|
|
@@ -74,11 +96,11 @@ declare global {
|
|
|
74
96
|
* @param v2 - second vector
|
|
75
97
|
* @returns dot product
|
|
76
98
|
* @example
|
|
77
|
-
* ```
|
|
78
|
-
* if vmath.dot(vector1, vector2)
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* if (vmath.dot(vector1, vector2) === 0) {
|
|
101
|
+
* // The two vectors are perpendicular (at right-angles to each other)
|
|
102
|
+
* // ...
|
|
103
|
+
* }
|
|
82
104
|
* ```
|
|
83
105
|
*/
|
|
84
106
|
function dot(v1: Vector3 | Vector4, v2: Vector3 | Vector4): number;
|
|
@@ -92,12 +114,12 @@ declare global {
|
|
|
92
114
|
* @param z - rotation around z-axis in degrees
|
|
93
115
|
* @returns quaternion describing an equivalent rotation (231 (YZX) rotation sequence)
|
|
94
116
|
* @example
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* print(q)
|
|
117
|
+
* ```ts
|
|
118
|
+
* const q = vmath.euler_to_quat(0, 45, 90);
|
|
119
|
+
* print(q); // => vmath.quat(0.27059805393219, 0.27059805393219, 0.65328145027161, 0.65328145027161)
|
|
98
120
|
*
|
|
99
|
-
*
|
|
100
|
-
* print(vmath.euler_to_quat(v))
|
|
121
|
+
* const v = vmath.vector3(0, 0, 90);
|
|
122
|
+
* print(vmath.euler_to_quat(v)); // => vmath.quat(0, 0, 0.70710676908493, 0.70710676908493)
|
|
101
123
|
* ```
|
|
102
124
|
*/
|
|
103
125
|
function euler_to_quat(x: number | Vector3, y: number, z: number): Quaternion;
|
|
@@ -111,11 +133,11 @@ declare global {
|
|
|
111
133
|
* @param m1 - matrix to invert
|
|
112
134
|
* @returns inverse of the supplied matrix
|
|
113
135
|
* @example
|
|
114
|
-
* ```
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* print(mat1
|
|
136
|
+
* ```ts
|
|
137
|
+
* const mat1 = vmath.matrix4_rotation_z(3.141592653);
|
|
138
|
+
* const mat2 = vmath.inv(mat1);
|
|
139
|
+
* // M * inv(M) = identity matrix
|
|
140
|
+
* print(mat1.mul(mat2)); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
|
119
141
|
* ```
|
|
120
142
|
*/
|
|
121
143
|
function inv(m1: Matrix4): Matrix4;
|
|
@@ -128,14 +150,14 @@ declare global {
|
|
|
128
150
|
* @param v - value of which to calculate the length
|
|
129
151
|
* @returns length
|
|
130
152
|
* @example
|
|
131
|
-
* ```
|
|
132
|
-
* if vmath.length(self.velocity) < max_velocity
|
|
133
|
-
*
|
|
153
|
+
* ```ts
|
|
154
|
+
* if (vmath.length(self.velocity) < max_velocity) {
|
|
155
|
+
* // The speed (velocity vector) is below max.
|
|
134
156
|
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
157
|
+
* // TODO: max_velocity can be expressed as squared
|
|
158
|
+
* // so we can compare with length_sqr() instead.
|
|
159
|
+
* // ...
|
|
160
|
+
* }
|
|
139
161
|
* ```
|
|
140
162
|
*/
|
|
141
163
|
function length(v: Vector3 | Vector4 | Quaternion): number;
|
|
@@ -145,11 +167,11 @@ declare global {
|
|
|
145
167
|
* @param v - value of which to calculate the squared length
|
|
146
168
|
* @returns squared length
|
|
147
169
|
* @example
|
|
148
|
-
* ```
|
|
149
|
-
* if vmath.length_sqr(vector1) < vmath.length_sqr(vector2)
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
170
|
+
* ```ts
|
|
171
|
+
* if (vmath.length_sqr(vector1) < vmath.length_sqr(vector2)) {
|
|
172
|
+
* // Vector 1 has less magnitude than vector 2
|
|
173
|
+
* // ...
|
|
174
|
+
* }
|
|
153
175
|
* ```
|
|
154
176
|
*/
|
|
155
177
|
function length_sqr(v: Vector3 | Vector4 | Quaternion): number;
|
|
@@ -165,20 +187,22 @@ declare global {
|
|
|
165
187
|
* @param v2 - vector to lerp to
|
|
166
188
|
* @returns the lerped vector
|
|
167
189
|
* @example
|
|
168
|
-
* ```
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
190
|
+
* ```ts
|
|
191
|
+
* export default defineScript({
|
|
192
|
+
* init() {
|
|
193
|
+
* return { t: 0 };
|
|
194
|
+
* },
|
|
172
195
|
*
|
|
173
|
-
*
|
|
174
|
-
* self.t = self.t + dt
|
|
175
|
-
* if self.t <= 1
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
196
|
+
* update(self, dt) {
|
|
197
|
+
* self.t = self.t + dt;
|
|
198
|
+
* if (self.t <= 1) {
|
|
199
|
+
* const startpos = vmath.vector3(0, 600, 0);
|
|
200
|
+
* const endpos = vmath.vector3(600, 0, 0);
|
|
201
|
+
* const pos = vmath.lerp(self.t, startpos, endpos);
|
|
202
|
+
* go.set_position(pos, "go");
|
|
203
|
+
* }
|
|
204
|
+
* },
|
|
205
|
+
* });
|
|
182
206
|
* ```
|
|
183
207
|
*/
|
|
184
208
|
function lerp(t: number, v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
|
|
@@ -244,13 +268,13 @@ declare global {
|
|
|
244
268
|
*
|
|
245
269
|
* @returns identity matrix
|
|
246
270
|
* @example
|
|
247
|
-
* ```
|
|
248
|
-
*
|
|
249
|
-
* print(mat)
|
|
250
|
-
*
|
|
251
|
-
* print(mat.c0)
|
|
252
|
-
*
|
|
253
|
-
* print(mat.m32)
|
|
271
|
+
* ```ts
|
|
272
|
+
* const mat = vmath.matrix4();
|
|
273
|
+
* print(mat); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
|
274
|
+
* // get column 0:
|
|
275
|
+
* print(mat.c0); // => vmath.vector4(1, 0, 0, 0)
|
|
276
|
+
* // get the value in row 3 and column 2:
|
|
277
|
+
* print(mat.m32); // => 0
|
|
254
278
|
* ```
|
|
255
279
|
*/
|
|
256
280
|
function matrix4(): Matrix4;
|
|
@@ -279,11 +303,11 @@ declare global {
|
|
|
279
303
|
* @param angle - angle in radians
|
|
280
304
|
* @returns matrix represented by axis and angle
|
|
281
305
|
* @example
|
|
282
|
-
* ```
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* print(mat
|
|
306
|
+
* ```ts
|
|
307
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
308
|
+
* const axis = vmath.vector3(0, 0, 1); // z-axis
|
|
309
|
+
* const mat = vmath.matrix4_axis_angle(axis, 3.141592653);
|
|
310
|
+
* print(mat.mul(vec)); // => vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)
|
|
287
311
|
* ```
|
|
288
312
|
*/
|
|
289
313
|
function matrix4_axis_angle(v: Vector3, angle: number): Matrix4;
|
|
@@ -296,12 +320,12 @@ declare global {
|
|
|
296
320
|
* @param scale - scale
|
|
297
321
|
* @returns new matrix4
|
|
298
322
|
* @example
|
|
299
|
-
* ```
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* print(result)
|
|
323
|
+
* ```ts
|
|
324
|
+
* const translation = vmath.vector3(103, -95, 14);
|
|
325
|
+
* const quat = vmath.quat(1, 2, 3, 4);
|
|
326
|
+
* const scale = vmath.vector3(1, 0.5, 0.5);
|
|
327
|
+
* const result = vmath.matrix4_compose(translation, quat, scale);
|
|
328
|
+
* print(result); // => vmath.matrix4(-25, -10, 11, 103, 28, -9.5, 2, -95, -10, 10, -4.5, 14, 0, 0, 0, 1)
|
|
305
329
|
* ```
|
|
306
330
|
*/
|
|
307
331
|
function matrix4_compose(translation: Vector3 | Vector4, rotation: Quaternion, scale: Vector3): Matrix4;
|
|
@@ -319,11 +343,11 @@ declare global {
|
|
|
319
343
|
* @param far - coordinate for far clipping plane
|
|
320
344
|
* @returns matrix representing the frustum
|
|
321
345
|
* @example
|
|
322
|
-
* ```
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
* render.set_projection(proj)
|
|
346
|
+
* ```ts
|
|
347
|
+
* // Construct a projection frustum with a vertical and horizontal FOV of
|
|
348
|
+
* // 45 degrees. Useful for rendering a square view.
|
|
349
|
+
* const proj = vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000);
|
|
350
|
+
* render.set_projection(proj);
|
|
327
351
|
* ```
|
|
328
352
|
*/
|
|
329
353
|
function matrix4_frustum(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4;
|
|
@@ -337,16 +361,15 @@ declare global {
|
|
|
337
361
|
* @param up - up vector
|
|
338
362
|
* @returns look-at matrix
|
|
339
363
|
* @example
|
|
340
|
-
* ```
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* render.set_projection(proj)
|
|
364
|
+
* ```ts
|
|
365
|
+
* // Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV, aspect ratio 4:3.
|
|
366
|
+
* const eye = vmath.vector3(0, 0, 100);
|
|
367
|
+
* const look_at = vmath.vector3(0, 0, 0);
|
|
368
|
+
* const up = vmath.vector3(0, 1, 0);
|
|
369
|
+
* const view = vmath.matrix4_look_at(eye, look_at, up);
|
|
370
|
+
* render.set_view(view);
|
|
371
|
+
* const proj = vmath.matrix4_perspective(3.141592 / 2, 4 / 3, 1, 1000);
|
|
372
|
+
* render.set_projection(proj);
|
|
350
373
|
* ```
|
|
351
374
|
*/
|
|
352
375
|
function matrix4_look_at(eye: Vector3, look_at: Vector3, up: Vector3): Matrix4;
|
|
@@ -362,13 +385,13 @@ declare global {
|
|
|
362
385
|
* @param far - coordinate for far clipping plane
|
|
363
386
|
* @returns orthographic projection matrix
|
|
364
387
|
* @example
|
|
365
|
-
* ```
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* render.set_projection(proj)
|
|
388
|
+
* ```ts
|
|
389
|
+
* // Set up an orthographic projection based on the width and height of the
|
|
390
|
+
* // game window.
|
|
391
|
+
* const w = render.get_width();
|
|
392
|
+
* const h = render.get_height();
|
|
393
|
+
* const proj = vmath.matrix4_orthographic(-w / 2, w / 2, -h / 2, h / 2, -1000, 1000);
|
|
394
|
+
* render.set_projection(proj);
|
|
372
395
|
* ```
|
|
373
396
|
*/
|
|
374
397
|
function matrix4_orthographic(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4;
|
|
@@ -382,16 +405,15 @@ declare global {
|
|
|
382
405
|
* @param far - coordinate for far clipping plane
|
|
383
406
|
* @returns perspective projection matrix
|
|
384
407
|
* @example
|
|
385
|
-
* ```
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
* render.set_projection(proj)
|
|
408
|
+
* ```ts
|
|
409
|
+
* // Set up a perspective camera at z 100 with 45 degrees (pi/2) FOV, aspect ratio 4:3.
|
|
410
|
+
* const eye = vmath.vector3(0, 0, 100);
|
|
411
|
+
* const look_at = vmath.vector3(0, 0, 0);
|
|
412
|
+
* const up = vmath.vector3(0, 1, 0);
|
|
413
|
+
* const view = vmath.matrix4_look_at(eye, look_at, up);
|
|
414
|
+
* render.set_view(view);
|
|
415
|
+
* const proj = vmath.matrix4_perspective(3.141592 / 2, 4 / 3, 1, 1000);
|
|
416
|
+
* render.set_projection(proj);
|
|
395
417
|
* ```
|
|
396
418
|
*/
|
|
397
419
|
function matrix4_perspective(fov: number, aspect: number, near: number, far: number): Matrix4;
|
|
@@ -401,11 +423,11 @@ declare global {
|
|
|
401
423
|
* @param q - quaternion to create matrix from
|
|
402
424
|
* @returns matrix represented by quaternion
|
|
403
425
|
* @example
|
|
404
|
-
* ```
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* print(mat
|
|
426
|
+
* ```ts
|
|
427
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
428
|
+
* const quat = vmath.quat_rotation_z(3.141592653);
|
|
429
|
+
* const mat = vmath.matrix4_quat(quat);
|
|
430
|
+
* print(mat.mul(vec)); // => vmath.matrix4_frustum(-1, 1, -1, 1, 1, 1000)
|
|
409
431
|
* ```
|
|
410
432
|
*/
|
|
411
433
|
function matrix4_quat(q: Quaternion): Matrix4;
|
|
@@ -416,10 +438,10 @@ declare global {
|
|
|
416
438
|
* @param angle - angle in radians around x-axis
|
|
417
439
|
* @returns matrix from rotation around x-axis
|
|
418
440
|
* @example
|
|
419
|
-
* ```
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* print(mat
|
|
441
|
+
* ```ts
|
|
442
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
443
|
+
* const mat = vmath.matrix4_rotation_x(3.141592653);
|
|
444
|
+
* print(mat.mul(vec)); // => vmath.vector4(1, -1, -8.7422776573476e-08, 0)
|
|
423
445
|
* ```
|
|
424
446
|
*/
|
|
425
447
|
function matrix4_rotation_x(angle: number): Matrix4;
|
|
@@ -430,10 +452,10 @@ declare global {
|
|
|
430
452
|
* @param angle - angle in radians around y-axis
|
|
431
453
|
* @returns matrix from rotation around y-axis
|
|
432
454
|
* @example
|
|
433
|
-
* ```
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* print(mat
|
|
455
|
+
* ```ts
|
|
456
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
457
|
+
* const mat = vmath.matrix4_rotation_y(3.141592653);
|
|
458
|
+
* print(mat.mul(vec)); // => vmath.vector4(-1, 1, 8.7422776573476e-08, 0)
|
|
437
459
|
* ```
|
|
438
460
|
*/
|
|
439
461
|
function matrix4_rotation_y(angle: number): Matrix4;
|
|
@@ -444,10 +466,10 @@ declare global {
|
|
|
444
466
|
* @param angle - angle in radians around z-axis
|
|
445
467
|
* @returns matrix from rotation around z-axis
|
|
446
468
|
* @example
|
|
447
|
-
* ```
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
* print(mat
|
|
469
|
+
* ```ts
|
|
470
|
+
* const vec = vmath.vector4(1, 1, 0, 0);
|
|
471
|
+
* const mat = vmath.matrix4_rotation_z(3.141592653);
|
|
472
|
+
* print(mat.mul(vec)); // => vmath.vector4(-0.99999994039536, -1.0000001192093, 0, 0)
|
|
451
473
|
* ```
|
|
452
474
|
*/
|
|
453
475
|
function matrix4_rotation_z(angle: number): Matrix4;
|
|
@@ -457,10 +479,10 @@ declare global {
|
|
|
457
479
|
* @param scale - scale
|
|
458
480
|
* @returns new matrix4
|
|
459
481
|
* @example
|
|
460
|
-
* ```
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
* print(result)
|
|
482
|
+
* ```ts
|
|
483
|
+
* const scale = vmath.vector3(1, 0.5, 0.5);
|
|
484
|
+
* const result = vmath.matrix4_scale(scale);
|
|
485
|
+
* print(result); // => vmath.matrix4(1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1)
|
|
464
486
|
* ```
|
|
465
487
|
*/
|
|
466
488
|
function matrix4_scale(scale: Vector3): Matrix4;
|
|
@@ -497,11 +519,11 @@ declare global {
|
|
|
497
519
|
* @param position - position vector to create matrix from
|
|
498
520
|
* @returns matrix from the supplied position vector
|
|
499
521
|
* @example
|
|
500
|
-
* ```
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
* render.set_view(mat_view
|
|
522
|
+
* ```ts
|
|
523
|
+
* // Set camera view from custom view and translation matrices.
|
|
524
|
+
* const mat_trans = vmath.matrix4_translation(vmath.vector3(0, 10, 100));
|
|
525
|
+
* const mat_view = vmath.matrix4_rotation_y(-3.141592 / 4);
|
|
526
|
+
* render.set_view(mat_view.mul(mat_trans));
|
|
505
527
|
* ```
|
|
506
528
|
*/
|
|
507
529
|
function matrix4_translation(position: Vector3 | Vector4): Matrix4;
|
|
@@ -514,8 +536,8 @@ declare global {
|
|
|
514
536
|
* @param v2 - second vector
|
|
515
537
|
* @returns multiplied vector
|
|
516
538
|
* @example
|
|
517
|
-
* ```
|
|
518
|
-
*
|
|
539
|
+
* ```ts
|
|
540
|
+
* const blend_color = vmath.mul_per_elem(color1, color2);
|
|
519
541
|
* ```
|
|
520
542
|
*/
|
|
521
543
|
function mul_per_elem(v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
|
|
@@ -528,11 +550,11 @@ declare global {
|
|
|
528
550
|
* @param v1 - vector to normalize
|
|
529
551
|
* @returns new normalized vector
|
|
530
552
|
* @example
|
|
531
|
-
* ```
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
* print(norm_vec)
|
|
535
|
-
* print(vmath.length(norm_vec))
|
|
553
|
+
* ```ts
|
|
554
|
+
* const vec = vmath.vector3(1, 2, 3);
|
|
555
|
+
* const norm_vec = vmath.normalize(vec);
|
|
556
|
+
* print(norm_vec); // => vmath.vector3(0.26726123690605, 0.5345224738121, 0.80178368091583)
|
|
557
|
+
* print(vmath.length(norm_vec)); // => 0.99999994039536
|
|
536
558
|
* ```
|
|
537
559
|
*/
|
|
538
560
|
function normalize(v1: Vector3 | Vector4 | Quaternion): Vector3 | Vector4 | Quaternion;
|
|
@@ -546,11 +568,11 @@ declare global {
|
|
|
546
568
|
* @param m1 - ortho-normalized matrix to invert
|
|
547
569
|
* @returns inverse of the supplied matrix
|
|
548
570
|
* @example
|
|
549
|
-
* ```
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
* print(mat1
|
|
571
|
+
* ```ts
|
|
572
|
+
* const mat1 = vmath.matrix4_rotation_z(3.141592653);
|
|
573
|
+
* const mat2 = vmath.ortho_inv(mat1);
|
|
574
|
+
* // M * inv(M) = identity matrix
|
|
575
|
+
* print(mat1.mul(mat2)); // => vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
|
|
554
576
|
* ```
|
|
555
577
|
*/
|
|
556
578
|
function ortho_inv(m1: Matrix4): Matrix4;
|
|
@@ -564,10 +586,10 @@ declare global {
|
|
|
564
586
|
* @param v2 - vector onto which the first will be projected, must not have zero length
|
|
565
587
|
* @returns the projected extent of the first vector onto the second
|
|
566
588
|
* @example
|
|
567
|
-
* ```
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
* print(vmath.project(v1, v2))
|
|
589
|
+
* ```ts
|
|
590
|
+
* const v1 = vmath.vector3(1, 1, 0);
|
|
591
|
+
* const v2 = vmath.vector3(2, 0, 0);
|
|
592
|
+
* print(vmath.project(v1, v2)); // => 0.5
|
|
571
593
|
* ```
|
|
572
594
|
*/
|
|
573
595
|
function project(v1: Vector3, v2: Vector3): number;
|
|
@@ -613,9 +635,9 @@ declare global {
|
|
|
613
635
|
* @param w - w coordinate
|
|
614
636
|
* @returns new quaternion
|
|
615
637
|
* @example
|
|
616
|
-
* ```
|
|
617
|
-
*
|
|
618
|
-
* print(quat)
|
|
638
|
+
* ```ts
|
|
639
|
+
* const quat = vmath.quat(1, 2, 3, 4);
|
|
640
|
+
* print(quat); // => vmath.quat(1, 2, 3, 4)
|
|
619
641
|
* ```
|
|
620
642
|
*/
|
|
621
643
|
function quat(x: number, y: number, z: number, w: number): Quaternion;
|
|
@@ -627,11 +649,11 @@ declare global {
|
|
|
627
649
|
* @param angle - angle
|
|
628
650
|
* @returns quaternion representing the axis-angle rotation
|
|
629
651
|
* @example
|
|
630
|
-
* ```
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
* print(vmath.rotate(rot, vec))
|
|
652
|
+
* ```ts
|
|
653
|
+
* const axis = vmath.vector3(1, 0, 0);
|
|
654
|
+
* const rot = vmath.quat_axis_angle(axis, 3.141592653);
|
|
655
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
656
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(1, -1, -8.7422776573476e-08)
|
|
635
657
|
* ```
|
|
636
658
|
*/
|
|
637
659
|
function quat_axis_angle(v: Vector3, angle: number): Quaternion;
|
|
@@ -645,17 +667,17 @@ declare global {
|
|
|
645
667
|
* @param z - z base vector
|
|
646
668
|
* @returns quaternion representing the rotation of the specified base vectors
|
|
647
669
|
* @example
|
|
648
|
-
* ```
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
* if rot1
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
670
|
+
* ```ts
|
|
671
|
+
* // Axis rotated 90 degrees around z.
|
|
672
|
+
* const rot_x = vmath.vector3(0, -1, 0);
|
|
673
|
+
* const rot_y = vmath.vector3(1, 0, 0);
|
|
674
|
+
* const z = vmath.vector3(0, 0, 1);
|
|
675
|
+
* const rot1 = vmath.quat_basis(rot_x, rot_y, z);
|
|
676
|
+
* const rot2 = vmath.quat_from_to(vmath.vector3(0, 1, 0), vmath.vector3(1, 0, 0));
|
|
677
|
+
* if (rot1 === rot2) {
|
|
678
|
+
* // These quaternions are equal!
|
|
679
|
+
* print(rot2); // => vmath.quat(0, 0, -0.70710676908493, 0.70710676908493)
|
|
680
|
+
* }
|
|
659
681
|
* ```
|
|
660
682
|
*/
|
|
661
683
|
function quat_basis(x: Vector3, y: Vector3, z: Vector3): Quaternion;
|
|
@@ -670,11 +692,11 @@ declare global {
|
|
|
670
692
|
* @param v2 - second unit vector, after rotation
|
|
671
693
|
* @returns quaternion representing the rotation from first to second vector
|
|
672
694
|
* @example
|
|
673
|
-
* ```
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
* print(vmath.rotate(rot, v1))
|
|
695
|
+
* ```ts
|
|
696
|
+
* const v1 = vmath.vector3(1, 0, 0);
|
|
697
|
+
* const v2 = vmath.vector3(0, 1, 0);
|
|
698
|
+
* const rot = vmath.quat_from_to(v1, v2);
|
|
699
|
+
* print(vmath.rotate(rot, v1)); // => vmath.vector3(0, 0.99999994039536, 0)
|
|
678
700
|
* ```
|
|
679
701
|
*/
|
|
680
702
|
function quat_from_to(v1: Vector3, v2: Vector3): Quaternion;
|
|
@@ -693,10 +715,10 @@ declare global {
|
|
|
693
715
|
* @param angle - angle in radians around x-axis
|
|
694
716
|
* @returns quaternion representing the rotation around the x-axis
|
|
695
717
|
* @example
|
|
696
|
-
* ```
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
* print(vmath.rotate(rot, vec))
|
|
718
|
+
* ```ts
|
|
719
|
+
* const rot = vmath.quat_rotation_x(3.141592653);
|
|
720
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
721
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(1, -1, -8.7422776573476e-08)
|
|
700
722
|
* ```
|
|
701
723
|
*/
|
|
702
724
|
function quat_rotation_x(angle: number): Quaternion;
|
|
@@ -707,10 +729,10 @@ declare global {
|
|
|
707
729
|
* @param angle - angle in radians around y-axis
|
|
708
730
|
* @returns quaternion representing the rotation around the y-axis
|
|
709
731
|
* @example
|
|
710
|
-
* ```
|
|
711
|
-
*
|
|
712
|
-
*
|
|
713
|
-
* print(vmath.rotate(rot, vec))
|
|
732
|
+
* ```ts
|
|
733
|
+
* const rot = vmath.quat_rotation_y(3.141592653);
|
|
734
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
735
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(-1, 1, 8.7422776573476e-08)
|
|
714
736
|
* ```
|
|
715
737
|
*/
|
|
716
738
|
function quat_rotation_y(angle: number): Quaternion;
|
|
@@ -721,10 +743,10 @@ declare global {
|
|
|
721
743
|
* @param angle - angle in radians around z-axis
|
|
722
744
|
* @returns quaternion representing the rotation around the z-axis
|
|
723
745
|
* @example
|
|
724
|
-
* ```
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
* print(vmath.rotate(rot, vec))
|
|
746
|
+
* ```ts
|
|
747
|
+
* const rot = vmath.quat_rotation_z(3.141592653);
|
|
748
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
749
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(-0.99999988079071, -1, 0)
|
|
728
750
|
* ```
|
|
729
751
|
*/
|
|
730
752
|
function quat_rotation_z(angle: number): Quaternion;
|
|
@@ -736,13 +758,14 @@ declare global {
|
|
|
736
758
|
*
|
|
737
759
|
* @param q - source quaternion
|
|
738
760
|
* @example
|
|
739
|
-
* ```
|
|
740
|
-
*
|
|
741
|
-
* print(vmath.quat_to_euler(q))
|
|
761
|
+
* ```ts
|
|
762
|
+
* const q = vmath.quat_rotation_z(math.rad(90));
|
|
763
|
+
* print(vmath.quat_to_euler(q)); // => 0 0 90
|
|
742
764
|
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
765
|
+
* const q2 = vmath.quat_rotation_y(math.rad(45)).mul(vmath.quat_rotation_z(math.rad(90)));
|
|
766
|
+
* const [ex, ey, ez] = vmath.quat_to_euler(q2);
|
|
767
|
+
* const v = vmath.vector3(ex, ey, ez);
|
|
768
|
+
* print(v); // => vmath.vector3(0, 45, 90)
|
|
746
769
|
* ```
|
|
747
770
|
*/
|
|
748
771
|
function quat_to_euler(q: Quaternion): LuaMultiReturn<[number, number, number]>;
|
|
@@ -755,10 +778,10 @@ declare global {
|
|
|
755
778
|
* @param v1 - vector to rotate
|
|
756
779
|
* @returns the rotated vector
|
|
757
780
|
* @example
|
|
758
|
-
* ```
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
* print(vmath.rotate(rot, vec))
|
|
781
|
+
* ```ts
|
|
782
|
+
* const vec = vmath.vector3(1, 1, 0);
|
|
783
|
+
* const rot = vmath.quat_rotation_z(3.141592563);
|
|
784
|
+
* print(vmath.rotate(rot, vec)); // => vmath.vector3(-1.0000002384186, -0.99999988079071, 0)
|
|
762
785
|
* ```
|
|
763
786
|
*/
|
|
764
787
|
function rotate(q: Quaternion, v1: Vector3): Vector3;
|
|
@@ -777,20 +800,22 @@ declare global {
|
|
|
777
800
|
* @param v2 - vector to slerp to
|
|
778
801
|
* @returns the slerped vector
|
|
779
802
|
* @example
|
|
780
|
-
* ```
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
803
|
+
* ```ts
|
|
804
|
+
* export default defineScript({
|
|
805
|
+
* init() {
|
|
806
|
+
* return { t: 0 };
|
|
807
|
+
* },
|
|
784
808
|
*
|
|
785
|
-
*
|
|
786
|
-
* self.t = self.t + dt
|
|
787
|
-
* if self.t <= 1
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
*
|
|
809
|
+
* update(self, dt) {
|
|
810
|
+
* self.t = self.t + dt;
|
|
811
|
+
* if (self.t <= 1) {
|
|
812
|
+
* const startpos = vmath.vector3(0, 600, 0);
|
|
813
|
+
* const endpos = vmath.vector3(600, 0, 0);
|
|
814
|
+
* const pos = vmath.slerp(self.t, startpos, endpos);
|
|
815
|
+
* go.set_position(pos, "go");
|
|
816
|
+
* }
|
|
817
|
+
* },
|
|
818
|
+
* });
|
|
794
819
|
* ```
|
|
795
820
|
*/
|
|
796
821
|
function slerp(t: number, v1: Vector3 | Vector4, v2: Vector3 | Vector4): Vector3 | Vector4;
|
|
@@ -835,12 +860,12 @@ declare global {
|
|
|
835
860
|
* @param t - table of numbers
|
|
836
861
|
* @returns new vector
|
|
837
862
|
* @example
|
|
838
|
-
* ```
|
|
839
|
-
* How to create a vector with custom data to be used for animation easing:
|
|
840
|
-
*
|
|
841
|
-
*
|
|
842
|
-
* print(vec)
|
|
843
|
-
* print(vec[2])
|
|
863
|
+
* ```ts
|
|
864
|
+
* // How to create a vector with custom data to be used for animation easing:
|
|
865
|
+
* const values = [0, 0.5, 0];
|
|
866
|
+
* const vec = vmath.vector(values);
|
|
867
|
+
* print(vec); // => vmath.vector (size: 3)
|
|
868
|
+
* print(vec[2]); // => 0.5
|
|
844
869
|
* ```
|
|
845
870
|
*/
|
|
846
871
|
function vector(t: number[]): Vector;
|
|
@@ -897,13 +922,13 @@ declare global {
|
|
|
897
922
|
* @param z - z coordinate
|
|
898
923
|
* @returns new vector
|
|
899
924
|
* @example
|
|
900
|
-
* ```
|
|
901
|
-
*
|
|
902
|
-
* print(vec)
|
|
903
|
-
* print(
|
|
904
|
-
* print(vec
|
|
905
|
-
* print(vec
|
|
906
|
-
* print(vec
|
|
925
|
+
* ```ts
|
|
926
|
+
* const vec = vmath.vector3(1.0, 2.0, 3.0);
|
|
927
|
+
* print(vec); // => vmath.vector3(1, 2, 3)
|
|
928
|
+
* print(vec.unm()); // => vmath.vector3(-1, -2, -3)
|
|
929
|
+
* print(vec.mul(2)); // => vmath.vector3(2, 4, 6)
|
|
930
|
+
* print(vec.add(vmath.vector3(2.0))); // => vmath.vector3(3, 4, 5)
|
|
931
|
+
* print(vec.sub(vmath.vector3(2.0))); // => vmath.vector3(-1, 0, 1)
|
|
907
932
|
* ```
|
|
908
933
|
*/
|
|
909
934
|
function vector3(x: number, y: number, z: number): Vector3;
|
|
@@ -961,13 +986,13 @@ declare global {
|
|
|
961
986
|
* @param w - w coordinate
|
|
962
987
|
* @returns new vector
|
|
963
988
|
* @example
|
|
964
|
-
* ```
|
|
965
|
-
*
|
|
966
|
-
* print(vec)
|
|
967
|
-
* print(
|
|
968
|
-
* print(vec
|
|
969
|
-
* print(vec
|
|
970
|
-
* print(vec
|
|
989
|
+
* ```ts
|
|
990
|
+
* const vec = vmath.vector4(1.0, 2.0, 3.0, 4.0);
|
|
991
|
+
* print(vec); // => vmath.vector4(1, 2, 3, 4)
|
|
992
|
+
* print(vec.unm()); // => vmath.vector4(-1, -2, -3, -4)
|
|
993
|
+
* print(vec.mul(2)); // => vmath.vector4(2, 4, 6, 8)
|
|
994
|
+
* print(vec.add(vmath.vector4(2.0))); // => vmath.vector4(3, 4, 5, 6)
|
|
995
|
+
* print(vec.sub(vmath.vector4(2.0))); // => vmath.vector4(-1, 0, 1, 2)
|
|
971
996
|
* ```
|
|
972
997
|
*/
|
|
973
998
|
function vector4(x: number, y: number, z: number, w: number): Vector4;
|