emeraldengine 2.2.1 → 3.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 (208) hide show
  1. package/README.md +2198 -968
  2. package/dist/types/index.d.ts +75 -32
  3. package/dist/types/src/Animator.d.ts +50 -0
  4. package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
  5. package/dist/types/src/Camera.d.ts +122 -0
  6. package/dist/types/src/CameraController.d.ts +107 -0
  7. package/dist/types/src/CanvasText.d.ts +91 -0
  8. package/dist/types/src/CollisionLayers.d.ts +58 -0
  9. package/dist/types/{Color.d.ts → src/Color.d.ts} +6 -6
  10. package/dist/types/src/Coroutine.d.ts +111 -0
  11. package/dist/types/src/DebugOverlay.d.ts +86 -0
  12. package/dist/types/src/Drawable.d.ts +271 -0
  13. package/dist/types/src/Easing.d.ts +22 -0
  14. package/dist/types/src/Emerald.d.ts +420 -0
  15. package/dist/types/src/EmeraldDB.d.ts +159 -0
  16. package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
  17. package/dist/types/src/GLUtils.d.ts +4 -0
  18. package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
  19. package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +75 -23
  20. package/dist/types/src/Interpolator.d.ts +66 -0
  21. package/dist/types/src/Material.d.ts +87 -0
  22. package/dist/types/src/MathUtils.d.ts +81 -0
  23. package/dist/types/src/ParticleEmitter.d.ts +131 -0
  24. package/dist/types/src/Physics.d.ts +337 -0
  25. package/dist/types/src/Pool.d.ts +53 -0
  26. package/dist/types/src/PostEffects.d.ts +68 -0
  27. package/dist/types/src/PostProcessor.d.ts +124 -0
  28. package/dist/types/src/RenderTarget.d.ts +56 -0
  29. package/dist/types/src/Scene.d.ts +62 -0
  30. package/dist/types/src/ScreenEffects.d.ts +111 -0
  31. package/dist/types/src/Serializer.d.ts +86 -0
  32. package/dist/types/src/Shaders.d.ts +2 -0
  33. package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
  34. package/dist/types/src/SpatialGrid.d.ts +50 -0
  35. package/dist/types/src/SpriteBatch.d.ts +89 -0
  36. package/dist/types/src/StateMachine.d.ts +59 -0
  37. package/dist/types/src/Storage.d.ts +89 -0
  38. package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
  39. package/dist/types/src/TextureAtlas.d.ts +55 -0
  40. package/dist/types/src/Tilemap.d.ts +91 -0
  41. package/dist/types/src/Time.d.ts +53 -0
  42. package/dist/types/src/Timer.d.ts +54 -0
  43. package/dist/types/src/Transform.d.ts +94 -0
  44. package/dist/types/src/Tween.d.ts +81 -0
  45. package/dist/types/src/UI.d.ts +121 -0
  46. package/dist/types/src/components/Behaviour.d.ts +71 -0
  47. package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
  48. package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
  49. package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
  50. package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
  51. package/dist/types/src/components/Collider.d.ts +102 -0
  52. package/dist/types/src/components/GameObject.d.ts +135 -0
  53. package/dist/types/src/components/PolygonCollider.d.ts +33 -0
  54. package/dist/types/src/components/RigidBody.d.ts +456 -0
  55. package/dist/types/src/importers/Aseprite.d.ts +79 -0
  56. package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
  57. package/dist/types/src/importers/TiledMap.d.ts +62 -0
  58. package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
  59. package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
  60. package/dist/types/src/managers/AssetManager.d.ts +116 -0
  61. package/dist/types/src/managers/AudioManager.d.ts +259 -0
  62. package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
  63. package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
  64. package/dist/types/src/managers/GLManager.d.ts +84 -0
  65. package/dist/types/src/managers/GLState.d.ts +37 -0
  66. package/dist/types/src/managers/Gamepad.d.ts +102 -0
  67. package/dist/types/src/managers/IDManager.d.ts +31 -0
  68. package/dist/types/src/managers/InputManager.d.ts +381 -0
  69. package/dist/types/src/managers/NetworkManager.d.ts +93 -0
  70. package/dist/types/src/managers/RenderStats.d.ts +34 -0
  71. package/dist/types/src/managers/SceneManager.d.ts +44 -0
  72. package/dist/types/src/managers/ShaderManager.d.ts +55 -0
  73. package/dist/types/src/managers/TextureManager.d.ts +102 -0
  74. package/dist/types/src/particlesystem/Particle.d.ts +64 -0
  75. package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
  76. package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
  77. package/dist/types/src/physics/AABB.d.ts +92 -0
  78. package/dist/types/src/physics/Body.d.ts +435 -0
  79. package/dist/types/src/physics/BodyType.d.ts +6 -0
  80. package/dist/types/src/physics/BroadPhase.d.ts +210 -0
  81. package/dist/types/src/physics/Collision.d.ts +102 -0
  82. package/dist/types/src/physics/Contact.d.ts +206 -0
  83. package/dist/types/src/physics/ContactSolver.d.ts +108 -0
  84. package/dist/types/src/physics/Distance.d.ts +54 -0
  85. package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
  86. package/dist/types/src/physics/Fixture.d.ts +221 -0
  87. package/dist/types/src/physics/Island.d.ts +52 -0
  88. package/dist/types/src/physics/Joint.d.ts +59 -0
  89. package/dist/types/src/physics/Math2D.d.ts +371 -0
  90. package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
  91. package/dist/types/src/physics/Settings.d.ts +22 -0
  92. package/dist/types/src/physics/Shapes.d.ts +207 -0
  93. package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
  94. package/dist/types/src/physics/World.d.ts +274 -0
  95. package/dist/types/src/physics/index.d.ts +34 -0
  96. package/index.js +78 -0
  97. package/package.json +73 -60
  98. package/src/Animator.js +95 -0
  99. package/src/BitmapText.js +6 -5
  100. package/src/Camera.js +183 -0
  101. package/src/CameraController.js +192 -0
  102. package/src/CanvasText.js +281 -0
  103. package/src/CollisionLayers.js +86 -0
  104. package/src/Color.js +26 -18
  105. package/src/Coroutine.js +259 -0
  106. package/src/DebugOverlay.js +246 -0
  107. package/src/Drawable.js +842 -582
  108. package/src/Easing.js +57 -0
  109. package/src/Emerald.js +1150 -459
  110. package/src/EmeraldDB.js +328 -0
  111. package/src/FPSCounter.js +43 -43
  112. package/src/GLUtils.js +60 -67
  113. package/src/Instance.js +41 -5
  114. package/src/InstancedTexture.js +308 -127
  115. package/src/Interpolator.js +124 -0
  116. package/src/Material.js +202 -0
  117. package/src/MathUtils.js +134 -0
  118. package/src/ParticleEmitter.js +284 -0
  119. package/src/Physics.js +431 -40
  120. package/src/Pool.js +85 -0
  121. package/src/PostEffects.js +296 -0
  122. package/src/PostProcessor.js +304 -0
  123. package/src/RenderTarget.js +134 -0
  124. package/src/Scene.js +115 -83
  125. package/src/ScreenEffects.js +266 -0
  126. package/src/Serializer.js +131 -0
  127. package/src/Shaders.js +150 -165
  128. package/src/Shapes.js +118 -129
  129. package/src/SpatialGrid.js +111 -0
  130. package/src/SpriteBatch.js +299 -0
  131. package/src/StateMachine.js +82 -0
  132. package/src/Storage.js +175 -47
  133. package/src/Texture.js +58 -67
  134. package/src/TextureAtlas.js +96 -0
  135. package/src/Tilemap.js +274 -0
  136. package/src/Time.js +51 -6
  137. package/src/Timer.js +99 -0
  138. package/src/Transform.js +100 -7
  139. package/src/Tween.js +160 -0
  140. package/src/UI.js +394 -0
  141. package/src/components/Behaviour.js +90 -0
  142. package/src/components/BoxCollider.js +29 -12
  143. package/src/components/BoxColliderDebug.js +3 -4
  144. package/src/components/CircleCollider.js +26 -12
  145. package/src/components/CircleColliderDebug.js +25 -24
  146. package/src/components/Collider.js +150 -34
  147. package/src/components/GameObject.js +130 -21
  148. package/src/components/PolygonCollider.js +55 -0
  149. package/src/components/RigidBody.js +556 -8
  150. package/src/importers/Aseprite.js +142 -0
  151. package/src/importers/ForgeLevel.js +581 -0
  152. package/src/importers/TiledMap.js +158 -0
  153. package/src/lights/DirectionalLight.js +6 -15
  154. package/src/lights/PointLight.js +4 -4
  155. package/src/managers/AssetManager.js +239 -0
  156. package/src/managers/AudioManager.js +565 -146
  157. package/src/managers/EventManager.js +488 -477
  158. package/src/managers/GLManager.js +57 -0
  159. package/src/managers/GLState.js +70 -0
  160. package/src/managers/Gamepad.js +126 -0
  161. package/src/managers/IDManager.js +24 -2
  162. package/src/managers/InputManager.js +905 -0
  163. package/src/managers/NetworkManager.js +178 -0
  164. package/src/managers/RenderStats.js +34 -0
  165. package/src/managers/SceneManager.js +30 -0
  166. package/src/managers/ShaderManager.js +0 -2
  167. package/src/managers/TextureManager.js +218 -0
  168. package/src/particlesystem/Particle.js +82 -7
  169. package/src/particlesystem/ParticleSettings.js +21 -3
  170. package/src/particlesystem/Particles.js +80 -31
  171. package/src/physics/AABB.js +207 -0
  172. package/src/physics/Body.js +862 -0
  173. package/src/physics/BodyType.js +16 -0
  174. package/src/physics/BroadPhase.js +641 -0
  175. package/src/physics/Collision.js +534 -0
  176. package/src/physics/Contact.js +500 -0
  177. package/src/physics/ContactSolver.js +526 -0
  178. package/src/physics/Distance.js +403 -0
  179. package/src/physics/DistanceJoint.js +227 -0
  180. package/src/physics/Fixture.js +346 -0
  181. package/src/physics/Island.js +203 -0
  182. package/src/physics/Joint.js +78 -0
  183. package/src/physics/Math2D.js +573 -0
  184. package/src/physics/RevoluteJoint.js +278 -0
  185. package/src/physics/Settings.js +78 -0
  186. package/src/physics/Shapes.js +549 -0
  187. package/src/physics/TimeOfImpact.js +87 -0
  188. package/src/physics/World.js +731 -0
  189. package/src/physics/index.js +79 -0
  190. package/dist/types/Drawable.d.ts +0 -157
  191. package/dist/types/Emerald.d.ts +0 -73
  192. package/dist/types/GLUtils.d.ts +0 -6
  193. package/dist/types/Physics.d.ts +0 -139
  194. package/dist/types/Scene.d.ts +0 -39
  195. package/dist/types/Shaders.d.ts +0 -4
  196. package/dist/types/Storage.d.ts +0 -46
  197. package/dist/types/Time.d.ts +0 -22
  198. package/dist/types/Transform.d.ts +0 -41
  199. package/dist/types/components/BoxColliderDebug.d.ts +0 -19
  200. package/dist/types/components/CircleColliderDebug.d.ts +0 -19
  201. package/dist/types/components/Collider.d.ts +0 -53
  202. package/dist/types/components/GameObject.d.ts +0 -72
  203. package/dist/types/components/RigidBody.d.ts +0 -104
  204. package/dist/types/managers/AudioManager.d.ts +0 -60
  205. package/dist/types/managers/GLManager.d.ts +0 -47
  206. package/dist/types/managers/IDManager.d.ts +0 -21
  207. package/dist/types/managers/SceneManager.d.ts +0 -22
  208. package/dist/types/particlesystem/Particle.d.ts +0 -42
