melonjs 14.0.1 → 14.1.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.
Files changed (214) hide show
  1. package/README.md +2 -0
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
  4. package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
  5. package/dist/melonjs.mjs/_virtual/howler.js +10 -0
  6. package/dist/melonjs.mjs/_virtual/index.js +10 -0
  7. package/dist/melonjs.mjs/_virtual/index2.js +10 -0
  8. package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
  10. package/dist/melonjs.mjs/application/application.js +240 -0
  11. package/dist/melonjs.mjs/audio/audio.js +536 -0
  12. package/dist/melonjs.mjs/camera/camera2d.js +732 -0
  13. package/dist/melonjs.mjs/entity/entity.js +248 -0
  14. package/dist/melonjs.mjs/game.js +29 -0
  15. package/dist/melonjs.mjs/geometries/ellipse.js +275 -0
  16. package/dist/melonjs.mjs/geometries/line.js +116 -0
  17. package/dist/melonjs.mjs/geometries/path2d.js +319 -0
  18. package/dist/melonjs.mjs/geometries/point.js +89 -0
  19. package/dist/melonjs.mjs/geometries/poly.js +500 -0
  20. package/dist/melonjs.mjs/geometries/rectangle.js +375 -0
  21. package/dist/melonjs.mjs/geometries/roundrect.js +168 -0
  22. package/dist/melonjs.mjs/index.js +248 -0
  23. package/dist/melonjs.mjs/input/gamepad.js +501 -0
  24. package/dist/melonjs.mjs/input/input.js +26 -0
  25. package/dist/melonjs.mjs/input/keyboard.js +470 -0
  26. package/dist/melonjs.mjs/input/pointer.js +393 -0
  27. package/dist/melonjs.mjs/input/pointerevent.js +818 -0
  28. package/dist/melonjs.mjs/lang/deprecated.js +157 -0
  29. package/dist/melonjs.mjs/level/level.js +297 -0
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +448 -0
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +194 -0
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +639 -0
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +311 -0
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +83 -0
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
  38. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +506 -0
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +220 -0
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +157 -0
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +125 -0
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +109 -0
  43. package/dist/melonjs.mjs/loader/loader.js +801 -0
  44. package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
  45. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
  46. package/dist/melonjs.mjs/math/color.js +618 -0
  47. package/dist/melonjs.mjs/math/math.js +218 -0
  48. package/dist/melonjs.mjs/math/matrix2.js +503 -0
  49. package/dist/melonjs.mjs/math/matrix3.js +681 -0
  50. package/dist/melonjs.mjs/math/observable_vector2.js +471 -0
  51. package/dist/melonjs.mjs/math/observable_vector3.js +561 -0
  52. package/dist/melonjs.mjs/math/vector2.js +528 -0
  53. package/dist/melonjs.mjs/math/vector3.js +569 -0
  54. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
  55. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
  56. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
  57. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
  58. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
  59. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
  60. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
  61. package/dist/melonjs.mjs/particles/emitter.js +267 -0
  62. package/dist/melonjs.mjs/particles/particle.js +188 -0
  63. package/dist/melonjs.mjs/particles/settings.js +319 -0
  64. package/dist/melonjs.mjs/physics/body.js +704 -0
  65. package/dist/melonjs.mjs/physics/bounds.js +460 -0
  66. package/dist/melonjs.mjs/physics/collision.js +132 -0
  67. package/dist/melonjs.mjs/physics/detector.js +194 -0
  68. package/dist/melonjs.mjs/physics/quadtree.js +391 -0
  69. package/dist/melonjs.mjs/physics/response.js +57 -0
  70. package/dist/melonjs.mjs/physics/sat.js +483 -0
  71. package/dist/melonjs.mjs/physics/world.js +221 -0
  72. package/dist/melonjs.mjs/plugin/plugin.js +141 -0
  73. package/dist/melonjs.mjs/renderable/collectable.js +62 -0
  74. package/dist/melonjs.mjs/renderable/colorlayer.js +80 -0
  75. package/dist/melonjs.mjs/renderable/container.js +1018 -0
  76. package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
  77. package/dist/melonjs.mjs/renderable/imagelayer.js +306 -0
  78. package/dist/melonjs.mjs/renderable/light2d.js +156 -0
  79. package/dist/melonjs.mjs/renderable/nineslicesprite.js +247 -0
  80. package/dist/melonjs.mjs/renderable/renderable.js +783 -0
  81. package/dist/melonjs.mjs/renderable/sprite.js +654 -0
  82. package/dist/melonjs.mjs/renderable/trigger.js +157 -0
  83. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +213 -0
  84. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +226 -0
  85. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +128 -0
  86. package/dist/melonjs.mjs/state/stage.js +237 -0
  87. package/dist/melonjs.mjs/state/state.js +596 -0
  88. package/dist/melonjs.mjs/system/device.js +909 -0
  89. package/dist/melonjs.mjs/system/dom.js +78 -0
  90. package/dist/melonjs.mjs/system/event.js +537 -0
  91. package/dist/melonjs.mjs/system/platform.js +41 -0
  92. package/dist/melonjs.mjs/system/pooling.js +209 -0
  93. package/dist/melonjs.mjs/system/save.js +157 -0
  94. package/dist/melonjs.mjs/system/timer.js +286 -0
  95. package/dist/melonjs.mjs/text/bitmaptext.js +364 -0
  96. package/dist/melonjs.mjs/text/bitmaptextdata.js +199 -0
  97. package/dist/melonjs.mjs/text/glyph.js +66 -0
  98. package/dist/melonjs.mjs/text/text.js +453 -0
  99. package/dist/melonjs.mjs/text/textmetrics.js +176 -0
  100. package/dist/melonjs.mjs/text/textstyle.js +23 -0
  101. package/dist/melonjs.mjs/tweens/easing.js +336 -0
  102. package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
  103. package/dist/melonjs.mjs/tweens/tween.js +480 -0
  104. package/dist/melonjs.mjs/utils/agent.js +76 -0
  105. package/dist/melonjs.mjs/utils/array.js +63 -0
  106. package/dist/melonjs.mjs/utils/file.js +42 -0
  107. package/dist/melonjs.mjs/utils/function.js +70 -0
  108. package/dist/melonjs.mjs/utils/string.js +82 -0
  109. package/dist/melonjs.mjs/utils/utils.js +173 -0
  110. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +807 -0
  111. package/dist/melonjs.mjs/video/renderer.js +411 -0
  112. package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
  113. package/dist/melonjs.mjs/video/texture/cache.js +143 -0
  114. package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
  115. package/dist/melonjs.mjs/video/video.js +462 -0
  116. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +143 -0
  117. package/dist/melonjs.mjs/video/webgl/glshader.js +168 -0
  118. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
  119. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
  120. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
  121. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
  122. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
  123. package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
  124. package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
  125. package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
  126. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
  127. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +495 -0
  128. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1036 -0
  129. package/dist/melonjs.module.d.ts +1163 -1163
  130. package/dist/melonjs.module.js +1903 -3274
  131. package/package.json +22 -17
  132. package/src/application/application.js +3 -3
  133. package/src/audio/audio.js +32 -32
  134. package/src/camera/camera2d.js +31 -31
  135. package/src/entity/entity.js +17 -17
  136. package/src/geometries/ellipse.js +16 -16
  137. package/src/geometries/line.js +5 -5
  138. package/src/geometries/path2d.js +32 -32
  139. package/src/geometries/poly.js +15 -15
  140. package/src/geometries/rectangle.js +18 -18
  141. package/src/geometries/roundrect.js +8 -8
  142. package/src/input/gamepad.js +15 -15
  143. package/src/input/keyboard.js +12 -12
  144. package/src/input/pointer.js +6 -6
  145. package/src/input/pointerevent.js +12 -12
  146. package/src/lang/deprecated.js +12 -12
  147. package/src/level/level.js +25 -25
  148. package/src/level/tiled/TMXLayer.js +22 -22
  149. package/src/level/tiled/TMXTile.js +5 -5
  150. package/src/level/tiled/TMXTileMap.js +6 -6
  151. package/src/level/tiled/TMXTileset.js +2 -2
  152. package/src/level/tiled/TMXUtils.js +5 -5
  153. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
  154. package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
  155. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  156. package/src/level/tiled/renderer/TMXRenderer.js +19 -19
  157. package/src/loader/loader.js +20 -20
  158. package/src/math/color.js +20 -20
  159. package/src/math/math.js +16 -16
  160. package/src/math/matrix2.js +16 -16
  161. package/src/math/matrix3.js +25 -25
  162. package/src/math/observable_vector2.js +14 -14
  163. package/src/math/observable_vector3.js +16 -16
  164. package/src/math/vector2.js +9 -9
  165. package/src/math/vector3.js +10 -10
  166. package/src/particles/emitter.js +6 -6
  167. package/src/particles/particle.js +2 -2
  168. package/src/physics/body.js +28 -28
  169. package/src/physics/bounds.js +8 -8
  170. package/src/physics/collision.js +2 -2
  171. package/src/physics/detector.js +6 -6
  172. package/src/physics/quadtree.js +11 -11
  173. package/src/physics/sat.js +31 -31
  174. package/src/physics/world.js +5 -5
  175. package/src/plugin/plugin.js +5 -5
  176. package/src/renderable/collectable.js +3 -3
  177. package/src/renderable/colorlayer.js +5 -5
  178. package/src/renderable/container.js +21 -21
  179. package/src/renderable/dragndrop.js +14 -14
  180. package/src/renderable/imagelayer.js +13 -13
  181. package/src/renderable/light2d.js +3 -3
  182. package/src/renderable/nineslicesprite.js +16 -16
  183. package/src/renderable/renderable.js +23 -23
  184. package/src/renderable/sprite.js +28 -28
  185. package/src/renderable/trigger.js +15 -15
  186. package/src/renderable/ui/uibaseelement.js +7 -7
  187. package/src/renderable/ui/uispriteelement.js +6 -6
  188. package/src/renderable/ui/uitextbutton.js +13 -13
  189. package/src/state/stage.js +7 -7
  190. package/src/state/state.js +17 -17
  191. package/src/system/device.js +11 -11
  192. package/src/system/event.js +10 -10
  193. package/src/system/pooling.js +9 -9
  194. package/src/system/save.js +2 -2
  195. package/src/system/timer.js +10 -10
  196. package/src/text/bitmaptext.js +18 -18
  197. package/src/text/bitmaptextdata.js +2 -2
  198. package/src/text/text.js +23 -23
  199. package/src/text/textmetrics.js +8 -8
  200. package/src/tweens/tween.js +19 -19
  201. package/src/utils/agent.js +5 -5
  202. package/src/utils/array.js +4 -4
  203. package/src/utils/file.js +2 -2
  204. package/src/utils/function.js +6 -6
  205. package/src/utils/string.js +5 -5
  206. package/src/utils/utils.js +4 -4
  207. package/src/video/canvas/canvas_renderer.js +70 -70
  208. package/src/video/renderer.js +26 -26
  209. package/src/video/texture/atlas.js +22 -22
  210. package/src/video/texture/canvas_texture.js +9 -9
  211. package/src/video/video.js +17 -17
  212. package/src/video/webgl/glshader.js +10 -10
  213. package/src/video/webgl/webgl_compositor.js +41 -41
  214. package/src/video/webgl/webgl_renderer.js +75 -75
