lecodes-cli 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +300 -149
- package/package.json +5 -3
- package/runtime/sdk/animate/animate.ts +238 -0
- package/runtime/sdk/animate/bezier.ts +138 -0
- package/runtime/sdk/animate/easings.ts +126 -0
- package/runtime/sdk/core/color.ts +66 -0
- package/runtime/sdk/core/events.ts +38 -0
- package/runtime/sdk/core/registry.ts +23 -0
- package/runtime/sdk/g2/Camera2D.ts +73 -0
- package/runtime/sdk/g2/Node2D.ts +104 -0
- package/runtime/sdk/g2/Scene2D.ts +73 -0
- package/runtime/sdk/g2/Sprite.ts +164 -0
- package/runtime/sdk/g2/Texture2D.ts +37 -0
- package/runtime/sdk/g2/Tilemap.ts +41 -0
- package/runtime/sdk/g2/loop.ts +22 -0
- package/runtime/sdk/gl/Body.ts +101 -0
- package/runtime/sdk/gl/Camera.ts +40 -0
- package/runtime/sdk/gl/Geometry.ts +218 -0
- package/runtime/sdk/gl/Light.ts +37 -0
- package/runtime/sdk/gl/Material.ts +124 -0
- package/runtime/sdk/gl/Mesh.ts +123 -0
- package/runtime/sdk/gl/Node.ts +307 -0
- package/runtime/sdk/gl/Noise.ts +30 -0
- package/runtime/sdk/gl/Particles.ts +185 -0
- package/runtime/sdk/gl/Plane.ts +53 -0
- package/runtime/sdk/gl/Ray.ts +16 -0
- package/runtime/sdk/gl/Scene.ts +179 -0
- package/runtime/sdk/gl/Texture.ts +35 -0
- package/runtime/sdk/gl/controls.ts +95 -0
- package/runtime/sdk/gl/state.ts +6 -0
- package/runtime/sdk/gl/touch.ts +56 -0
- package/runtime/sdk/inject.ts +72 -0
- package/runtime/sdk/math/Mathf.ts +118 -0
- package/runtime/sdk/math/mat4.ts +278 -0
- package/runtime/sdk/math/quat.ts +232 -0
- package/runtime/sdk/math/vec.ts +255 -0
- package/runtime/sdk/plugins/qr.ts +36 -0
- package/runtime/sdk/runtime/device.ts +33 -0
- package/runtime/sdk/runtime/fetch.ts +71 -0
- package/runtime/sdk/runtime/files.ts +23 -0
- package/runtime/sdk/runtime/input.ts +12 -0
- package/runtime/sdk/runtime/media.ts +111 -0
- package/runtime/sdk/runtime/misc.ts +12 -0
- package/runtime/sdk/runtime/net.ts +36 -0
- package/runtime/sdk/runtime/storage.ts +13 -0
- package/runtime/sdk/runtime/touch.ts +44 -0
- package/runtime/sdk/ui/UI.ts +19 -0
- package/runtime/sdk/ui/UIButton.ts +84 -0
- package/runtime/sdk/ui/UIContainer.ts +100 -0
- package/runtime/sdk/ui/UIImage.ts +68 -0
- package/runtime/sdk/ui/UIInput.ts +78 -0
- package/runtime/sdk/ui/UINode.ts +342 -0
- package/runtime/sdk/ui/UIScreen.ts +122 -0
- package/runtime/sdk/ui/UIScrollable.ts +70 -0
- package/runtime/sdk/ui/UISpacer.ts +14 -0
- package/runtime/sdk/ui/UIText.ts +40 -0
- package/runtime/sdk/ui/UIVideo.ts +38 -0
- package/runtime/sdk/ui/UIVirtualizedList.ts +222 -0
- package/runtime/sdk/ui/UIWidget.ts +97 -0
- package/runtime/sdk/ui/fonts.ts +10 -0
- package/runtime/sdk/ui/router.ts +73 -0
- package/runtime/gl-matrix/common.js +0 -54
- package/runtime/gl-matrix/header.js +0 -12
- package/runtime/gl-matrix/index.js +0 -11
- package/runtime/gl-matrix/mat2.js +0 -425
- package/runtime/gl-matrix/mat2d.js +0 -476
- package/runtime/gl-matrix/mat3.js +0 -765
- package/runtime/gl-matrix/mat4.js +0 -1947
- package/runtime/gl-matrix/quat.js +0 -737
- package/runtime/gl-matrix/quat2.js +0 -822
- package/runtime/gl-matrix/vec2.js +0 -620
- package/runtime/gl-matrix/vec3.js +0 -791
- package/runtime/gl-matrix/vec4.js +0 -652
- package/runtime/worker/animate.js +0 -304
- package/runtime/worker/chunk-4ZN32GYS.js +0 -34
- package/runtime/worker/chunk-G5ZA3LKB.js +0 -52
- package/runtime/worker/chunk-MI3UXE5H.js +0 -1395
- package/runtime/worker/creator.js +0 -930
- package/runtime/worker/globals.js +0 -208
- package/runtime/worker/ui.js +0 -763
- package/runtime/worker/utils.js +0 -16
|
@@ -1,737 +0,0 @@
|
|
|
1
|
-
import * as glMatrix from "./common.js";
|
|
2
|
-
import * as mat3 from "./mat3.js";
|
|
3
|
-
import * as vec3 from "./vec3.js";
|
|
4
|
-
import * as vec4 from "./vec4.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Quaternion in the format XYZW
|
|
8
|
-
* @module quat
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new identity quat
|
|
13
|
-
*
|
|
14
|
-
* @returns {quat} a new quaternion
|
|
15
|
-
*/
|
|
16
|
-
export function create() {
|
|
17
|
-
var out = new Float32Array(4);
|
|
18
|
-
out[3] = 1;
|
|
19
|
-
return out;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Set a quat to the identity quaternion
|
|
24
|
-
*
|
|
25
|
-
* @param {quat} out the receiving quaternion
|
|
26
|
-
* @returns {quat} out
|
|
27
|
-
*/
|
|
28
|
-
export function identity(out) {
|
|
29
|
-
out[0] = 0;
|
|
30
|
-
out[1] = 0;
|
|
31
|
-
out[2] = 0;
|
|
32
|
-
out[3] = 1;
|
|
33
|
-
return out;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Sets a quat from the given angle and rotation axis,
|
|
38
|
-
* then returns it.
|
|
39
|
-
*
|
|
40
|
-
* @param {quat} out the receiving quaternion
|
|
41
|
-
* @param {ReadonlyVec3} axis the axis around which to rotate
|
|
42
|
-
* @param {Number} rad the angle in radians
|
|
43
|
-
* @returns {quat} out
|
|
44
|
-
**/
|
|
45
|
-
export function setAxisAngle(out, axis, rad) {
|
|
46
|
-
rad = rad * 0.5;
|
|
47
|
-
var s = Math.sin(rad);
|
|
48
|
-
out[0] = s * axis[0];
|
|
49
|
-
out[1] = s * axis[1];
|
|
50
|
-
out[2] = s * axis[2];
|
|
51
|
-
out[3] = Math.cos(rad);
|
|
52
|
-
return out;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Gets the rotation axis and angle for a given
|
|
57
|
-
* quaternion. If a quaternion is created with
|
|
58
|
-
* setAxisAngle, this method will return the same
|
|
59
|
-
* values as providied in the original parameter list
|
|
60
|
-
* OR functionally equivalent values.
|
|
61
|
-
* Example: The quaternion formed by axis [0, 0, 1] and
|
|
62
|
-
* angle -90 is the same as the quaternion formed by
|
|
63
|
-
* [0, 0, 1] and 270. This method favors the latter.
|
|
64
|
-
* @param {vec3} out_axis Vector receiving the axis of rotation
|
|
65
|
-
* @param {ReadonlyQuat} q Quaternion to be decomposed
|
|
66
|
-
* @return {Number} Angle, in radians, of the rotation
|
|
67
|
-
*/
|
|
68
|
-
export function getAxisAngle(out_axis, q) {
|
|
69
|
-
var rad = Math.acos(q[3]) * 2.0;
|
|
70
|
-
var s = Math.sin(rad / 2.0);
|
|
71
|
-
if (s > glMatrix.EPSILON) {
|
|
72
|
-
out_axis[0] = q[0] / s;
|
|
73
|
-
out_axis[1] = q[1] / s;
|
|
74
|
-
out_axis[2] = q[2] / s;
|
|
75
|
-
} else {
|
|
76
|
-
// If s is zero, return any axis (no rotation - axis does not matter)
|
|
77
|
-
out_axis[0] = 1;
|
|
78
|
-
out_axis[1] = 0;
|
|
79
|
-
out_axis[2] = 0;
|
|
80
|
-
}
|
|
81
|
-
return rad;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Gets the angular distance between two unit quaternions
|
|
86
|
-
*
|
|
87
|
-
* @param {ReadonlyQuat} a Origin unit quaternion
|
|
88
|
-
* @param {ReadonlyQuat} b Destination unit quaternion
|
|
89
|
-
* @return {Number} Angle, in radians, between the two quaternions
|
|
90
|
-
*/
|
|
91
|
-
export function getAngle(a, b) {
|
|
92
|
-
var dotproduct = dot(a, b);
|
|
93
|
-
return Math.acos(2 * dotproduct * dotproduct - 1);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Multiplies two quat's
|
|
98
|
-
*
|
|
99
|
-
* @param {quat} out the receiving quaternion
|
|
100
|
-
* @param {ReadonlyQuat} a the first operand
|
|
101
|
-
* @param {ReadonlyQuat} b the second operand
|
|
102
|
-
* @returns {quat} out
|
|
103
|
-
*/
|
|
104
|
-
export function multiply(out, a, b) {
|
|
105
|
-
var ax = a[0],
|
|
106
|
-
ay = a[1],
|
|
107
|
-
az = a[2],
|
|
108
|
-
aw = a[3];
|
|
109
|
-
var bx = b[0],
|
|
110
|
-
by = b[1],
|
|
111
|
-
bz = b[2],
|
|
112
|
-
bw = b[3];
|
|
113
|
-
out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
|
114
|
-
out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
|
115
|
-
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
|
116
|
-
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
|
117
|
-
return out;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Rotates a quaternion by the given angle about the X axis
|
|
122
|
-
*
|
|
123
|
-
* @param {quat} out quat receiving operation result
|
|
124
|
-
* @param {ReadonlyQuat} a quat to rotate
|
|
125
|
-
* @param {number} rad angle (in radians) to rotate
|
|
126
|
-
* @returns {quat} out
|
|
127
|
-
*/
|
|
128
|
-
export function rotateX(out, a, rad) {
|
|
129
|
-
rad *= 0.5;
|
|
130
|
-
var ax = a[0],
|
|
131
|
-
ay = a[1],
|
|
132
|
-
az = a[2],
|
|
133
|
-
aw = a[3];
|
|
134
|
-
var bx = Math.sin(rad),
|
|
135
|
-
bw = Math.cos(rad);
|
|
136
|
-
out[0] = ax * bw + aw * bx;
|
|
137
|
-
out[1] = ay * bw + az * bx;
|
|
138
|
-
out[2] = az * bw - ay * bx;
|
|
139
|
-
out[3] = aw * bw - ax * bx;
|
|
140
|
-
return out;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Rotates a quaternion by the given angle about the Y axis
|
|
145
|
-
*
|
|
146
|
-
* @param {quat} out quat receiving operation result
|
|
147
|
-
* @param {ReadonlyQuat} a quat to rotate
|
|
148
|
-
* @param {number} rad angle (in radians) to rotate
|
|
149
|
-
* @returns {quat} out
|
|
150
|
-
*/
|
|
151
|
-
export function rotateY(out, a, rad) {
|
|
152
|
-
rad *= 0.5;
|
|
153
|
-
var ax = a[0],
|
|
154
|
-
ay = a[1],
|
|
155
|
-
az = a[2],
|
|
156
|
-
aw = a[3];
|
|
157
|
-
var by = Math.sin(rad),
|
|
158
|
-
bw = Math.cos(rad);
|
|
159
|
-
out[0] = ax * bw - az * by;
|
|
160
|
-
out[1] = ay * bw + aw * by;
|
|
161
|
-
out[2] = az * bw + ax * by;
|
|
162
|
-
out[3] = aw * bw - ay * by;
|
|
163
|
-
return out;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Rotates a quaternion by the given angle about the Z axis
|
|
168
|
-
*
|
|
169
|
-
* @param {quat} out quat receiving operation result
|
|
170
|
-
* @param {ReadonlyQuat} a quat to rotate
|
|
171
|
-
* @param {number} rad angle (in radians) to rotate
|
|
172
|
-
* @returns {quat} out
|
|
173
|
-
*/
|
|
174
|
-
export function rotateZ(out, a, rad) {
|
|
175
|
-
rad *= 0.5;
|
|
176
|
-
var ax = a[0],
|
|
177
|
-
ay = a[1],
|
|
178
|
-
az = a[2],
|
|
179
|
-
aw = a[3];
|
|
180
|
-
var bz = Math.sin(rad),
|
|
181
|
-
bw = Math.cos(rad);
|
|
182
|
-
out[0] = ax * bw + ay * bz;
|
|
183
|
-
out[1] = ay * bw - ax * bz;
|
|
184
|
-
out[2] = az * bw + aw * bz;
|
|
185
|
-
out[3] = aw * bw - az * bz;
|
|
186
|
-
return out;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Calculates the W component of a quat from the X, Y, and Z components.
|
|
191
|
-
* Assumes that quaternion is 1 unit in length.
|
|
192
|
-
* Any existing W component will be ignored.
|
|
193
|
-
*
|
|
194
|
-
* @param {quat} out the receiving quaternion
|
|
195
|
-
* @param {ReadonlyQuat} a quat to calculate W component of
|
|
196
|
-
* @returns {quat} out
|
|
197
|
-
*/
|
|
198
|
-
export function calculateW(out, a) {
|
|
199
|
-
var x = a[0],
|
|
200
|
-
y = a[1],
|
|
201
|
-
z = a[2];
|
|
202
|
-
out[0] = x;
|
|
203
|
-
out[1] = y;
|
|
204
|
-
out[2] = z;
|
|
205
|
-
out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
|
|
206
|
-
return out;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Calculate the exponential of a unit quaternion.
|
|
211
|
-
*
|
|
212
|
-
* @param {quat} out the receiving quaternion
|
|
213
|
-
* @param {ReadonlyQuat} a quat to calculate the exponential of
|
|
214
|
-
* @returns {quat} out
|
|
215
|
-
*/
|
|
216
|
-
export function exp(out, a) {
|
|
217
|
-
var x = a[0],
|
|
218
|
-
y = a[1],
|
|
219
|
-
z = a[2],
|
|
220
|
-
w = a[3];
|
|
221
|
-
var r = Math.sqrt(x * x + y * y + z * z);
|
|
222
|
-
var et = Math.exp(w);
|
|
223
|
-
var s = r > 0 ? et * Math.sin(r) / r : 0;
|
|
224
|
-
out[0] = x * s;
|
|
225
|
-
out[1] = y * s;
|
|
226
|
-
out[2] = z * s;
|
|
227
|
-
out[3] = et * Math.cos(r);
|
|
228
|
-
return out;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Calculate the natural logarithm of a unit quaternion.
|
|
233
|
-
*
|
|
234
|
-
* @param {quat} out the receiving quaternion
|
|
235
|
-
* @param {ReadonlyQuat} a quat to calculate the exponential of
|
|
236
|
-
* @returns {quat} out
|
|
237
|
-
*/
|
|
238
|
-
export function ln(out, a) {
|
|
239
|
-
var x = a[0],
|
|
240
|
-
y = a[1],
|
|
241
|
-
z = a[2],
|
|
242
|
-
w = a[3];
|
|
243
|
-
var r = Math.sqrt(x * x + y * y + z * z);
|
|
244
|
-
var t = r > 0 ? Math.atan2(r, w) / r : 0;
|
|
245
|
-
out[0] = x * t;
|
|
246
|
-
out[1] = y * t;
|
|
247
|
-
out[2] = z * t;
|
|
248
|
-
out[3] = 0.5 * Math.log(x * x + y * y + z * z + w * w);
|
|
249
|
-
return out;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Calculate the scalar power of a unit quaternion.
|
|
254
|
-
*
|
|
255
|
-
* @param {quat} out the receiving quaternion
|
|
256
|
-
* @param {ReadonlyQuat} a quat to calculate the exponential of
|
|
257
|
-
* @param {Number} b amount to scale the quaternion by
|
|
258
|
-
* @returns {quat} out
|
|
259
|
-
*/
|
|
260
|
-
export function pow(out, a, b) {
|
|
261
|
-
ln(out, a);
|
|
262
|
-
scale(out, out, b);
|
|
263
|
-
exp(out, out);
|
|
264
|
-
return out;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Performs a spherical linear interpolation between two quat
|
|
269
|
-
*
|
|
270
|
-
* @param {quat} out the receiving quaternion
|
|
271
|
-
* @param {ReadonlyQuat} a the first operand
|
|
272
|
-
* @param {ReadonlyQuat} b the second operand
|
|
273
|
-
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
274
|
-
* @returns {quat} out
|
|
275
|
-
*/
|
|
276
|
-
export function slerp(out, a, b, t) {
|
|
277
|
-
// benchmarks:
|
|
278
|
-
// http://jsperf.com/quaternion-slerp-implementations
|
|
279
|
-
var ax = a[0],
|
|
280
|
-
ay = a[1],
|
|
281
|
-
az = a[2],
|
|
282
|
-
aw = a[3];
|
|
283
|
-
var bx = b[0],
|
|
284
|
-
by = b[1],
|
|
285
|
-
bz = b[2],
|
|
286
|
-
bw = b[3];
|
|
287
|
-
var omega, cosom, sinom, scale0, scale1;
|
|
288
|
-
|
|
289
|
-
// calc cosine
|
|
290
|
-
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
|
291
|
-
// adjust signs (if necessary)
|
|
292
|
-
if (cosom < 0.0) {
|
|
293
|
-
cosom = -cosom;
|
|
294
|
-
bx = -bx;
|
|
295
|
-
by = -by;
|
|
296
|
-
bz = -bz;
|
|
297
|
-
bw = -bw;
|
|
298
|
-
}
|
|
299
|
-
// calculate coefficients
|
|
300
|
-
if (1.0 - cosom > glMatrix.EPSILON) {
|
|
301
|
-
// standard case (slerp)
|
|
302
|
-
omega = Math.acos(cosom);
|
|
303
|
-
sinom = Math.sin(omega);
|
|
304
|
-
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
|
305
|
-
scale1 = Math.sin(t * omega) / sinom;
|
|
306
|
-
} else {
|
|
307
|
-
// "from" and "to" quaternions are very close
|
|
308
|
-
// ... so we can do a linear interpolation
|
|
309
|
-
scale0 = 1.0 - t;
|
|
310
|
-
scale1 = t;
|
|
311
|
-
}
|
|
312
|
-
// calculate final values
|
|
313
|
-
out[0] = scale0 * ax + scale1 * bx;
|
|
314
|
-
out[1] = scale0 * ay + scale1 * by;
|
|
315
|
-
out[2] = scale0 * az + scale1 * bz;
|
|
316
|
-
out[3] = scale0 * aw + scale1 * bw;
|
|
317
|
-
return out;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Generates a random unit quaternion
|
|
322
|
-
*
|
|
323
|
-
* @param {quat} out the receiving quaternion
|
|
324
|
-
* @returns {quat} out
|
|
325
|
-
*/
|
|
326
|
-
export function random(out) {
|
|
327
|
-
// Implementation of http://planning.cs.uiuc.edu/node198.html
|
|
328
|
-
// TODO: Calling random 3 times is probably not the fastest solution
|
|
329
|
-
var u1 = glMatrix.RANDOM();
|
|
330
|
-
var u2 = glMatrix.RANDOM();
|
|
331
|
-
var u3 = glMatrix.RANDOM();
|
|
332
|
-
var sqrt1MinusU1 = Math.sqrt(1 - u1);
|
|
333
|
-
var sqrtU1 = Math.sqrt(u1);
|
|
334
|
-
out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);
|
|
335
|
-
out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);
|
|
336
|
-
out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);
|
|
337
|
-
out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);
|
|
338
|
-
return out;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Calculates the inverse of a quat
|
|
343
|
-
*
|
|
344
|
-
* @param {quat} out the receiving quaternion
|
|
345
|
-
* @param {ReadonlyQuat} a quat to calculate inverse of
|
|
346
|
-
* @returns {quat} out
|
|
347
|
-
*/
|
|
348
|
-
export function invert(out, a) {
|
|
349
|
-
var a0 = a[0],
|
|
350
|
-
a1 = a[1],
|
|
351
|
-
a2 = a[2],
|
|
352
|
-
a3 = a[3];
|
|
353
|
-
var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
|
|
354
|
-
var invDot = dot ? 1.0 / dot : 0;
|
|
355
|
-
|
|
356
|
-
// TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
|
|
357
|
-
|
|
358
|
-
out[0] = -a0 * invDot;
|
|
359
|
-
out[1] = -a1 * invDot;
|
|
360
|
-
out[2] = -a2 * invDot;
|
|
361
|
-
out[3] = a3 * invDot;
|
|
362
|
-
return out;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Calculates the conjugate of a quat
|
|
367
|
-
* If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
|
|
368
|
-
*
|
|
369
|
-
* @param {quat} out the receiving quaternion
|
|
370
|
-
* @param {ReadonlyQuat} a quat to calculate conjugate of
|
|
371
|
-
* @returns {quat} out
|
|
372
|
-
*/
|
|
373
|
-
export function conjugate(out, a) {
|
|
374
|
-
out[0] = -a[0];
|
|
375
|
-
out[1] = -a[1];
|
|
376
|
-
out[2] = -a[2];
|
|
377
|
-
out[3] = a[3];
|
|
378
|
-
return out;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
383
|
-
*
|
|
384
|
-
* NOTE: The resultant quaternion is not normalized, so you should be sure
|
|
385
|
-
* to renormalize the quaternion yourself where necessary.
|
|
386
|
-
*
|
|
387
|
-
* @param {quat} out the receiving quaternion
|
|
388
|
-
* @param {ReadonlyMat3} m rotation matrix
|
|
389
|
-
* @returns {quat} out
|
|
390
|
-
* @function
|
|
391
|
-
*/
|
|
392
|
-
export function fromMat3(out, m) {
|
|
393
|
-
// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
|
|
394
|
-
// article "Quaternion Calculus and Fast Animation".
|
|
395
|
-
var fTrace = m[0] + m[4] + m[8];
|
|
396
|
-
var fRoot;
|
|
397
|
-
if (fTrace > 0.0) {
|
|
398
|
-
// |w| > 1/2, may as well choose w > 1/2
|
|
399
|
-
fRoot = Math.sqrt(fTrace + 1.0); // 2w
|
|
400
|
-
out[3] = 0.5 * fRoot;
|
|
401
|
-
fRoot = 0.5 / fRoot; // 1/(4w)
|
|
402
|
-
out[0] = (m[5] - m[7]) * fRoot;
|
|
403
|
-
out[1] = (m[6] - m[2]) * fRoot;
|
|
404
|
-
out[2] = (m[1] - m[3]) * fRoot;
|
|
405
|
-
} else {
|
|
406
|
-
// |w| <= 1/2
|
|
407
|
-
var i = 0;
|
|
408
|
-
if (m[4] > m[0]) i = 1;
|
|
409
|
-
if (m[8] > m[i * 3 + i]) i = 2;
|
|
410
|
-
var j = (i + 1) % 3;
|
|
411
|
-
var k = (i + 2) % 3;
|
|
412
|
-
fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
|
|
413
|
-
out[i] = 0.5 * fRoot;
|
|
414
|
-
fRoot = 0.5 / fRoot;
|
|
415
|
-
out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
|
|
416
|
-
out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
|
|
417
|
-
out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
|
|
418
|
-
}
|
|
419
|
-
return out;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Creates a quaternion from the given euler angle x, y, z using the provided intrinsic order for the conversion.
|
|
424
|
-
*
|
|
425
|
-
* @param {quat} out the receiving quaternion
|
|
426
|
-
* @param {Number} x Angle to rotate around X axis in degrees.
|
|
427
|
-
* @param {Number} y Angle to rotate around Y axis in degrees.
|
|
428
|
-
* @param {Number} z Angle to rotate around Z axis in degrees.
|
|
429
|
-
* @param {'xyz'|'xzy'|'yxz'|'yzx'|'zxy'|'zyx'} order Intrinsic order for conversion, default is zyx.
|
|
430
|
-
* @returns {quat} out
|
|
431
|
-
* @function
|
|
432
|
-
*/
|
|
433
|
-
export function fromEuler(out, x, y, z) {
|
|
434
|
-
var order = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : glMatrix.ANGLE_ORDER;
|
|
435
|
-
var halfToRad = Math.PI / 360;
|
|
436
|
-
x *= halfToRad;
|
|
437
|
-
z *= halfToRad;
|
|
438
|
-
y *= halfToRad;
|
|
439
|
-
var sx = Math.sin(x);
|
|
440
|
-
var cx = Math.cos(x);
|
|
441
|
-
var sy = Math.sin(y);
|
|
442
|
-
var cy = Math.cos(y);
|
|
443
|
-
var sz = Math.sin(z);
|
|
444
|
-
var cz = Math.cos(z);
|
|
445
|
-
switch (order) {
|
|
446
|
-
case "xyz":
|
|
447
|
-
out[0] = sx * cy * cz + cx * sy * sz;
|
|
448
|
-
out[1] = cx * sy * cz - sx * cy * sz;
|
|
449
|
-
out[2] = cx * cy * sz + sx * sy * cz;
|
|
450
|
-
out[3] = cx * cy * cz - sx * sy * sz;
|
|
451
|
-
break;
|
|
452
|
-
case "xzy":
|
|
453
|
-
out[0] = sx * cy * cz - cx * sy * sz;
|
|
454
|
-
out[1] = cx * sy * cz - sx * cy * sz;
|
|
455
|
-
out[2] = cx * cy * sz + sx * sy * cz;
|
|
456
|
-
out[3] = cx * cy * cz + sx * sy * sz;
|
|
457
|
-
break;
|
|
458
|
-
case "yxz":
|
|
459
|
-
out[0] = sx * cy * cz + cx * sy * sz;
|
|
460
|
-
out[1] = cx * sy * cz - sx * cy * sz;
|
|
461
|
-
out[2] = cx * cy * sz - sx * sy * cz;
|
|
462
|
-
out[3] = cx * cy * cz + sx * sy * sz;
|
|
463
|
-
break;
|
|
464
|
-
case "yzx":
|
|
465
|
-
out[0] = sx * cy * cz + cx * sy * sz;
|
|
466
|
-
out[1] = cx * sy * cz + sx * cy * sz;
|
|
467
|
-
out[2] = cx * cy * sz - sx * sy * cz;
|
|
468
|
-
out[3] = cx * cy * cz - sx * sy * sz;
|
|
469
|
-
break;
|
|
470
|
-
case "zxy":
|
|
471
|
-
out[0] = sx * cy * cz - cx * sy * sz;
|
|
472
|
-
out[1] = cx * sy * cz + sx * cy * sz;
|
|
473
|
-
out[2] = cx * cy * sz + sx * sy * cz;
|
|
474
|
-
out[3] = cx * cy * cz - sx * sy * sz;
|
|
475
|
-
break;
|
|
476
|
-
case "zyx":
|
|
477
|
-
out[0] = sx * cy * cz - cx * sy * sz;
|
|
478
|
-
out[1] = cx * sy * cz + sx * cy * sz;
|
|
479
|
-
out[2] = cx * cy * sz - sx * sy * cz;
|
|
480
|
-
out[3] = cx * cy * cz + sx * sy * sz;
|
|
481
|
-
break;
|
|
482
|
-
default:
|
|
483
|
-
throw new Error('Unknown angle order ' + order);
|
|
484
|
-
}
|
|
485
|
-
return out;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Returns a string representation of a quaternion
|
|
490
|
-
*
|
|
491
|
-
* @param {ReadonlyQuat} a vector to represent as a string
|
|
492
|
-
* @returns {String} string representation of the vector
|
|
493
|
-
*/
|
|
494
|
-
export function str(a) {
|
|
495
|
-
return "quat(" + a[0] + ", " + a[1] + ", " + a[2] + ", " + a[3] + ")";
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Creates a new quat initialized with values from an existing quaternion
|
|
500
|
-
*
|
|
501
|
-
* @param {ReadonlyQuat} a quaternion to clone
|
|
502
|
-
* @returns {quat} a new quaternion
|
|
503
|
-
* @function
|
|
504
|
-
*/
|
|
505
|
-
export var clone = vec4.clone;
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Creates a new quat initialized with the given values
|
|
509
|
-
*
|
|
510
|
-
* @param {Number} x X component
|
|
511
|
-
* @param {Number} y Y component
|
|
512
|
-
* @param {Number} z Z component
|
|
513
|
-
* @param {Number} w W component
|
|
514
|
-
* @returns {quat} a new quaternion
|
|
515
|
-
* @function
|
|
516
|
-
*/
|
|
517
|
-
export var fromValues = vec4.fromValues;
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* Copy the values from one quat to another
|
|
521
|
-
*
|
|
522
|
-
* @param {quat} out the receiving quaternion
|
|
523
|
-
* @param {ReadonlyQuat} a the source quaternion
|
|
524
|
-
* @returns {quat} out
|
|
525
|
-
* @function
|
|
526
|
-
*/
|
|
527
|
-
export var copy = vec4.copy;
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Set the components of a quat to the given values
|
|
531
|
-
*
|
|
532
|
-
* @param {quat} out the receiving quaternion
|
|
533
|
-
* @param {Number} x X component
|
|
534
|
-
* @param {Number} y Y component
|
|
535
|
-
* @param {Number} z Z component
|
|
536
|
-
* @param {Number} w W component
|
|
537
|
-
* @returns {quat} out
|
|
538
|
-
* @function
|
|
539
|
-
*/
|
|
540
|
-
export var set = vec4.set;
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Adds two quat's
|
|
544
|
-
*
|
|
545
|
-
* @param {quat} out the receiving quaternion
|
|
546
|
-
* @param {ReadonlyQuat} a the first operand
|
|
547
|
-
* @param {ReadonlyQuat} b the second operand
|
|
548
|
-
* @returns {quat} out
|
|
549
|
-
* @function
|
|
550
|
-
*/
|
|
551
|
-
export var add = vec4.add;
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Alias for {@link quat.multiply}
|
|
555
|
-
* @function
|
|
556
|
-
*/
|
|
557
|
-
export var mul = multiply;
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Scales a quat by a scalar number
|
|
561
|
-
*
|
|
562
|
-
* @param {quat} out the receiving vector
|
|
563
|
-
* @param {ReadonlyQuat} a the vector to scale
|
|
564
|
-
* @param {Number} b amount to scale the vector by
|
|
565
|
-
* @returns {quat} out
|
|
566
|
-
* @function
|
|
567
|
-
*/
|
|
568
|
-
export var scale = vec4.scale;
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Calculates the dot product of two quat's
|
|
572
|
-
*
|
|
573
|
-
* @param {ReadonlyQuat} a the first operand
|
|
574
|
-
* @param {ReadonlyQuat} b the second operand
|
|
575
|
-
* @returns {Number} dot product of a and b
|
|
576
|
-
* @function
|
|
577
|
-
*/
|
|
578
|
-
export var dot = vec4.dot;
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Performs a linear interpolation between two quat's
|
|
582
|
-
*
|
|
583
|
-
* @param {quat} out the receiving quaternion
|
|
584
|
-
* @param {ReadonlyQuat} a the first operand
|
|
585
|
-
* @param {ReadonlyQuat} b the second operand
|
|
586
|
-
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
587
|
-
* @returns {quat} out
|
|
588
|
-
* @function
|
|
589
|
-
*/
|
|
590
|
-
export var lerp = vec4.lerp;
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* Calculates the length of a quat
|
|
594
|
-
*
|
|
595
|
-
* @param {ReadonlyQuat} a vector to calculate length of
|
|
596
|
-
* @returns {Number} length of a
|
|
597
|
-
*/
|
|
598
|
-
export var length = vec4.length;
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Alias for {@link quat.length}
|
|
602
|
-
* @function
|
|
603
|
-
*/
|
|
604
|
-
export var len = length;
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* Calculates the squared length of a quat
|
|
608
|
-
*
|
|
609
|
-
* @param {ReadonlyQuat} a vector to calculate squared length of
|
|
610
|
-
* @returns {Number} squared length of a
|
|
611
|
-
* @function
|
|
612
|
-
*/
|
|
613
|
-
export var squaredLength = vec4.squaredLength;
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Alias for {@link quat.squaredLength}
|
|
617
|
-
* @function
|
|
618
|
-
*/
|
|
619
|
-
export var sqrLen = squaredLength;
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
* Normalize a quat
|
|
623
|
-
*
|
|
624
|
-
* @param {quat} out the receiving quaternion
|
|
625
|
-
* @param {ReadonlyQuat} a quaternion to normalize
|
|
626
|
-
* @returns {quat} out
|
|
627
|
-
* @function
|
|
628
|
-
*/
|
|
629
|
-
export var normalize = vec4.normalize;
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)
|
|
633
|
-
*
|
|
634
|
-
* @param {ReadonlyQuat} a The first quaternion.
|
|
635
|
-
* @param {ReadonlyQuat} b The second quaternion.
|
|
636
|
-
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
637
|
-
*/
|
|
638
|
-
export var exactEquals = vec4.exactEquals;
|
|
639
|
-
|
|
640
|
-
/**
|
|
641
|
-
* Returns whether or not the quaternions point approximately to the same direction.
|
|
642
|
-
*
|
|
643
|
-
* Both quaternions are assumed to be unit length.
|
|
644
|
-
*
|
|
645
|
-
* @param {ReadonlyQuat} a The first unit quaternion.
|
|
646
|
-
* @param {ReadonlyQuat} b The second unit quaternion.
|
|
647
|
-
* @returns {Boolean} True if the quaternions are equal, false otherwise.
|
|
648
|
-
*/
|
|
649
|
-
export function equals(a, b) {
|
|
650
|
-
return Math.abs(vec4.dot(a, b)) >= 1 - glMatrix.EPSILON;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* Sets a quaternion to represent the shortest rotation from one
|
|
655
|
-
* vector to another.
|
|
656
|
-
*
|
|
657
|
-
* Both vectors are assumed to be unit length.
|
|
658
|
-
*
|
|
659
|
-
* @param {quat} out the receiving quaternion.
|
|
660
|
-
* @param {ReadonlyVec3} a the initial vector
|
|
661
|
-
* @param {ReadonlyVec3} b the destination vector
|
|
662
|
-
* @returns {quat} out
|
|
663
|
-
*/
|
|
664
|
-
export function rotationTo (out, a, b) {
|
|
665
|
-
var tmpvec3 = vec3.create();
|
|
666
|
-
var xUnitVec3 = vec3.fromValues(1, 0, 0);
|
|
667
|
-
var yUnitVec3 = vec3.fromValues(0, 1, 0);
|
|
668
|
-
|
|
669
|
-
var dot = vec3.dot(a, b);
|
|
670
|
-
if (dot < -0.999999) {
|
|
671
|
-
vec3.cross(tmpvec3, xUnitVec3, a);
|
|
672
|
-
if (vec3.len(tmpvec3) < 0.000001) vec3.cross(tmpvec3, yUnitVec3, a);
|
|
673
|
-
vec3.normalize(tmpvec3, tmpvec3);
|
|
674
|
-
setAxisAngle(out, tmpvec3, Math.PI);
|
|
675
|
-
return out;
|
|
676
|
-
} else if (dot > 0.999999) {
|
|
677
|
-
out[0] = 0;
|
|
678
|
-
out[1] = 0;
|
|
679
|
-
out[2] = 0;
|
|
680
|
-
out[3] = 1;
|
|
681
|
-
return out;
|
|
682
|
-
} else {
|
|
683
|
-
vec3.cross(tmpvec3, a, b);
|
|
684
|
-
out[0] = tmpvec3[0];
|
|
685
|
-
out[1] = tmpvec3[1];
|
|
686
|
-
out[2] = tmpvec3[2];
|
|
687
|
-
out[3] = 1 + dot;
|
|
688
|
-
return normalize(out, out);
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* Performs a spherical linear interpolation with two control points
|
|
695
|
-
*
|
|
696
|
-
* @param {quat} out the receiving quaternion
|
|
697
|
-
* @param {ReadonlyQuat} a the first operand
|
|
698
|
-
* @param {ReadonlyQuat} b the second operand
|
|
699
|
-
* @param {ReadonlyQuat} c the third operand
|
|
700
|
-
* @param {ReadonlyQuat} d the fourth operand
|
|
701
|
-
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
702
|
-
* @returns {quat} out
|
|
703
|
-
*/
|
|
704
|
-
export function sqlerp (out, a, b, c, d, t) {
|
|
705
|
-
var temp1 = create();
|
|
706
|
-
var temp2 = create();
|
|
707
|
-
slerp(temp1, a, d, t);
|
|
708
|
-
slerp(temp2, b, c, t);
|
|
709
|
-
slerp(out, temp1, temp2, 2 * t * (1 - t));
|
|
710
|
-
return out;
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* Sets the specified quaternion with values corresponding to the given
|
|
716
|
-
* axes. Each axis is a vec3 and is expected to be unit length and
|
|
717
|
-
* perpendicular to all other specified axes.
|
|
718
|
-
*
|
|
719
|
-
* @param {ReadonlyVec3} view the vector representing the viewing direction
|
|
720
|
-
* @param {ReadonlyVec3} right the vector representing the local "right" direction
|
|
721
|
-
* @param {ReadonlyVec3} up the vector representing the local "up" direction
|
|
722
|
-
* @returns {quat} out
|
|
723
|
-
*/
|
|
724
|
-
export function setAxes (out, view, right, up) {
|
|
725
|
-
var matr = new Float32Array(9);
|
|
726
|
-
|
|
727
|
-
matr[0] = right[0];
|
|
728
|
-
matr[3] = right[1];
|
|
729
|
-
matr[6] = right[2];
|
|
730
|
-
matr[1] = up[0];
|
|
731
|
-
matr[4] = up[1];
|
|
732
|
-
matr[7] = up[2];
|
|
733
|
-
matr[2] = -view[0];
|
|
734
|
-
matr[5] = -view[1];
|
|
735
|
-
matr[8] = -view[2];
|
|
736
|
-
return normalize(out, fromMat3(out, matr));
|
|
737
|
-
};
|