melonjs 10.2.2 → 10.4.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/README.md +6 -6
- package/dist/melonjs.js +2907 -3383
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3620 -4528
- package/dist/melonjs.module.js +3210 -3331
- package/package.json +19 -19
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/draggable.js +11 -21
- package/src/entity/droptarget.js +12 -22
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +9 -20
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +44 -14
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +38 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +8 -10
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +47 -146
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +14 -14
- package/src/physics/quadtree.js +18 -21
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +4 -6
- package/src/video/video.js +16 -17
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -110
- package/src/video/webgl/webgl_renderer.js +126 -106
package/src/math/vector3.js
CHANGED
|
@@ -4,18 +4,15 @@ import pool from "./../system/pooling.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @classdesc
|
|
6
6
|
* a generic 3D Vector Object
|
|
7
|
-
* @class Vector3d
|
|
8
|
-
* @memberOf me
|
|
9
|
-
* @constructor
|
|
10
|
-
* @param {number} [x=0] x value of the vector
|
|
11
|
-
* @param {number} [y=0] y value of the vector
|
|
12
|
-
* @param {number} [z=0] z value of the vector
|
|
13
7
|
*/
|
|
14
|
-
|
|
15
8
|
class Vector3d {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {number} [x=0] x value of the vector
|
|
11
|
+
* @param {number} [y=0] y value of the vector
|
|
12
|
+
* @param {number} [z=0] z value of the vector
|
|
13
|
+
*/
|
|
14
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
15
|
+
this.onResetEvent(x, y, z);
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
/**
|
|
@@ -42,12 +39,12 @@ class Vector3d {
|
|
|
42
39
|
/**
|
|
43
40
|
* set the Vector x and y properties to the given values<br>
|
|
44
41
|
* @name set
|
|
45
|
-
* @
|
|
42
|
+
* @memberof Vector3d
|
|
46
43
|
* @function
|
|
47
44
|
* @param {number} x
|
|
48
45
|
* @param {number} y
|
|
49
46
|
* @param {number} [z=0]
|
|
50
|
-
* @returns {
|
|
47
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
51
48
|
*/
|
|
52
49
|
set(x, y, z) {
|
|
53
50
|
if (x !== +x || y !== +y || (typeof z !== "undefined" && z !== +z)) {
|
|
@@ -61,7 +58,7 @@ class Vector3d {
|
|
|
61
58
|
* @public
|
|
62
59
|
* @type {number}
|
|
63
60
|
* @name x
|
|
64
|
-
* @
|
|
61
|
+
* @memberof Vector3d
|
|
65
62
|
*/
|
|
66
63
|
//this.x = x;
|
|
67
64
|
|
|
@@ -70,7 +67,7 @@ class Vector3d {
|
|
|
70
67
|
* @public
|
|
71
68
|
* @type {number}
|
|
72
69
|
* @name y
|
|
73
|
-
* @
|
|
70
|
+
* @memberof Vector3d
|
|
74
71
|
*/
|
|
75
72
|
//this.y = y;
|
|
76
73
|
|
|
@@ -79,7 +76,7 @@ class Vector3d {
|
|
|
79
76
|
* @public
|
|
80
77
|
* @type {number}
|
|
81
78
|
* @name z
|
|
82
|
-
* @
|
|
79
|
+
* @memberof Vector3d
|
|
83
80
|
*/
|
|
84
81
|
//this.z = z;
|
|
85
82
|
|
|
@@ -89,9 +86,9 @@ class Vector3d {
|
|
|
89
86
|
/**
|
|
90
87
|
* set the Vector x and y properties to 0
|
|
91
88
|
* @name setZero
|
|
92
|
-
* @
|
|
89
|
+
* @memberof Vector3d
|
|
93
90
|
* @function
|
|
94
|
-
* @returns {
|
|
91
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
95
92
|
*/
|
|
96
93
|
setZero() {
|
|
97
94
|
return this.set(0, 0, 0);
|
|
@@ -100,10 +97,10 @@ class Vector3d {
|
|
|
100
97
|
/**
|
|
101
98
|
* set the Vector x and y properties using the passed vector
|
|
102
99
|
* @name setV
|
|
103
|
-
* @
|
|
100
|
+
* @memberof Vector3d
|
|
104
101
|
* @function
|
|
105
|
-
* @param {
|
|
106
|
-
* @returns {
|
|
102
|
+
* @param {Vector2d|Vector3d} v
|
|
103
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
107
104
|
*/
|
|
108
105
|
setV(v) {
|
|
109
106
|
return this._set(v.x, v.y, v.z);
|
|
@@ -112,10 +109,10 @@ class Vector3d {
|
|
|
112
109
|
/**
|
|
113
110
|
* Add the passed vector to this vector
|
|
114
111
|
* @name add
|
|
115
|
-
* @
|
|
112
|
+
* @memberof Vector3d
|
|
116
113
|
* @function
|
|
117
|
-
* @param {
|
|
118
|
-
* @returns {
|
|
114
|
+
* @param {Vector2d|Vector3d} v
|
|
115
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
119
116
|
*/
|
|
120
117
|
add(v) {
|
|
121
118
|
return this._set(this.x + v.x, this.y + v.y, this.z + (v.z || 0));
|
|
@@ -124,10 +121,10 @@ class Vector3d {
|
|
|
124
121
|
/**
|
|
125
122
|
* Substract the passed vector to this vector
|
|
126
123
|
* @name sub
|
|
127
|
-
* @
|
|
124
|
+
* @memberof Vector3d
|
|
128
125
|
* @function
|
|
129
|
-
* @param {
|
|
130
|
-
* @returns {
|
|
126
|
+
* @param {Vector2d|Vector3d} v
|
|
127
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
131
128
|
*/
|
|
132
129
|
sub(v) {
|
|
133
130
|
return this._set(this.x - v.x, this.y - v.y, this.z - (v.z || 0));
|
|
@@ -136,12 +133,12 @@ class Vector3d {
|
|
|
136
133
|
/**
|
|
137
134
|
* Multiply this vector values by the given scalar
|
|
138
135
|
* @name scale
|
|
139
|
-
* @
|
|
136
|
+
* @memberof Vector3d
|
|
140
137
|
* @function
|
|
141
138
|
* @param {number} x
|
|
142
139
|
* @param {number} [y=x]
|
|
143
140
|
* @param {number} [z=1]
|
|
144
|
-
* @returns {
|
|
141
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
145
142
|
*/
|
|
146
143
|
scale(x, y, z) {
|
|
147
144
|
y = (typeof (y) !== "undefined" ? y : x);
|
|
@@ -151,10 +148,10 @@ class Vector3d {
|
|
|
151
148
|
/**
|
|
152
149
|
* Multiply this vector values by the passed vector
|
|
153
150
|
* @name scaleV
|
|
154
|
-
* @
|
|
151
|
+
* @memberof Vector3d
|
|
155
152
|
* @function
|
|
156
|
-
* @param {
|
|
157
|
-
* @returns {
|
|
153
|
+
* @param {Vector2d|Vector3d} v
|
|
154
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
158
155
|
*/
|
|
159
156
|
scaleV(v) {
|
|
160
157
|
return this.scale(v.x, v.y, v.z);
|
|
@@ -163,9 +160,9 @@ class Vector3d {
|
|
|
163
160
|
/**
|
|
164
161
|
* Convert this vector into isometric coordinate space
|
|
165
162
|
* @name toIso
|
|
166
|
-
* @
|
|
163
|
+
* @memberof Vector3d
|
|
167
164
|
* @function
|
|
168
|
-
* @returns {
|
|
165
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
169
166
|
*/
|
|
170
167
|
toIso() {
|
|
171
168
|
return this._set(this.x - this.y, (this.x + this.y) * 0.5, this.z);
|
|
@@ -174,9 +171,9 @@ class Vector3d {
|
|
|
174
171
|
/**
|
|
175
172
|
* Convert this vector into 2d coordinate space
|
|
176
173
|
* @name to2d
|
|
177
|
-
* @
|
|
174
|
+
* @memberof Vector3d
|
|
178
175
|
* @function
|
|
179
|
-
* @returns {
|
|
176
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
180
177
|
*/
|
|
181
178
|
to2d() {
|
|
182
179
|
return this._set(this.y + this.x / 2, this.y - this.x / 2, this.z);
|
|
@@ -185,10 +182,10 @@ class Vector3d {
|
|
|
185
182
|
/**
|
|
186
183
|
* Divide this vector values by the passed value
|
|
187
184
|
* @name div
|
|
188
|
-
* @
|
|
185
|
+
* @memberof Vector3d
|
|
189
186
|
* @function
|
|
190
187
|
* @param {number} n the value to divide the vector by
|
|
191
|
-
* @returns {
|
|
188
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
192
189
|
*/
|
|
193
190
|
div(n) {
|
|
194
191
|
return this._set(this.x / n, this.y / n, this.z / n);
|
|
@@ -197,9 +194,9 @@ class Vector3d {
|
|
|
197
194
|
/**
|
|
198
195
|
* Update this vector values to absolute values
|
|
199
196
|
* @name abs
|
|
200
|
-
* @
|
|
197
|
+
* @memberof Vector3d
|
|
201
198
|
* @function
|
|
202
|
-
* @returns {
|
|
199
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
203
200
|
*/
|
|
204
201
|
abs() {
|
|
205
202
|
return this._set((this.x < 0) ? -this.x : this.x, (this.y < 0) ? -this.y : this.y, (this.z < 0) ? -this.z : this.z);
|
|
@@ -208,11 +205,11 @@ class Vector3d {
|
|
|
208
205
|
/**
|
|
209
206
|
* Clamp the vector value within the specified value range
|
|
210
207
|
* @name clamp
|
|
211
|
-
* @
|
|
208
|
+
* @memberof Vector3d
|
|
212
209
|
* @function
|
|
213
210
|
* @param {number} low
|
|
214
211
|
* @param {number} high
|
|
215
|
-
* @returns {
|
|
212
|
+
* @returns {Vector3d} new me.Vector3d
|
|
216
213
|
*/
|
|
217
214
|
clamp(low, high) {
|
|
218
215
|
return new Vector3d(clamp(this.x, low, high), clamp(this.y, low, high), clamp(this.z, low, high));
|
|
@@ -221,11 +218,11 @@ class Vector3d {
|
|
|
221
218
|
/**
|
|
222
219
|
* Clamp this vector value within the specified value range
|
|
223
220
|
* @name clampSelf
|
|
224
|
-
* @
|
|
221
|
+
* @memberof Vector3d
|
|
225
222
|
* @function
|
|
226
223
|
* @param {number} low
|
|
227
224
|
* @param {number} high
|
|
228
|
-
* @returns {
|
|
225
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
229
226
|
*/
|
|
230
227
|
clampSelf(low, high) {
|
|
231
228
|
return this._set(clamp(this.x, low, high), clamp(this.y, low, high), clamp(this.z, low, high));
|
|
@@ -234,10 +231,10 @@ class Vector3d {
|
|
|
234
231
|
/**
|
|
235
232
|
* Update this vector with the minimum value between this and the passed vector
|
|
236
233
|
* @name minV
|
|
237
|
-
* @
|
|
234
|
+
* @memberof Vector3d
|
|
238
235
|
* @function
|
|
239
|
-
* @param {
|
|
240
|
-
* @returns {
|
|
236
|
+
* @param {Vector2d|Vector3d} v
|
|
237
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
241
238
|
*/
|
|
242
239
|
minV(v) {
|
|
243
240
|
var _vz = v.z || 0;
|
|
@@ -247,10 +244,10 @@ class Vector3d {
|
|
|
247
244
|
/**
|
|
248
245
|
* Update this vector with the maximum value between this and the passed vector
|
|
249
246
|
* @name maxV
|
|
250
|
-
* @
|
|
247
|
+
* @memberof Vector3d
|
|
251
248
|
* @function
|
|
252
|
-
* @param {
|
|
253
|
-
* @returns {
|
|
249
|
+
* @param {Vector2d|Vector3d} v
|
|
250
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
254
251
|
*/
|
|
255
252
|
maxV(v) {
|
|
256
253
|
var _vz = v.z || 0;
|
|
@@ -260,9 +257,9 @@ class Vector3d {
|
|
|
260
257
|
/**
|
|
261
258
|
* Floor the vector values
|
|
262
259
|
* @name floor
|
|
263
|
-
* @
|
|
260
|
+
* @memberof Vector3d
|
|
264
261
|
* @function
|
|
265
|
-
* @returns {
|
|
262
|
+
* @returns {Vector3d} new me.Vector3d
|
|
266
263
|
*/
|
|
267
264
|
floor() {
|
|
268
265
|
return new Vector3d(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
|
|
@@ -271,9 +268,9 @@ class Vector3d {
|
|
|
271
268
|
/**
|
|
272
269
|
* Floor this vector values
|
|
273
270
|
* @name floorSelf
|
|
274
|
-
* @
|
|
271
|
+
* @memberof Vector3d
|
|
275
272
|
* @function
|
|
276
|
-
* @returns {
|
|
273
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
277
274
|
*/
|
|
278
275
|
floorSelf() {
|
|
279
276
|
return this._set(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
|
|
@@ -282,9 +279,9 @@ class Vector3d {
|
|
|
282
279
|
/**
|
|
283
280
|
* Ceil the vector values
|
|
284
281
|
* @name ceil
|
|
285
|
-
* @
|
|
282
|
+
* @memberof Vector3d
|
|
286
283
|
* @function
|
|
287
|
-
* @returns {
|
|
284
|
+
* @returns {Vector3d} new me.Vector3d
|
|
288
285
|
*/
|
|
289
286
|
ceil() {
|
|
290
287
|
return new Vector3d(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
|
|
@@ -293,9 +290,9 @@ class Vector3d {
|
|
|
293
290
|
/**
|
|
294
291
|
* Ceil this vector values
|
|
295
292
|
* @name ceilSelf
|
|
296
|
-
* @
|
|
293
|
+
* @memberof Vector3d
|
|
297
294
|
* @function
|
|
298
|
-
* @returns {
|
|
295
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
299
296
|
*/
|
|
300
297
|
ceilSelf() {
|
|
301
298
|
return this._set(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
|
|
@@ -304,9 +301,9 @@ class Vector3d {
|
|
|
304
301
|
/**
|
|
305
302
|
* Negate the vector values
|
|
306
303
|
* @name negate
|
|
307
|
-
* @
|
|
304
|
+
* @memberof Vector3d
|
|
308
305
|
* @function
|
|
309
|
-
* @returns {
|
|
306
|
+
* @returns {Vector3d} new me.Vector3d
|
|
310
307
|
*/
|
|
311
308
|
negate() {
|
|
312
309
|
return new Vector3d(-this.x, -this.y, -this.z);
|
|
@@ -315,9 +312,9 @@ class Vector3d {
|
|
|
315
312
|
/**
|
|
316
313
|
* Negate this vector values
|
|
317
314
|
* @name negateSelf
|
|
318
|
-
* @
|
|
315
|
+
* @memberof Vector3d
|
|
319
316
|
* @function
|
|
320
|
-
* @returns {
|
|
317
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
321
318
|
*/
|
|
322
319
|
negateSelf() {
|
|
323
320
|
return this._set(-this.x, -this.y, -this.z);
|
|
@@ -326,10 +323,10 @@ class Vector3d {
|
|
|
326
323
|
/**
|
|
327
324
|
* Copy the components of the given vector into this one
|
|
328
325
|
* @name copy
|
|
329
|
-
* @
|
|
326
|
+
* @memberof Vector3d
|
|
330
327
|
* @function
|
|
331
|
-
* @param {
|
|
332
|
-
* @returns {
|
|
328
|
+
* @param {Vector2d|Vector3d} v
|
|
329
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
333
330
|
*/
|
|
334
331
|
copy(v) {
|
|
335
332
|
return this._set(v.x, v.y, v.z || 0);
|
|
@@ -338,15 +335,15 @@ class Vector3d {
|
|
|
338
335
|
/**
|
|
339
336
|
* return true if the two vectors are the same
|
|
340
337
|
* @name equals
|
|
341
|
-
* @
|
|
338
|
+
* @memberof Vector3d
|
|
342
339
|
* @function
|
|
343
|
-
* @param {
|
|
340
|
+
* @param {Vector2d|Vector3d} v
|
|
344
341
|
* @returns {boolean}
|
|
345
342
|
*/
|
|
346
343
|
/**
|
|
347
344
|
* return true if this vector is equal to the given values
|
|
348
345
|
* @name equals
|
|
349
|
-
* @
|
|
346
|
+
* @memberof Vector3d
|
|
350
347
|
* @function
|
|
351
348
|
* @param {number} x
|
|
352
349
|
* @param {number} y
|
|
@@ -377,9 +374,9 @@ class Vector3d {
|
|
|
377
374
|
/**
|
|
378
375
|
* normalize this vector (scale the vector so that its magnitude is 1)
|
|
379
376
|
* @name normalize
|
|
380
|
-
* @
|
|
377
|
+
* @memberof Vector3d
|
|
381
378
|
* @function
|
|
382
|
-
* @returns {
|
|
379
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
383
380
|
*/
|
|
384
381
|
normalize() {
|
|
385
382
|
return this.div(this.length() || 1);
|
|
@@ -389,9 +386,9 @@ class Vector3d {
|
|
|
389
386
|
* change this vector to be perpendicular to what it was before.<br>
|
|
390
387
|
* (Effectively rotates it 90 degrees in a clockwise direction around the z axis)
|
|
391
388
|
* @name perp
|
|
392
|
-
* @
|
|
389
|
+
* @memberof Vector3d
|
|
393
390
|
* @function
|
|
394
|
-
* @returns {
|
|
391
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
395
392
|
*/
|
|
396
393
|
perp() {
|
|
397
394
|
return this._set(this.y, -this.x, this.z);
|
|
@@ -400,11 +397,11 @@ class Vector3d {
|
|
|
400
397
|
/**
|
|
401
398
|
* Rotate this vector (counter-clockwise) by the specified angle (in radians) around the z axis
|
|
402
399
|
* @name rotate
|
|
403
|
-
* @
|
|
400
|
+
* @memberof Vector3d
|
|
404
401
|
* @function
|
|
405
402
|
* @param {number} angle The angle to rotate (in radians)
|
|
406
|
-
* @param {
|
|
407
|
-
* @returns {
|
|
403
|
+
* @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around (on the same z axis)
|
|
404
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
408
405
|
*/
|
|
409
406
|
rotate(angle, v) {
|
|
410
407
|
var cx = 0;
|
|
@@ -427,31 +424,50 @@ class Vector3d {
|
|
|
427
424
|
|
|
428
425
|
/**
|
|
429
426
|
* return the dot product of this vector and the passed one
|
|
430
|
-
* @name
|
|
431
|
-
* @
|
|
427
|
+
* @name dot
|
|
428
|
+
* @memberof Vector3d
|
|
432
429
|
* @function
|
|
433
|
-
* @param {
|
|
430
|
+
* @param {Vector2d|Vector3d} v
|
|
434
431
|
* @returns {number} The dot product.
|
|
435
432
|
*/
|
|
436
|
-
|
|
433
|
+
dot(v) {
|
|
437
434
|
return this.x * v.x + this.y * v.y + this.z * (typeof(v.z) !== "undefined" ? v.z : this.z);
|
|
438
435
|
}
|
|
439
436
|
|
|
437
|
+
/**
|
|
438
|
+
* calculate the cross product of this vector and the passed one
|
|
439
|
+
* @name cross
|
|
440
|
+
* @memberof Vector3d
|
|
441
|
+
* @function
|
|
442
|
+
* @param {Vector3d} v
|
|
443
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
444
|
+
*/
|
|
445
|
+
cross(v) {
|
|
446
|
+
var ax = this.x, ay = this.y, az = this.z;
|
|
447
|
+
var bx = v.x, by = v.y, bz = v.z;
|
|
448
|
+
|
|
449
|
+
this.x = ay * bz - az * by;
|
|
450
|
+
this.y = az * bx - ax * bz;
|
|
451
|
+
this.z = ax * by - ay * bx;
|
|
452
|
+
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
|
|
440
456
|
/**
|
|
441
457
|
* return the square length of this vector
|
|
442
458
|
* @name length2
|
|
443
|
-
* @
|
|
459
|
+
* @memberof Vector3d
|
|
444
460
|
* @function
|
|
445
461
|
* @returns {number} The length^2 of this vector.
|
|
446
462
|
*/
|
|
447
463
|
length2() {
|
|
448
|
-
return this.
|
|
464
|
+
return this.dot(this);
|
|
449
465
|
}
|
|
450
466
|
|
|
451
467
|
/**
|
|
452
468
|
* return the length (magnitude) of this vector
|
|
453
469
|
* @name length
|
|
454
|
-
* @
|
|
470
|
+
* @memberof Vector3d
|
|
455
471
|
* @function
|
|
456
472
|
* @returns {number} the length of this vector
|
|
457
473
|
*/
|
|
@@ -462,11 +478,11 @@ class Vector3d {
|
|
|
462
478
|
/**
|
|
463
479
|
* Linearly interpolate between this vector and the given one.
|
|
464
480
|
* @name lerp
|
|
465
|
-
* @
|
|
481
|
+
* @memberof Vector3d
|
|
466
482
|
* @function
|
|
467
|
-
* @param {
|
|
483
|
+
* @param {Vector3d} v
|
|
468
484
|
* @param {number} alpha distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one).
|
|
469
|
-
* @returns {
|
|
485
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
470
486
|
*/
|
|
471
487
|
lerp(v, alpha) {
|
|
472
488
|
this.x += ( v.x - this.x ) * alpha;
|
|
@@ -478,9 +494,9 @@ class Vector3d {
|
|
|
478
494
|
/**
|
|
479
495
|
* return the distance between this vector and the passed one
|
|
480
496
|
* @name distance
|
|
481
|
-
* @
|
|
497
|
+
* @memberof Vector3d
|
|
482
498
|
* @function
|
|
483
|
-
* @param {
|
|
499
|
+
* @param {Vector2d|Vector3d} v
|
|
484
500
|
* @returns {number}
|
|
485
501
|
*/
|
|
486
502
|
distance(v) {
|
|
@@ -493,25 +509,25 @@ class Vector3d {
|
|
|
493
509
|
/**
|
|
494
510
|
* return the angle between this vector and the passed one
|
|
495
511
|
* @name angle
|
|
496
|
-
* @
|
|
512
|
+
* @memberof Vector3d
|
|
497
513
|
* @function
|
|
498
|
-
* @param {
|
|
514
|
+
* @param {Vector2d|Vector3d} v
|
|
499
515
|
* @returns {number} angle in radians
|
|
500
516
|
*/
|
|
501
517
|
angle(v) {
|
|
502
|
-
return Math.acos(clamp(this.
|
|
518
|
+
return Math.acos(clamp(this.dot(v) / (this.length() * v.length()), -1, 1));
|
|
503
519
|
}
|
|
504
520
|
|
|
505
521
|
/**
|
|
506
522
|
* project this vector on to another vector.
|
|
507
523
|
* @name project
|
|
508
|
-
* @
|
|
524
|
+
* @memberof Vector3d
|
|
509
525
|
* @function
|
|
510
|
-
* @param {
|
|
511
|
-
* @returns {
|
|
526
|
+
* @param {Vector2d|Vector3d} v The vector to project onto.
|
|
527
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
512
528
|
*/
|
|
513
529
|
project(v) {
|
|
514
|
-
var ratio = this.
|
|
530
|
+
var ratio = this.dot(v) / v.length2();
|
|
515
531
|
return this.scale(ratio, ratio, ratio);
|
|
516
532
|
}
|
|
517
533
|
|
|
@@ -519,22 +535,22 @@ class Vector3d {
|
|
|
519
535
|
* Project this vector onto a vector of unit length.<br>
|
|
520
536
|
* This is slightly more efficient than `project` when dealing with unit vectors.
|
|
521
537
|
* @name projectN
|
|
522
|
-
* @
|
|
538
|
+
* @memberof Vector3d
|
|
523
539
|
* @function
|
|
524
|
-
* @param {
|
|
525
|
-
* @returns {
|
|
540
|
+
* @param {Vector2d|Vector3d} v The unit vector to project onto.
|
|
541
|
+
* @returns {Vector3d} Reference to this object for method chaining
|
|
526
542
|
*/
|
|
527
543
|
projectN(v) {
|
|
528
|
-
var ratio = this.
|
|
544
|
+
var ratio = this.dot(v) / v.length2();
|
|
529
545
|
return this.scale(ratio, ratio, ratio);
|
|
530
546
|
}
|
|
531
547
|
|
|
532
548
|
/**
|
|
533
549
|
* return a clone copy of this vector
|
|
534
550
|
* @name clone
|
|
535
|
-
* @
|
|
551
|
+
* @memberof Vector3d
|
|
536
552
|
* @function
|
|
537
|
-
* @returns {
|
|
553
|
+
* @returns {Vector3d} new me.Vector3d
|
|
538
554
|
*/
|
|
539
555
|
clone() {
|
|
540
556
|
return pool.pull("Vector3d", this.x, this.y, this.z);
|
|
@@ -543,7 +559,7 @@ class Vector3d {
|
|
|
543
559
|
/**
|
|
544
560
|
* convert the object to a string representation
|
|
545
561
|
* @name toString
|
|
546
|
-
* @
|
|
562
|
+
* @memberof Vector3d
|
|
547
563
|
* @function
|
|
548
564
|
* @returns {string}
|
|
549
565
|
*/
|