@@ -0,0 +1,569 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import { clamp } from './math.js';
9
+ import pool from '../system/pooling.js';
10
+
11
+ /**
12
+ * @classdesc
13
+ * a generic 3D Vector Object
14
+ */
15
+ class Vector3d {
16
+ /**
17
+ * @param {number} [x=0] - x value of the vector
18
+ * @param {number} [y=0] - y value of the vector
19
+ * @param {number} [z=0] - z value of the vector
20
+ */
21
+ constructor(x = 0, y = 0, z = 0) {
22
+ this.onResetEvent(x, y, z);
23
+ }
24
+
25
+ /**
26
+ * @ignore
27
+ */
28
+ onResetEvent(x = 0, y = 0, z = 0) {
29
+ // this is to enable proper object pooling
30
+ this.x = x;
31
+ this.y = y;
32
+ this.z = z;
33
+ return this;
34
+ }
35
+
36
+ /**
37
+ * @ignore
38
+ */
39
+ _set(x, y, z = 0) {
40
+ this.x = x;
41
+ this.y = y;
42
+ this.z = z;
43
+ return this;
44
+ }
45
+
46
+ /**
47
+ * set the Vector x and y properties to the given values<br>
48
+ * @name set
49
+ * @memberof Vector3d
50
+ * @param {number} x
51
+ * @param {number} y
52
+ * @param {number} [z=0]
53
+ * @returns {Vector3d} Reference to this object for method chaining
54
+ */
55
+ set(x, y, z) {
56
+ if (x !== +x || y !== +y || (typeof z !== "undefined" && z !== +z)) {
57
+ throw new Error(
58
+ "invalid x, y, z parameters (not a number)"
59
+ );
60
+ }
61
+
62
+ /**
63
+ * x value of the vector
64
+ * @public
65
+ * @member {number}
66
+ * @name x
67
+ * @memberof Vector3d
68
+ */
69
+ //this.x = x;
70
+
71
+ /**
72
+ * y value of the vector
73
+ * @public
74
+ * @member {number}
75
+ * @name y
76
+ * @memberof Vector3d
77
+ */
78
+ //this.y = y;
79
+
80
+ /**
81
+ * z value of the vector
82
+ * @public
83
+ * @member {number}
84
+ * @name z
85
+ * @memberof Vector3d
86
+ */
87
+ //this.z = z;
88
+
89
+ return this._set(x, y, z);
90
+ }
91
+
92
+ /**
93
+ * set the Vector x and y properties to 0
94
+ * @name setZero
95
+ * @memberof Vector3d
96
+ * @returns {Vector3d} Reference to this object for method chaining
97
+ */
98
+ setZero() {
99
+ return this.set(0, 0, 0);
100
+ }
101
+
102
+ /**
103
+ * set the Vector x and y properties using the passed vector
104
+ * @name setV
105
+ * @memberof Vector3d
106
+ * @param {Vector2d|Vector3d} v
107
+ * @returns {Vector3d} Reference to this object for method chaining
108
+ */
109
+ setV(v) {
110
+ return this._set(v.x, v.y, v.z);
111
+ }
112
+
113
+ /**
114
+ * Add the passed vector to this vector
115
+ * @name add
116
+ * @memberof Vector3d
117
+ * @param {Vector2d|Vector3d} v
118
+ * @returns {Vector3d} Reference to this object for method chaining
119
+ */
120
+ add(v) {
121
+ return this._set(this.x + v.x, this.y + v.y, this.z + (v.z || 0));
122
+ }
123
+
124
+ /**
125
+ * Substract the passed vector to this vector
126
+ * @name sub
127
+ * @memberof Vector3d
128
+ * @param {Vector2d|Vector3d} v
129
+ * @returns {Vector3d} Reference to this object for method chaining
130
+ */
131
+ sub(v) {
132
+ return this._set(this.x - v.x, this.y - v.y, this.z - (v.z || 0));
133
+ }
134
+
135
+ /**
136
+ * Multiply this vector values by the given scalar
137
+ * @name scale
138
+ * @memberof Vector3d
139
+ * @param {number} x
140
+ * @param {number} [y=x]
141
+ * @param {number} [z=1]
142
+ * @returns {Vector3d} Reference to this object for method chaining
143
+ */
144
+ scale(x, y, z) {
145
+ y = (typeof (y) !== "undefined" ? y : x);
146
+ return this._set(this.x * x, this.y * y, this.z * (z || 1));
147
+ }
148
+
149
+ /**
150
+ * Multiply this vector values by the passed vector
151
+ * @name scaleV
152
+ * @memberof Vector3d
153
+ * @param {Vector2d|Vector3d} v
154
+ * @returns {Vector3d} Reference to this object for method chaining
155
+ */
156
+ scaleV(v) {
157
+ return this.scale(v.x, v.y, v.z);
158
+ }
159
+
160
+ /**
161
+ * Convert this vector into isometric coordinate space
162
+ * @name toIso
163
+ * @memberof Vector3d
164
+ * @returns {Vector3d} Reference to this object for method chaining
165
+ */
166
+ toIso() {
167
+ return this._set(this.x - this.y, (this.x + this.y) * 0.5, this.z);
168
+ }
169
+
170
+ /**
171
+ * Convert this vector into 2d coordinate space
172
+ * @name to2d
173
+ * @memberof Vector3d
174
+ * @returns {Vector3d} Reference to this object for method chaining
175
+ */
176
+ to2d() {
177
+ return this._set(this.y + this.x / 2, this.y - this.x / 2, this.z);
178
+ }
179
+
180
+ /**
181
+ * Divide this vector values by the passed value
182
+ * @name div
183
+ * @memberof Vector3d
184
+ * @param {number} n - the value to divide the vector by
185
+ * @returns {Vector3d} Reference to this object for method chaining
186
+ */
187
+ div(n) {
188
+ return this._set(this.x / n, this.y / n, this.z / n);
189
+ }
190
+
191
+ /**
192
+ * Update this vector values to absolute values
193
+ * @name abs
194
+ * @memberof Vector3d
195
+ * @returns {Vector3d} Reference to this object for method chaining
196
+ */
197
+ abs() {
198
+ return this._set((this.x < 0) ? -this.x : this.x, (this.y < 0) ? -this.y : this.y, (this.z < 0) ? -this.z : this.z);
199
+ }
200
+
201
+ /**
202
+ * Clamp the vector value within the specified value range
203
+ * @name clamp
204
+ * @memberof Vector3d
205
+ * @param {number} low
206
+ * @param {number} high
207
+ * @returns {Vector3d} new me.Vector3d
208
+ */
209
+ clamp(low, high) {
210
+ return new Vector3d(clamp(this.x, low, high), clamp(this.y, low, high), clamp(this.z, low, high));
211
+ }
212
+
213
+ /**
214
+ * Clamp this vector value within the specified value range
215
+ * @name clampSelf
216
+ * @memberof Vector3d
217
+ * @param {number} low
218
+ * @param {number} high
219
+ * @returns {Vector3d} Reference to this object for method chaining
220
+ */
221
+ clampSelf(low, high) {
222
+ return this._set(clamp(this.x, low, high), clamp(this.y, low, high), clamp(this.z, low, high));
223
+ }
224
+
225
+ /**
226
+ * Update this vector with the minimum value between this and the passed vector
227
+ * @name minV
228
+ * @memberof Vector3d
229
+ * @param {Vector2d|Vector3d} v
230
+ * @returns {Vector3d} Reference to this object for method chaining
231
+ */
232
+ minV(v) {
233
+ var _vz = v.z || 0;
234
+ return this._set((this.x < v.x) ? this.x : v.x, (this.y < v.y) ? this.y : v.y, (this.z < _vz) ? this.z : _vz);
235
+ }
236
+
237
+ /**
238
+ * Update this vector with the maximum value between this and the passed vector
239
+ * @name maxV
240
+ * @memberof Vector3d
241
+ * @param {Vector2d|Vector3d} v
242
+ * @returns {Vector3d} Reference to this object for method chaining
243
+ */
244
+ maxV(v) {
245
+ var _vz = v.z || 0;
246
+ return this._set((this.x > v.x) ? this.x : v.x, (this.y > v.y) ? this.y : v.y, (this.z > _vz) ? this.z : _vz);
247
+ }
248
+
249
+ /**
250
+ * Floor the vector values
251
+ * @name floor
252
+ * @memberof Vector3d
253
+ * @returns {Vector3d} new me.Vector3d
254
+ */
255
+ floor() {
256
+ return new Vector3d(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
257
+ }
258
+
259
+ /**
260
+ * Floor this vector values
261
+ * @name floorSelf
262
+ * @memberof Vector3d
263
+ * @returns {Vector3d} Reference to this object for method chaining
264
+ */
265
+ floorSelf() {
266
+ return this._set(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
267
+ }
268
+
269
+ /**
270
+ * Ceil the vector values
271
+ * @name ceil
272
+ * @memberof Vector3d
273
+ * @returns {Vector3d} new me.Vector3d
274
+ */
275
+ ceil() {
276
+ return new Vector3d(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
277
+ }
278
+
279
+ /**
280
+ * Ceil this vector values
281
+ * @name ceilSelf
282
+ * @memberof Vector3d
283
+ * @returns {Vector3d} Reference to this object for method chaining
284
+ */
285
+ ceilSelf() {
286
+ return this._set(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z));
287
+ }
288
+
289
+ /**
290
+ * Negate the vector values
291
+ * @name negate
292
+ * @memberof Vector3d
293
+ * @returns {Vector3d} new me.Vector3d
294
+ */
295
+ negate() {
296
+ return new Vector3d(-this.x, -this.y, -this.z);
297
+ }
298
+
299
+ /**
300
+ * Negate this vector values
301
+ * @name negateSelf
302
+ * @memberof Vector3d
303
+ * @returns {Vector3d} Reference to this object for method chaining
304
+ */
305
+ negateSelf() {
306
+ return this._set(-this.x, -this.y, -this.z);
307
+ }
308
+
309
+ /**
310
+ * Copy the components of the given vector into this one
311
+ * @name copy
312
+ * @memberof Vector3d
313
+ * @param {Vector2d|Vector3d} v
314
+ * @returns {Vector3d} Reference to this object for method chaining
315
+ */
316
+ copy(v) {
317
+ return this._set(v.x, v.y, v.z || 0);
318
+ }
319
+
320
+ /**
321
+ * return true if the two vectors are the same
322
+ * @name equals
323
+ * @memberof Vector3d
324
+ * @method
325
+ * @param {Vector2d|Vector3d} v
326
+ * @returns {boolean}
327
+ */
328
+ /**
329
+ * return true if this vector is equal to the given values
330
+ * @name equals
331
+ * @memberof Vector3d
332
+ * @param {number} x
333
+ * @param {number} y
334
+ * @param {number} [z]
335
+ * @returns {boolean}
336
+ */
337
+ equals() {
338
+ var _x, _y, _z;
339
+ if (arguments.length >= 2) {
340
+ // x, y, z
341
+ _x = arguments[0];
342
+ _y = arguments[1];
343
+ _z = arguments[2];
344
+ } else {
345
+ // vector
346
+ _x = arguments[0].x;
347
+ _y = arguments[0].y;
348
+ _z = arguments[0].z;
349
+ }
350
+
351
+ if (typeof _z === "undefined") {
352
+ _z = this.z;
353
+ }
354
+
355
+ return ((this.x === _x) && (this.y === _y) && (this.z === _z));
356
+ }
357
+
358
+ /**
359
+ * normalize this vector (scale the vector so that its magnitude is 1)
360
+ * @name normalize
361
+ * @memberof Vector3d
362
+ * @returns {Vector3d} Reference to this object for method chaining
363
+ */
364
+ normalize() {
365
+ return this.div(this.length() || 1);
366
+ }
367
+
368
+ /**
369
+ * change this vector to be perpendicular to what it was before.<br>
370
+ * (Effectively rotates it 90 degrees in a clockwise direction around the z axis)
371
+ * @name perp
372
+ * @memberof Vector3d
373
+ * @returns {Vector3d} Reference to this object for method chaining
374
+ */
375
+ perp() {
376
+ return this._set(this.y, -this.x, this.z);
377
+ }
378
+
379
+ /**
380
+ * Rotate this vector (counter-clockwise) by the specified angle (in radians) around the z axis
381
+ * @name rotate
382
+ * @memberof Vector3d
383
+ * @param {number} angle - The angle to rotate (in radians)
384
+ * @param {Vector2d|ObservableVector2d} [v] - an optional point to rotate around (on the same z axis)
385
+ * @returns {Vector3d} Reference to this object for method chaining
386
+ */
387
+ rotate(angle, v) {
388
+ var cx = 0;
389
+ var cy = 0;
390
+
391
+ if (typeof v === "object") {
392
+ cx = v.x;
393
+ cy = v.y;
394
+ }
395
+
396
+ // TODO also rotate on the z axis if the given vector is a 3d one
397
+ var x = this.x - cx;
398
+ var y = this.y - cy;
399
+
400
+ var c = Math.cos(angle);
401
+ var s = Math.sin(angle);
402
+
403
+ return this._set(x * c - y * s + cx, x * s + y * c + cy, this.z);
404
+ }
405
+
406
+ /**
407
+ * return the dot product of this vector and the passed one
408
+ * @name dot
409
+ * @memberof Vector3d
410
+ * @param {Vector2d|Vector3d} v
411
+ * @returns {number} The dot product.
412
+ */
413
+ dot(v) {
414
+ return this.x * v.x + this.y * v.y + this.z * (typeof(v.z) !== "undefined" ? v.z : this.z);
415
+ }
416
+
417
+ /**
418
+ * calculate the cross product of this vector and the passed one
419
+ * @name cross
420
+ * @memberof Vector3d
421
+ * @param {Vector3d} v
422
+ * @returns {Vector3d} Reference to this object for method chaining
423
+ */
424
+ cross(v) {
425
+ var ax = this.x, ay = this.y, az = this.z;
426
+ var bx = v.x, by = v.y, bz = v.z;
427
+
428
+ this.x = ay * bz - az * by;
429
+ this.y = az * bx - ax * bz;
430
+ this.z = ax * by - ay * bx;
431
+
432
+ return this;
433
+ }
434
+
435
+ /**
436
+ * return the square length of this vector
437
+ * @name length2
438
+ * @memberof Vector3d
439
+ * @returns {number} The length^2 of this vector.
440
+ */
441
+ length2() {
442
+ return this.dot(this);
443
+ }
444
+
445
+ /**
446
+ * return the length (magnitude) of this vector
447
+ * @name length
448
+ * @memberof Vector3d
449
+ * @returns {number} the length of this vector
450
+ */
451
+ length() {
452
+ return Math.sqrt(this.length2());
453
+ }
454
+
455
+ /**
456
+ * Linearly interpolate between this vector and the given one.
457
+ * @name lerp
458
+ * @memberof Vector3d
459
+ * @param {Vector3d} v
460
+ * @param {number} alpha - distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one).
461
+ * @returns {Vector3d} Reference to this object for method chaining
462
+ */
463
+ lerp(v, alpha) {
464
+ this.x += ( v.x - this.x ) * alpha;
465
+ this.y += ( v.y - this.y ) * alpha;
466
+ this.z += ( v.z - this.z ) * alpha;
467
+ return this;
468
+ }
469
+
470
+ /**
471
+ * interpolate the position of this vector on the x and y axis towards the given one by the given maximum step.
472
+ * @name moveTowards
473
+ * @memberof Vector3d
474
+ * @param {Vector2d|Vector3d} target
475
+ * @param {number} step - the maximum step per iteration (Negative values will push the vector away from the target)
476
+ * @returns {Vector3d} Reference to this object for method chaining
477
+ */
478
+ moveTowards(target, step) {
479
+ var angle = Math.atan2(target.y - this.y, target.x - this.x);
480
+
481
+ var dx = this.x - target.x;
482
+ var dy = this.y - target.y;
483
+
484
+ var distance = Math.sqrt(dx * dx + dy * dy);
485
+
486
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
487
+ return target;
488
+ }
489
+
490
+ this.x += Math.cos(angle) * step;
491
+ this.y += Math.sin(angle) * step;
492
+
493
+ return this;
494
+ }
495
+
496
+ /**
497
+ * return the distance between this vector and the passed one
498
+ * @name distance
499
+ * @memberof Vector3d
500
+ * @param {Vector2d|Vector3d} v
501
+ * @returns {number}
502
+ */
503
+ distance(v) {
504
+ var dx = this.x - v.x;
505
+ var dy = this.y - v.y;
506
+ var dz = this.z - (v.z || 0);
507
+ return Math.sqrt(dx * dx + dy * dy + dz * dz);
508
+ }
509
+
510
+ /**
511
+ * return the angle between this vector and the passed one
512
+ * @name angle
513
+ * @memberof Vector3d
514
+ * @param {Vector2d|Vector3d} v
515
+ * @returns {number} angle in radians
516
+ */
517
+ angle(v) {
518
+ return Math.acos(clamp(this.dot(v) / (this.length() * v.length()), -1, 1));
519
+ }
520
+
521
+ /**
522
+ * project this vector on to another vector.
523
+ * @name project
524
+ * @memberof Vector3d
525
+ * @param {Vector2d|Vector3d} v - The vector to project onto.
526
+ * @returns {Vector3d} Reference to this object for method chaining
527
+ */
528
+ project(v) {
529
+ var ratio = this.dot(v) / v.length2();
530
+ return this.scale(ratio, ratio, ratio);
531
+ }
532
+
533
+ /**
534
+ * Project this vector onto a vector of unit length.<br>
535
+ * This is slightly more efficient than `project` when dealing with unit vectors.
536
+ * @name projectN
537
+ * @memberof Vector3d
538
+ * @param {Vector2d|Vector3d} v - The unit vector to project onto.
539
+ * @returns {Vector3d} Reference to this object for method chaining
540
+ */
541
+ projectN(v) {
542
+ var ratio = this.dot(v) / v.length2();
543
+ return this.scale(ratio, ratio, ratio);
544
+ }
545
+
546
+ /**
547
+ * return a clone copy of this vector
548
+ * @name clone
549
+ * @memberof Vector3d
550
+ * @returns {Vector3d} new me.Vector3d
551
+ */
552
+ clone() {
553
+ return pool.pull("Vector3d", this.x, this.y, this.z);
554
+ }
555
+
556
+ /**
557
+ * convert the object to a string representation
558
+ * @name toString
559
+ * @memberof Vector3d
560
+ * @returns {string}
561
+ */
562
+ toString() {
563
+ return "x:" + this.x + ",y:" + this.y + ",z:" + this.z;
564
+ }
565
+ }
566
+
567
+ var Vector3d$1 = Vector3d;
568
+
569
+ export { Vector3d$1 as default };
@@ -0,0 +1,73 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import { commonjsGlobal } from '../../../../../_virtual/_commonjsHelpers.js';
9
+ import { __exports as arraymultimap } from '../../../../../_virtual/arraymultimap.js';
10
+ export { __exports as default } from '../../../../../_virtual/arraymultimap.js';
11
+ import './multimap.js';
12
+ import { __exports as multimap } from '../../../../../_virtual/multimap.js';
13
+
14
+ var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
15
+ var extendStatics = function (d, b) {
16
+ extendStatics = Object.setPrototypeOf ||
17
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
18
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
19
+ return extendStatics(d, b);
20
+ };
21
+ return function (d, b) {
22
+ extendStatics(d, b);
23
+ function __() { this.constructor = d; }
24
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
25
+ };
26
+ })();
27
+ Object.defineProperty(arraymultimap, "__esModule", { value: true });
28
+ arraymultimap.ArrayMultimap = void 0;
29
+ var multimap_1 = multimap;
30
+ var ArrayMultimap = /** @class */ (function (_super) {
31
+ __extends(ArrayMultimap, _super);
32
+ function ArrayMultimap(iterable) {
33
+ return _super.call(this, new ArrayOperator(), iterable) || this;
34
+ }
35
+ Object.defineProperty(ArrayMultimap.prototype, Symbol.toStringTag, {
36
+ get: function () {
37
+ return "ArrayMultimap";
38
+ },
39
+ enumerable: false,
40
+ configurable: true
41
+ });
42
+ return ArrayMultimap;
43
+ }(multimap_1.Multimap));
44
+ arraymultimap.ArrayMultimap = ArrayMultimap;
45
+ var ArrayOperator = /** @class */ (function () {
46
+ function ArrayOperator() {
47
+ }
48
+ ArrayOperator.prototype.create = function () {
49
+ return [];
50
+ };
51
+ ArrayOperator.prototype.clone = function (collection) {
52
+ return collection.slice();
53
+ };
54
+ ArrayOperator.prototype.add = function (value, collection) {
55
+ collection.push(value);
56
+ return true;
57
+ };
58
+ ArrayOperator.prototype.size = function (collection) {
59
+ return collection.length;
60
+ };
61
+ ArrayOperator.prototype.delete = function (value, collection) {
62
+ var index = collection.indexOf(value);
63
+ if (index > -1) {
64
+ collection.splice(index, 1);
65
+ return true;
66
+ }
67
+ return false;
68
+ };
69
+ ArrayOperator.prototype.has = function (value, collection) {
70
+ return collection.includes(value);
71
+ };
72
+ return ArrayOperator;
73
+ }());
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import { __exports as src } from '../../../../../_virtual/index.js';
9
+ import './arraymultimap.js';
10
+ import './setmultimap.js';
11
+ import { __exports as arraymultimap } from '../../../../../_virtual/arraymultimap.js';
12
+ import { __exports as setmultimap } from '../../../../../_virtual/setmultimap.js';
13
+
14
+ (function (exports) {
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.SetMultimap = exports.ArrayMultimap = void 0;
17
+ var arraymultimap_1 = arraymultimap;
18
+ Object.defineProperty(exports, "ArrayMultimap", { enumerable: true, get: function () { return arraymultimap_1.ArrayMultimap; } });
19
+ var setmultimap_1 = setmultimap;
20
+ Object.defineProperty(exports, "SetMultimap", { enumerable: true, get: function () { return setmultimap_1.SetMultimap; } });
21
+ } (src));