emeraldengine 3.0.0 → 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.
- package/README.md +1498 -1659
- package/dist/types/index.d.ts +4 -1
- package/dist/types/src/Animator.d.ts +1 -1
- package/dist/types/src/CollisionLayers.d.ts +2 -2
- package/dist/types/src/Color.d.ts +1 -0
- package/dist/types/src/Drawable.d.ts +1 -1
- package/dist/types/src/EmeraldDB.d.ts +2 -2
- package/dist/types/src/InstancedTexture.d.ts +17 -2
- package/dist/types/src/Material.d.ts +2 -2
- package/dist/types/src/MathUtils.d.ts +2 -1
- package/dist/types/src/ParticleEmitter.d.ts +1 -1
- package/dist/types/src/Physics.d.ts +148 -18
- package/dist/types/src/Scene.d.ts +1 -1
- package/dist/types/src/Shaders.d.ts +2 -2
- package/dist/types/src/Tilemap.d.ts +1 -1
- package/dist/types/src/UI.d.ts +1 -1
- package/dist/types/src/components/Behaviour.d.ts +2 -2
- package/dist/types/src/components/Collider.d.ts +7 -1
- package/dist/types/src/components/GameObject.d.ts +2 -2
- package/dist/types/src/components/PolygonCollider.d.ts +33 -0
- package/dist/types/src/components/RigidBody.d.ts +281 -8
- package/dist/types/src/importers/Aseprite.d.ts +2 -2
- package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
- package/dist/types/src/importers/TiledMap.d.ts +1 -1
- package/dist/types/src/managers/EventManager.d.ts +1 -1
- package/dist/types/src/managers/Gamepad.d.ts +102 -0
- package/dist/types/src/managers/InputManager.d.ts +93 -2
- package/dist/types/src/managers/NetworkManager.d.ts +2 -2
- package/dist/types/src/managers/RenderStats.d.ts +1 -1
- package/dist/types/src/managers/TextureManager.d.ts +1 -1
- package/dist/types/src/physics/AABB.d.ts +92 -0
- package/dist/types/src/physics/Body.d.ts +435 -0
- package/dist/types/src/physics/BodyType.d.ts +6 -0
- package/dist/types/src/physics/BroadPhase.d.ts +210 -0
- package/dist/types/src/physics/Collision.d.ts +102 -0
- package/dist/types/src/physics/Contact.d.ts +206 -0
- package/dist/types/src/physics/ContactSolver.d.ts +108 -0
- package/dist/types/src/physics/Distance.d.ts +54 -0
- package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
- package/dist/types/src/physics/Fixture.d.ts +221 -0
- package/dist/types/src/physics/Island.d.ts +52 -0
- package/dist/types/src/physics/Joint.d.ts +59 -0
- package/dist/types/src/physics/Math2D.d.ts +371 -0
- package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
- package/dist/types/src/physics/Settings.d.ts +22 -0
- package/dist/types/src/physics/Shapes.d.ts +207 -0
- package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
- package/dist/types/src/physics/World.d.ts +274 -0
- package/dist/types/src/physics/index.d.ts +34 -0
- package/index.js +6 -0
- package/package.json +2 -3
- package/src/Animator.js +1 -1
- package/src/CollisionLayers.js +3 -3
- package/src/Color.js +8 -0
- package/src/Drawable.js +1 -1
- package/src/Emerald.js +1 -1
- package/src/EmeraldDB.js +2 -2
- package/src/InstancedTexture.js +57 -9
- package/src/Material.js +2 -2
- package/src/MathUtils.js +2 -1
- package/src/ParticleEmitter.js +1 -1
- package/src/Physics.js +270 -60
- package/src/Scene.js +1 -1
- package/src/Shaders.js +20 -20
- package/src/Tilemap.js +1 -1
- package/src/UI.js +1 -1
- package/src/components/Behaviour.js +2 -2
- package/src/components/BoxCollider.js +7 -9
- package/src/components/BoxColliderDebug.js +3 -4
- package/src/components/CircleCollider.js +7 -9
- package/src/components/CircleColliderDebug.js +3 -2
- package/src/components/Collider.js +13 -3
- package/src/components/GameObject.js +2 -2
- package/src/components/PolygonCollider.js +55 -0
- package/src/components/RigidBody.js +441 -14
- package/src/importers/Aseprite.js +2 -2
- package/src/importers/ForgeLevel.js +581 -0
- package/src/importers/TiledMap.js +1 -1
- package/src/managers/EventManager.js +1 -1
- package/src/managers/Gamepad.js +126 -0
- package/src/managers/InputManager.js +129 -3
- package/src/managers/NetworkManager.js +2 -2
- package/src/managers/RenderStats.js +1 -1
- package/src/managers/TextureManager.js +1 -1
- package/src/physics/AABB.js +207 -0
- package/src/physics/Body.js +862 -0
- package/src/physics/BodyType.js +16 -0
- package/src/physics/BroadPhase.js +641 -0
- package/src/physics/Collision.js +534 -0
- package/src/physics/Contact.js +500 -0
- package/src/physics/ContactSolver.js +526 -0
- package/src/physics/Distance.js +403 -0
- package/src/physics/DistanceJoint.js +227 -0
- package/src/physics/Fixture.js +346 -0
- package/src/physics/Island.js +203 -0
- package/src/physics/Joint.js +78 -0
- package/src/physics/Math2D.js +573 -0
- package/src/physics/RevoluteJoint.js +278 -0
- package/src/physics/Settings.js +78 -0
- package/src/physics/Shapes.js +549 -0
- package/src/physics/TimeOfImpact.js +87 -0
- package/src/physics/World.js +731 -0
- package/src/physics/index.js +79 -0
|
@@ -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;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export default RevoluteJoint;
|
|
2
|
+
/**
|
|
3
|
+
* @class RevoluteJoint
|
|
4
|
+
* @extends Joint
|
|
5
|
+
* @description Pins two bodies together at a shared point while leaving
|
|
6
|
+
* rotation free, like a door hinge or a pendulum arm. Optionally driven by a
|
|
7
|
+
* motor that spins the joint toward a target angular speed, up to a torque
|
|
8
|
+
* limit; set `enableMotor` for a turntable, a windmill blade, or a wheel.
|
|
9
|
+
* @param {Object} def - `{ bodyA, bodyB, localAnchorA, localAnchorB,
|
|
10
|
+
* enableMotor, motorSpeed, maxMotorTorque, collideConnected, userData }`
|
|
11
|
+
*/
|
|
12
|
+
declare class RevoluteJoint extends Joint {
|
|
13
|
+
localAnchorA: Vec2;
|
|
14
|
+
localAnchorB: Vec2;
|
|
15
|
+
referenceAngle: any;
|
|
16
|
+
enableMotor: boolean;
|
|
17
|
+
motorSpeed: any;
|
|
18
|
+
maxMotorTorque: any;
|
|
19
|
+
impulse: Vec2;
|
|
20
|
+
motorImpulse: number;
|
|
21
|
+
axialMass: number;
|
|
22
|
+
motorMass: number;
|
|
23
|
+
K: {
|
|
24
|
+
k11: number;
|
|
25
|
+
k12: number;
|
|
26
|
+
k22: number;
|
|
27
|
+
};
|
|
28
|
+
rA: Vec2;
|
|
29
|
+
rB: Vec2;
|
|
30
|
+
/** @private */
|
|
31
|
+
private indexA;
|
|
32
|
+
/** @private */
|
|
33
|
+
private indexB;
|
|
34
|
+
/**
|
|
35
|
+
* @method getAnchorA
|
|
36
|
+
* @returns {Vec2}
|
|
37
|
+
*/
|
|
38
|
+
getAnchorA(): Vec2;
|
|
39
|
+
/**
|
|
40
|
+
* @method getAnchorB
|
|
41
|
+
* @returns {Vec2}
|
|
42
|
+
*/
|
|
43
|
+
getAnchorB(): Vec2;
|
|
44
|
+
/**
|
|
45
|
+
* @method getReactionForce
|
|
46
|
+
* @param {number} invDt
|
|
47
|
+
* @returns {Vec2}
|
|
48
|
+
*/
|
|
49
|
+
getReactionForce(invDt: number): Vec2;
|
|
50
|
+
/**
|
|
51
|
+
* @method getReactionTorque
|
|
52
|
+
* @param {number} invDt
|
|
53
|
+
* @returns {number}
|
|
54
|
+
*/
|
|
55
|
+
getReactionTorque(invDt: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* @method getJointAngle
|
|
58
|
+
* @description Current angle of body B relative to body A, minus the angle
|
|
59
|
+
* they started at.
|
|
60
|
+
* @returns {number}
|
|
61
|
+
*/
|
|
62
|
+
getJointAngle(): number;
|
|
63
|
+
/**
|
|
64
|
+
* @method setMotorSpeed
|
|
65
|
+
* @param {number} speed
|
|
66
|
+
*/
|
|
67
|
+
setMotorSpeed(speed: number): void;
|
|
68
|
+
/**
|
|
69
|
+
* @method getMotorSpeed
|
|
70
|
+
* @returns {number}
|
|
71
|
+
*/
|
|
72
|
+
getMotorSpeed(): number;
|
|
73
|
+
/**
|
|
74
|
+
* @method setMaxMotorTorque
|
|
75
|
+
* @param {number} torque
|
|
76
|
+
*/
|
|
77
|
+
setMaxMotorTorque(torque: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* @method setEnableMotor
|
|
80
|
+
* @param {boolean} flag
|
|
81
|
+
*/
|
|
82
|
+
setEnableMotor(flag: boolean): void;
|
|
83
|
+
/**
|
|
84
|
+
* @method isMotorEnabled
|
|
85
|
+
* @returns {boolean}
|
|
86
|
+
*/
|
|
87
|
+
isMotorEnabled(): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* @method getMotorTorque
|
|
90
|
+
* @param {number} invDt
|
|
91
|
+
* @returns {number}
|
|
92
|
+
*/
|
|
93
|
+
getMotorTorque(invDt: number): number;
|
|
94
|
+
/**
|
|
95
|
+
* @method initVelocityConstraints
|
|
96
|
+
* @param {Object} step - `{ dt, warmStarting }`
|
|
97
|
+
* @param {Array<Object>} positions
|
|
98
|
+
* @param {Array<Object>} velocities
|
|
99
|
+
*/
|
|
100
|
+
initVelocityConstraints(step: any, positions: Array<any>, velocities: Array<any>): void;
|
|
101
|
+
invMassA: any;
|
|
102
|
+
invMassB: any;
|
|
103
|
+
invIA: any;
|
|
104
|
+
invIB: any;
|
|
105
|
+
/**
|
|
106
|
+
* @method solveVelocityConstraints
|
|
107
|
+
* @param {Object} step - `{ dt }`
|
|
108
|
+
* @param {Array<Object>} velocities
|
|
109
|
+
*/
|
|
110
|
+
solveVelocityConstraints(step: any, velocities: Array<any>): void;
|
|
111
|
+
/**
|
|
112
|
+
* @method solvePositionConstraints
|
|
113
|
+
* @param {Array<Object>} positions
|
|
114
|
+
* @returns {boolean}
|
|
115
|
+
*/
|
|
116
|
+
solvePositionConstraints(positions: Array<any>): boolean;
|
|
117
|
+
}
|
|
118
|
+
import { Joint } from "./Joint.js";
|
|
119
|
+
import { Vec2 } from "./Math2D.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default Settings;
|
|
2
|
+
declare namespace Settings {
|
|
3
|
+
let linearSlop: number;
|
|
4
|
+
let angularSlop: number;
|
|
5
|
+
let polygonRadius: number;
|
|
6
|
+
let maxLinearCorrection: number;
|
|
7
|
+
let maxAngularCorrection: number;
|
|
8
|
+
let maxTranslation: number;
|
|
9
|
+
let maxRotation: number;
|
|
10
|
+
let baumgarte: number;
|
|
11
|
+
let toiBaumgarte: number;
|
|
12
|
+
let velocityThreshold: number;
|
|
13
|
+
let timeToSleep: number;
|
|
14
|
+
let linearSleepTolerance: number;
|
|
15
|
+
let angularSleepTolerance: number;
|
|
16
|
+
let aabbExtension: number;
|
|
17
|
+
let aabbMultiplier: number;
|
|
18
|
+
let velocityIterations: number;
|
|
19
|
+
let positionIterations: number;
|
|
20
|
+
let maxTOIIterations: number;
|
|
21
|
+
let maxTOIPasses: number;
|
|
22
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class Shape
|
|
3
|
+
* @description Base class for collision shapes. A shape is pure geometry in a
|
|
4
|
+
* body's local frame: it carries no position of its own and can be shared
|
|
5
|
+
* between fixtures.
|
|
6
|
+
*/
|
|
7
|
+
export class Shape {
|
|
8
|
+
constructor(type: any, radius: any);
|
|
9
|
+
type: any;
|
|
10
|
+
radius: any;
|
|
11
|
+
/**
|
|
12
|
+
* @method getType
|
|
13
|
+
* @description Returns the shape type ("circle" or "polygon").
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
getType(): string;
|
|
17
|
+
/**
|
|
18
|
+
* @method getRadius
|
|
19
|
+
* @description Returns the shape's skin radius.
|
|
20
|
+
* @returns {number}
|
|
21
|
+
*/
|
|
22
|
+
getRadius(): number;
|
|
23
|
+
}
|
|
24
|
+
export type ShapeType = ShapeType;
|
|
25
|
+
export namespace ShapeType {
|
|
26
|
+
let CIRCLE: string;
|
|
27
|
+
let POLYGON: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @class CircleShape
|
|
31
|
+
* @extends Shape
|
|
32
|
+
* @description A circle, optionally offset from the body origin.
|
|
33
|
+
* @param {number} [radius=0] - Radius in physics units
|
|
34
|
+
* @param {Object} [center] - Local center `{ x, y }`, defaults to the origin
|
|
35
|
+
*/
|
|
36
|
+
export class CircleShape extends Shape {
|
|
37
|
+
constructor(radius?: number, center?: any);
|
|
38
|
+
p: Vec2;
|
|
39
|
+
/**
|
|
40
|
+
* @method getVertexCount
|
|
41
|
+
* @description A circle is a single-point proxy plus a radius.
|
|
42
|
+
* @returns {number}
|
|
43
|
+
*/
|
|
44
|
+
getVertexCount(): number;
|
|
45
|
+
/**
|
|
46
|
+
* @method getVertex
|
|
47
|
+
* @description Returns the circle's local center (its only support point).
|
|
48
|
+
* @returns {Vec2}
|
|
49
|
+
*/
|
|
50
|
+
getVertex(): Vec2;
|
|
51
|
+
/**
|
|
52
|
+
* @method getSupport
|
|
53
|
+
* @description Index of the vertex furthest along a direction (always 0).
|
|
54
|
+
* @returns {number}
|
|
55
|
+
*/
|
|
56
|
+
getSupport(): number;
|
|
57
|
+
/**
|
|
58
|
+
* @method computeAABB
|
|
59
|
+
* @description Writes this shape's world AABB under a transform.
|
|
60
|
+
* @param {AABB} aabb - Output box
|
|
61
|
+
* @param {Transform2} xf - The owning body's transform
|
|
62
|
+
*/
|
|
63
|
+
computeAABB(aabb: AABB, xf: Transform2): void;
|
|
64
|
+
/**
|
|
65
|
+
* @method computeMass
|
|
66
|
+
* @description Writes mass, center and rotational inertia for a density.
|
|
67
|
+
* @param {Object} massData - Output `{ mass, center, I }`
|
|
68
|
+
* @param {number} density
|
|
69
|
+
*/
|
|
70
|
+
computeMass(massData: any, density: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* @method testPoint
|
|
73
|
+
* @description True when a world point is inside the circle.
|
|
74
|
+
* @param {Transform2} xf
|
|
75
|
+
* @param {Object} p - World point
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
testPoint(xf: Transform2, p: any): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* @method rayCast
|
|
81
|
+
* @description Casts a ray against the circle.
|
|
82
|
+
* @param {Object} output - Written as `{ fraction, normal }` on a hit
|
|
83
|
+
* @param {Object} input - `{ p1, p2, maxFraction }` in world space
|
|
84
|
+
* @param {Transform2} xf
|
|
85
|
+
* @returns {boolean} - Whether the ray hit
|
|
86
|
+
*/
|
|
87
|
+
rayCast(output: any, input: any, xf: Transform2): boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @class PolygonShape
|
|
91
|
+
* @extends Shape
|
|
92
|
+
* @description A convex polygon with up to `MAX_VERTICES` corners, wound
|
|
93
|
+
* counter-clockwise. Boxes, by far the common case, come from
|
|
94
|
+
* {@link PolygonShape.box}.
|
|
95
|
+
* @param {Array<Object>} [points] - Optional points to build a convex hull from
|
|
96
|
+
*/
|
|
97
|
+
export class PolygonShape extends Shape {
|
|
98
|
+
/**
|
|
99
|
+
* @method box
|
|
100
|
+
* @description Builds an axis-aligned box from half-extents, optionally
|
|
101
|
+
* offset and rotated in the body's local frame.
|
|
102
|
+
* @param {number} hx - Half width
|
|
103
|
+
* @param {number} hy - Half height
|
|
104
|
+
* @param {Object} [center] - Local center `{ x, y }`
|
|
105
|
+
* @param {number} [angle=0] - Local rotation in radians
|
|
106
|
+
* @returns {PolygonShape}
|
|
107
|
+
*/
|
|
108
|
+
static box(hx: number, hy: number, center?: any, angle?: number): PolygonShape;
|
|
109
|
+
constructor(points?: any);
|
|
110
|
+
vertices: any[];
|
|
111
|
+
normals: any[];
|
|
112
|
+
centroid: Vec2;
|
|
113
|
+
/**
|
|
114
|
+
* @method setAsBox
|
|
115
|
+
* @description Turns this polygon into a box in place.
|
|
116
|
+
* @param {number} hx - Half width
|
|
117
|
+
* @param {number} hy - Half height
|
|
118
|
+
* @param {Object} [center] - Local center `{ x, y }`
|
|
119
|
+
* @param {number} [angle=0] - Local rotation in radians
|
|
120
|
+
* @returns {PolygonShape} - this
|
|
121
|
+
*/
|
|
122
|
+
setAsBox(hx: number, hy: number, center?: any, angle?: number): PolygonShape;
|
|
123
|
+
/**
|
|
124
|
+
* @method set
|
|
125
|
+
* @description Builds the convex hull of a point cloud. Points inside the
|
|
126
|
+
* hull are dropped, so callers can pass a rough outline.
|
|
127
|
+
* @param {Array<Object>} points - `{ x, y }` points
|
|
128
|
+
* @returns {PolygonShape} - this
|
|
129
|
+
*/
|
|
130
|
+
set(points: Array<any>): PolygonShape;
|
|
131
|
+
/**
|
|
132
|
+
* @method getVertexCount
|
|
133
|
+
* @description Number of corners.
|
|
134
|
+
* @returns {number}
|
|
135
|
+
*/
|
|
136
|
+
getVertexCount(): number;
|
|
137
|
+
/**
|
|
138
|
+
* @method getVertex
|
|
139
|
+
* @description Returns a corner by index.
|
|
140
|
+
* @param {number} index
|
|
141
|
+
* @returns {Vec2}
|
|
142
|
+
*/
|
|
143
|
+
getVertex(index: number): Vec2;
|
|
144
|
+
/**
|
|
145
|
+
* @method getSupport
|
|
146
|
+
* @description Index of the vertex furthest along a local direction: the
|
|
147
|
+
* support function GJK is built on.
|
|
148
|
+
* @param {Object} d - Local direction
|
|
149
|
+
* @returns {number}
|
|
150
|
+
*/
|
|
151
|
+
getSupport(d: any): number;
|
|
152
|
+
/**
|
|
153
|
+
* @method computeAABB
|
|
154
|
+
* @description Writes this shape's world AABB under a transform.
|
|
155
|
+
* @param {AABB} aabb - Output box
|
|
156
|
+
* @param {Transform2} xf
|
|
157
|
+
*/
|
|
158
|
+
computeAABB(aabb: AABB, xf: Transform2): void;
|
|
159
|
+
/**
|
|
160
|
+
* @method computeMass
|
|
161
|
+
* @description Writes mass, center and rotational inertia for a density by
|
|
162
|
+
* summing the triangle fan of the polygon.
|
|
163
|
+
* @param {Object} massData - Output `{ mass, center, I }`
|
|
164
|
+
* @param {number} density
|
|
165
|
+
*/
|
|
166
|
+
computeMass(massData: any, density: number): void;
|
|
167
|
+
/**
|
|
168
|
+
* @method testPoint
|
|
169
|
+
* @description True when a world point is inside the polygon.
|
|
170
|
+
* @param {Transform2} xf
|
|
171
|
+
* @param {Object} p - World point
|
|
172
|
+
* @returns {boolean}
|
|
173
|
+
*/
|
|
174
|
+
testPoint(xf: Transform2, p: any): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* @method rayCast
|
|
177
|
+
* @description Casts a ray against the polygon by clipping it against every
|
|
178
|
+
* edge plane and keeping the surviving interval.
|
|
179
|
+
* @param {Object} output - Written as `{ fraction, normal }` on a hit
|
|
180
|
+
* @param {Object} input - `{ p1, p2, maxFraction }` in world space
|
|
181
|
+
* @param {Transform2} xf
|
|
182
|
+
* @returns {boolean}
|
|
183
|
+
*/
|
|
184
|
+
rayCast(output: any, input: any, xf: Transform2): boolean;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* @function Box
|
|
188
|
+
* @description Convenience factory for a box polygon.
|
|
189
|
+
* @param {number} hx - Half width in physics units
|
|
190
|
+
* @param {number} hy - Half height in physics units
|
|
191
|
+
* @param {Object} [center] - Local center `{ x, y }`
|
|
192
|
+
* @param {number} [angle=0] - Local rotation in radians
|
|
193
|
+
* @returns {PolygonShape}
|
|
194
|
+
*/
|
|
195
|
+
export function Box(hx: number, hy: number, center?: any, angle?: number): PolygonShape;
|
|
196
|
+
/**
|
|
197
|
+
* @function Circle
|
|
198
|
+
* @description Convenience factory for a circle shape.
|
|
199
|
+
* @param {number} radius - Radius in physics units
|
|
200
|
+
* @param {Object} [center] - Local center `{ x, y }`
|
|
201
|
+
* @returns {CircleShape}
|
|
202
|
+
*/
|
|
203
|
+
export function Circle(radius: number, center?: any): CircleShape;
|
|
204
|
+
import AABB from "./AABB.js";
|
|
205
|
+
import { Vec2 } from "./Math2D.js";
|
|
206
|
+
import { Transform2 } from "./Math2D.js";
|
|
207
|
+
export { AABB };
|