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