@@ -0,0 +1,221 @@
1
+ /**
2
+ * @class Fixture
3
+ * @description A shape bound to a body, together with the material properties
4
+ * that decide how contacts behave: density (which feeds the body's mass),
5
+ * friction, restitution (bounciness), the sensor flag, and the collision
6
+ * filter. A body can carry any number of fixtures.
7
+ *
8
+ * Fixtures are created through {@link Body#createFixture}, never directly.
9
+ */
10
+ export class Fixture {
11
+ constructor(body: any, shape: any, def?: {});
12
+ body: any;
13
+ shape: any;
14
+ density: any;
15
+ friction: any;
16
+ restitution: any;
17
+ sensor: boolean;
18
+ userData: any;
19
+ filter: {
20
+ categoryBits: any;
21
+ maskBits: any;
22
+ groupIndex: any;
23
+ };
24
+ /** @private */
25
+ private proxies;
26
+ /** @private */
27
+ private next;
28
+ /**
29
+ * @method getType
30
+ * @description Returns the underlying shape type ("circle" or "polygon").
31
+ * @returns {string}
32
+ */
33
+ getType(): string;
34
+ /**
35
+ * @method getShape
36
+ * @description Returns the fixture's shape.
37
+ * @returns {Shape}
38
+ */
39
+ getShape(): Shape;
40
+ /**
41
+ * @method getBody
42
+ * @description Returns the body this fixture is attached to.
43
+ * @returns {Body}
44
+ */
45
+ getBody(): Body;
46
+ /**
47
+ * @method getNext
48
+ * @description Returns the next fixture on the same body, or null.
49
+ * @returns {Fixture|null}
50
+ */
51
+ getNext(): Fixture | null;
52
+ /**
53
+ * @method setUserData
54
+ * @description Attaches arbitrary data to the fixture.
55
+ * @param {*} data
56
+ */
57
+ setUserData(data: any): void;
58
+ /**
59
+ * @method getUserData
60
+ * @description Returns the attached data.
61
+ * @returns {*}
62
+ */
63
+ getUserData(): any;
64
+ /**
65
+ * @method setSensor
66
+ * @description A sensor still reports contacts but never generates a
67
+ * collision response: the classic trigger volume.
68
+ * @param {boolean} value
69
+ */
70
+ setSensor(value: boolean): void;
71
+ /**
72
+ * @method isSensor
73
+ * @description Whether this fixture is a sensor.
74
+ * @returns {boolean}
75
+ */
76
+ isSensor(): boolean;
77
+ /**
78
+ * @method setFilterData
79
+ * @description Replaces the collision filter. Two fixtures collide only when
80
+ * each one's category bit appears in the other's mask (or they share a
81
+ * positive group index).
82
+ * @param {Object} filter - `{ categoryBits, maskBits, groupIndex }`
83
+ */
84
+ setFilterData(filter?: any): void;
85
+ /**
86
+ * @method getFilterData
87
+ * @description Returns the current collision filter.
88
+ * @returns {Object}
89
+ */
90
+ getFilterData(): any;
91
+ /**
92
+ * @method getFilterCategoryBits
93
+ * @description Returns the category bits.
94
+ * @returns {number}
95
+ */
96
+ getFilterCategoryBits(): number;
97
+ /**
98
+ * @method getFilterMaskBits
99
+ * @description Returns the mask bits.
100
+ * @returns {number}
101
+ */
102
+ getFilterMaskBits(): number;
103
+ /**
104
+ * @method getFilterGroupIndex
105
+ * @description Returns the group index.
106
+ * @returns {number}
107
+ */
108
+ getFilterGroupIndex(): number;
109
+ /**
110
+ * @method refilter
111
+ * @description Re-evaluates existing contacts after a filter change, so a
112
+ * fixture that just stopped colliding with a layer separates immediately
113
+ * instead of on its next move.
114
+ */
115
+ refilter(): void;
116
+ /**
117
+ * @method setDensity
118
+ * @description Sets the density. Call {@link Body#resetMassData} afterwards
119
+ * for it to take effect on the body's mass.
120
+ * @param {number} density
121
+ */
122
+ setDensity(density: number): void;
123
+ /**
124
+ * @method getDensity
125
+ * @description Returns the density.
126
+ * @returns {number}
127
+ */
128
+ getDensity(): number;
129
+ /**
130
+ * @method setFriction
131
+ * @description Sets the friction coefficient (0 = ice).
132
+ * @param {number} friction
133
+ */
134
+ setFriction(friction: number): void;
135
+ /**
136
+ * @method getFriction
137
+ * @description Returns the friction coefficient.
138
+ * @returns {number}
139
+ */
140
+ getFriction(): number;
141
+ /**
142
+ * @method setRestitution
143
+ * @description Sets the bounciness (0 = no bounce, 1 = perfectly elastic).
144
+ * @param {number} restitution
145
+ */
146
+ setRestitution(restitution: number): void;
147
+ /**
148
+ * @method getRestitution
149
+ * @description Returns the bounciness.
150
+ * @returns {number}
151
+ */
152
+ getRestitution(): number;
153
+ /**
154
+ * @method testPoint
155
+ * @description True when a world-space point is inside this fixture.
156
+ * @param {Object} p - `{ x, y }` in physics units
157
+ * @returns {boolean}
158
+ */
159
+ testPoint(p: any): boolean;
160
+ /**
161
+ * @method rayCast
162
+ * @description Casts a ray against this fixture's shape.
163
+ * @param {Object} output - Written as `{ fraction, normal }` on a hit
164
+ * @param {Object} input - `{ p1, p2, maxFraction }`
165
+ * @returns {boolean}
166
+ */
167
+ rayCast(output: any, input: any): boolean;
168
+ /**
169
+ * @method getMassData
170
+ * @description Computes this fixture's contribution to the body's mass.
171
+ * @param {Object} [massData]
172
+ * @returns {Object} - `{ mass, center, I }`
173
+ */
174
+ getMassData(massData?: any): any;
175
+ /**
176
+ * @method getAABB
177
+ * @description Returns the fixture's current world AABB.
178
+ * @param {number} [childIndex=0]
179
+ * @returns {AABB}
180
+ */
181
+ getAABB(childIndex?: number): AABB;
182
+ /**
183
+ * @method createProxies
184
+ * @description Registers this fixture with the broadphase.
185
+ * @param {BroadPhase} broadPhase
186
+ * @param {Transform2} xf
187
+ * @private
188
+ */
189
+ private createProxies;
190
+ /**
191
+ * @method destroyProxies
192
+ * @description Removes this fixture from the broadphase.
193
+ * @param {BroadPhase} broadPhase
194
+ * @private
195
+ */
196
+ private destroyProxies;
197
+ /**
198
+ * @method synchronize
199
+ * @description Re-fits the broadphase proxies after the body moved. The AABB
200
+ * spans both the old and the new transform so a fast body's proxy still
201
+ * covers the ground it swept over.
202
+ * @param {BroadPhase} broadPhase
203
+ * @param {Transform2} xf1
204
+ * @param {Transform2} xf2
205
+ * @private
206
+ */
207
+ private synchronize;
208
+ }
209
+ /**
210
+ * @class FixtureProxy
211
+ * @description The link between a fixture and its entry in the broadphase tree.
212
+ * @private
213
+ */
214
+ export class FixtureProxy {
215
+ constructor(fixture: any, childIndex: any);
216
+ aabb: AABB;
217
+ fixture: any;
218
+ childIndex: any;
219
+ proxyId: number;
220
+ }
221
+ import AABB from "./AABB.js";
@@ -0,0 +1,52 @@
1
+ export default Island;
2
+ /**
3
+ * @class Island
4
+ * @description A connected group of bodies, everything reachable through
5
+ * touching contacts, solved together. Islands are what make sleeping work:
6
+ * a pile of crates only goes to sleep once *every* body in it has settled, so
7
+ * one crate still rolling keeps the whole pile simulated.
8
+ */
9
+ declare class Island {
10
+ bodies: any[];
11
+ contacts: any[];
12
+ joints: any[];
13
+ /** @private */
14
+ private positions;
15
+ /** @private */
16
+ private velocities;
17
+ /**
18
+ * @method clear
19
+ * @description Empties the island for reuse on the next seed body.
20
+ */
21
+ clear(): void;
22
+ /**
23
+ * @method addBody
24
+ * @description Adds a body and records its index for the solver.
25
+ * @param {Body} body
26
+ */
27
+ addBody(body: Body): void;
28
+ /**
29
+ * @method addContact
30
+ * @description Adds a touching contact to be solved with this island.
31
+ * @param {Contact} contact
32
+ */
33
+ addContact(contact: Contact): void;
34
+ /**
35
+ * @method addJoint
36
+ * @description Adds a joint to be solved with this island.
37
+ * @param {Joint} joint
38
+ */
39
+ addJoint(joint: Joint): void;
40
+ /**
41
+ * @method solve
42
+ * @description Advances the island by one step: integrate velocities, solve
43
+ * contacts, integrate positions, fix leftover overlap, then decide whether
44
+ * the island can go to sleep.
45
+ * @param {Object} step - `{ dt, velocityIterations, positionIterations,
46
+ * warmStarting, velocityThreshold }`
47
+ * @param {Vec2} gravity - World gravity in physics units
48
+ * @param {boolean} allowSleep - Whether sleeping is enabled world-wide
49
+ */
50
+ solve(step: any, gravity: Vec2, allowSleep: boolean): void;
51
+ }
52
+ import { Vec2 } from "./Math2D.js";
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @class Joint
3
+ * @description Base class for a constraint between two bodies. A joint is
4
+ * solved by the same island that solves contacts (see {@link Island}), right
5
+ * alongside them, so a body linked only by a joint (no touching fixtures)
6
+ * still wakes, sleeps and moves together with whatever it is jointed to.
7
+ *
8
+ * Concrete joints ({@link DistanceJoint}, {@link RevoluteJoint}) implement
9
+ * `initVelocityConstraints`, `solveVelocityConstraints` and
10
+ * `solvePositionConstraints`, matching {@link ContactSolver}'s per-step
11
+ * lifecycle.
12
+ * @param {Object} def - `{ type, bodyA, bodyB, collideConnected, userData }`
13
+ */
14
+ export class Joint {
15
+ constructor(def: any);
16
+ type: any;
17
+ bodyA: any;
18
+ bodyB: any;
19
+ collideConnected: any;
20
+ userData: any;
21
+ /** @private */
22
+ private islandFlag;
23
+ /** @private */
24
+ private prev;
25
+ /** @private */
26
+ private next;
27
+ /**
28
+ * @method getType
29
+ * @returns {string}
30
+ */
31
+ getType(): string;
32
+ /**
33
+ * @method getBodyA
34
+ * @returns {Body}
35
+ */
36
+ getBodyA(): Body;
37
+ /**
38
+ * @method getBodyB
39
+ * @returns {Body}
40
+ */
41
+ getBodyB(): Body;
42
+ /**
43
+ * @method getUserData
44
+ * @returns {*}
45
+ */
46
+ getUserData(): any;
47
+ /**
48
+ * @method setUserData
49
+ * @param {*} data
50
+ */
51
+ setUserData(data: any): void;
52
+ }
53
+ /**
54
+ * @description Identifies a concrete {@link Joint} subclass.
55
+ */
56
+ export const JointType: Readonly<{
57
+ DISTANCE: "distance";
58
+ REVOLUTE: "revolute";
59
+ }>;
@@ -0,0 +1,371 @@
1
+ /**
2
+ * @file Math primitives for the Emerald physics engine.
3
+ * @description Everything here works in *physics units* (meters, radians), not
4
+ * world/pixel units. The conversion happens in {@link Physics} and
5
+ * {@link RigidBody}, so nothing below ever needs to know about the pixel scale.
6
+ */
7
+ /**
8
+ * @class Vec2
9
+ * @description A 2D vector in physics space. Instance methods mutate in place
10
+ * (used in the hot solver paths); the statics allocate a new vector. Accepts
11
+ * either two numbers or any `{ x, y }` object.
12
+ * @param {number|Object} [x=0] - The x coordinate, or an `{ x, y }` object
13
+ * @param {number} [y=0] - The y coordinate
14
+ */
15
+ export class Vec2 {
16
+ /**
17
+ * @method zero
18
+ * @description Returns a fresh zero vector.
19
+ * @returns {Vec2}
20
+ */
21
+ static zero(): Vec2;
22
+ /**
23
+ * @method add
24
+ * @description a + b as a new vector.
25
+ * @param {Object} a
26
+ * @param {Object} b
27
+ * @returns {Vec2}
28
+ */
29
+ static add(a: any, b: any): Vec2;
30
+ /**
31
+ * @method sub
32
+ * @description a - b as a new vector.
33
+ * @param {Object} a
34
+ * @param {Object} b
35
+ * @returns {Vec2}
36
+ */
37
+ static sub(a: any, b: any): Vec2;
38
+ /**
39
+ * @method mul
40
+ * @description s * v as a new vector (either argument order works).
41
+ * @param {number|Object} a
42
+ * @param {number|Object} b
43
+ * @returns {Vec2}
44
+ */
45
+ static mul(a: number | any, b: number | any): Vec2;
46
+ /**
47
+ * @method combine
48
+ * @description sa * a + sb * b as a new vector.
49
+ * @param {number} sa
50
+ * @param {Object} a
51
+ * @param {number} sb
52
+ * @param {Object} b
53
+ * @returns {Vec2}
54
+ */
55
+ static combine(sa: number, a: any, sb: number, b: any): Vec2;
56
+ /**
57
+ * @method neg
58
+ * @description -v as a new vector.
59
+ * @param {Object} v
60
+ * @returns {Vec2}
61
+ */
62
+ static neg(v: any): Vec2;
63
+ /**
64
+ * @method dot
65
+ * @description Dot product.
66
+ * @param {Object} a
67
+ * @param {Object} b
68
+ * @returns {number}
69
+ */
70
+ static dot(a: any, b: any): number;
71
+ /**
72
+ * @method cross
73
+ * @description 2D cross product (the z of the 3D cross): a.x*b.y - a.y*b.x.
74
+ * @param {Object} a
75
+ * @param {Object} b
76
+ * @returns {number}
77
+ */
78
+ static cross(a: any, b: any): number;
79
+ /**
80
+ * @method crossVS
81
+ * @description Cross of a vector with a scalar: (v.y * s, -v.x * s).
82
+ * @param {Object} v
83
+ * @param {number} s
84
+ * @returns {Vec2}
85
+ */
86
+ static crossVS(v: any, s: number): Vec2;
87
+ /**
88
+ * @method crossSV
89
+ * @description Cross of a scalar with a vector: (-s * v.y, s * v.x). This is
90
+ * how angular velocity turns into linear velocity at an offset.
91
+ * @param {number} s
92
+ * @param {Object} v
93
+ * @returns {Vec2}
94
+ */
95
+ static crossSV(s: number, v: any): Vec2;
96
+ /**
97
+ * @method distance
98
+ * @description Distance between two points.
99
+ * @param {Object} a
100
+ * @param {Object} b
101
+ * @returns {number}
102
+ */
103
+ static distance(a: any, b: any): number;
104
+ /**
105
+ * @method distanceSquared
106
+ * @description Squared distance between two points.
107
+ * @param {Object} a
108
+ * @param {Object} b
109
+ * @returns {number}
110
+ */
111
+ static distanceSquared(a: any, b: any): number;
112
+ /**
113
+ * @method lerp
114
+ * @description Linear interpolation between two points.
115
+ * @param {Object} a
116
+ * @param {Object} b
117
+ * @param {number} t
118
+ * @returns {Vec2}
119
+ */
120
+ static lerp(a: any, b: any, t: number): Vec2;
121
+ constructor(x?: number, y?: number);
122
+ x: any;
123
+ y: any;
124
+ /**
125
+ * @method set
126
+ * @description Sets both components in place.
127
+ * @param {number} x
128
+ * @param {number} y
129
+ * @returns {Vec2} - this
130
+ */
131
+ set(x: number, y: number): Vec2;
132
+ /**
133
+ * @method copy
134
+ * @description Copies another vector's components into this one.
135
+ * @param {Object} v - Any `{ x, y }`
136
+ * @returns {Vec2} - this
137
+ */
138
+ copy(v: any): Vec2;
139
+ /**
140
+ * @method clone
141
+ * @description Returns an independent copy.
142
+ * @returns {Vec2}
143
+ */
144
+ clone(): Vec2;
145
+ /**
146
+ * @method setZero
147
+ * @description Zeroes both components in place.
148
+ * @returns {Vec2} - this
149
+ */
150
+ setZero(): Vec2;
151
+ /**
152
+ * @method add
153
+ * @description Adds another vector in place.
154
+ * @param {Object} v
155
+ * @returns {Vec2} - this
156
+ */
157
+ add(v: any): Vec2;
158
+ /**
159
+ * @method addMul
160
+ * @description Adds `s * v` in place. The workhorse of the solver.
161
+ * @param {number} s
162
+ * @param {Object} v
163
+ * @returns {Vec2} - this
164
+ */
165
+ addMul(s: number, v: any): Vec2;
166
+ /**
167
+ * @method sub
168
+ * @description Subtracts another vector in place.
169
+ * @param {Object} v
170
+ * @returns {Vec2} - this
171
+ */
172
+ sub(v: any): Vec2;
173
+ /**
174
+ * @method subMul
175
+ * @description Subtracts `s * v` in place.
176
+ * @param {number} s
177
+ * @param {Object} v
178
+ * @returns {Vec2} - this
179
+ */
180
+ subMul(s: number, v: any): Vec2;
181
+ /**
182
+ * @method mul
183
+ * @description Scales in place.
184
+ * @param {number} s
185
+ * @returns {Vec2} - this
186
+ */
187
+ mul(s: number): Vec2;
188
+ /**
189
+ * @method neg
190
+ * @description Negates in place.
191
+ * @returns {Vec2} - this
192
+ */
193
+ neg(): Vec2;
194
+ /**
195
+ * @method length
196
+ * @description Euclidean length.
197
+ * @returns {number}
198
+ */
199
+ length(): number;
200
+ /**
201
+ * @method lengthSquared
202
+ * @description Squared length (no sqrt).
203
+ * @returns {number}
204
+ */
205
+ lengthSquared(): number;
206
+ /**
207
+ * @method normalize
208
+ * @description Normalizes in place and returns the previous length. A
209
+ * zero-length vector is left untouched (and reports 0).
210
+ * @returns {number} - The length before normalizing
211
+ */
212
+ normalize(): number;
213
+ /**
214
+ * @method isValid
215
+ * @description True when both components are finite.
216
+ * @returns {boolean}
217
+ */
218
+ isValid(): boolean;
219
+ }
220
+ /**
221
+ * @class Rot
222
+ * @description A 2D rotation stored as sine/cosine, so rotating a vector never
223
+ * needs a trig call in the inner loop.
224
+ * @param {number} [angle=0] - Angle in radians
225
+ */
226
+ export class Rot {
227
+ /**
228
+ * @method mulVec
229
+ * @description Rotates a vector by `q` into a new vector.
230
+ * @param {Rot} q
231
+ * @param {Object} v
232
+ * @returns {Vec2}
233
+ */
234
+ static mulVec(q: Rot, v: any): Vec2;
235
+ /**
236
+ * @method mulTVec
237
+ * @description Inverse-rotates a vector by `q` (world direction -> local).
238
+ * @param {Rot} q
239
+ * @param {Object} v
240
+ * @returns {Vec2}
241
+ */
242
+ static mulTVec(q: Rot, v: any): Vec2;
243
+ constructor(angle?: number);
244
+ s: number;
245
+ c: number;
246
+ /**
247
+ * @method set
248
+ * @description Sets the rotation from an angle in radians.
249
+ * @param {number} angle
250
+ * @returns {Rot} - this
251
+ */
252
+ set(angle: number): Rot;
253
+ /**
254
+ * @method copy
255
+ * @description Copies another rotation.
256
+ * @param {Rot} r
257
+ * @returns {Rot} - this
258
+ */
259
+ copy(r: Rot): Rot;
260
+ /**
261
+ * @method setIdentity
262
+ * @description Resets to zero rotation.
263
+ * @returns {Rot} - this
264
+ */
265
+ setIdentity(): Rot;
266
+ /**
267
+ * @method getAngle
268
+ * @description Returns the angle in radians.
269
+ * @returns {number}
270
+ */
271
+ getAngle(): number;
272
+ }
273
+ /**
274
+ * @class Transform2
275
+ * @description A rigid transform: a translation `p` plus a rotation `q`. Named
276
+ * Transform2 so it never collides with the engine's renderable `Transform`.
277
+ */
278
+ export class Transform2 {
279
+ /**
280
+ * @method mulVec
281
+ * @description Transforms a local point into world space.
282
+ * @param {Transform2} xf
283
+ * @param {Object} v
284
+ * @returns {Vec2}
285
+ */
286
+ static mulVec(xf: Transform2, v: any): Vec2;
287
+ /**
288
+ * @method mulTVec
289
+ * @description Transforms a world point into local space.
290
+ * @param {Transform2} xf
291
+ * @param {Object} v
292
+ * @returns {Vec2}
293
+ */
294
+ static mulTVec(xf: Transform2, v: any): Vec2;
295
+ p: Vec2;
296
+ q: Rot;
297
+ /**
298
+ * @method setIdentity
299
+ * @description Resets to the identity transform.
300
+ * @returns {Transform2} - this
301
+ */
302
+ setIdentity(): Transform2;
303
+ /**
304
+ * @method set
305
+ * @description Sets position and angle.
306
+ * @param {Object} position
307
+ * @param {number} angle
308
+ * @returns {Transform2} - this
309
+ */
310
+ set(position: any, angle: number): Transform2;
311
+ /**
312
+ * @method copy
313
+ * @description Copies another transform.
314
+ * @param {Transform2} xf
315
+ * @returns {Transform2} - this
316
+ */
317
+ copy(xf: Transform2): Transform2;
318
+ }
319
+ /**
320
+ * @class Sweep
321
+ * @description The motion of a body's center of mass across one step, used by
322
+ * continuous collision detection to reconstruct where the body was at any
323
+ * fraction of the step.
324
+ */
325
+ export class Sweep {
326
+ /** Local center of mass */
327
+ localCenter: Vec2;
328
+ /** World center at the start of the step */
329
+ c0: Vec2;
330
+ /** World center now */
331
+ c: Vec2;
332
+ /** Angle at the start of the step */
333
+ a0: number;
334
+ /** Angle now */
335
+ a: number;
336
+ /** Fraction of the step `c0`/`a0` correspond to (0..1) */
337
+ alpha0: number;
338
+ /**
339
+ * @method getTransform
340
+ * @description Writes the body transform at fraction `beta` of the sweep into
341
+ * `xf`. beta 0 is the start of the (remaining) sweep, 1 is the end.
342
+ * @param {Transform2} xf - Output transform
343
+ * @param {number} beta - Interpolation fraction
344
+ * @returns {Transform2} - xf
345
+ */
346
+ getTransform(xf: Transform2, beta: number): Transform2;
347
+ /**
348
+ * @method advance
349
+ * @description Moves the start of the sweep forward to fraction `alpha` of
350
+ * the original span, so later TOI queries only consider the remaining motion.
351
+ * @param {number} alpha - Absolute fraction of the original sweep
352
+ */
353
+ advance(alpha: number): void;
354
+ /**
355
+ * @method normalize
356
+ * @description Keeps the sweep angles near zero so long-lived spinning bodies
357
+ * don't lose float precision.
358
+ */
359
+ normalize(): void;
360
+ }
361
+ /**
362
+ * @function clamp
363
+ * @description Clamps a number to [min, max].
364
+ * @param {number} value
365
+ * @param {number} min
366
+ * @param {number} max
367
+ * @returns {number}
368
+ * @private
369
+ */
370
+ export function clamp(value: number, min: number, max: number): number;
371
+ export const EPSILON: 1.1920929e-7;