Class: CollisionsSpace
physics/spaces/collisions.CollisionsSpace
Represents an infinite space containing CollisionObjects.
Can be used to test for and solve collisions between objects in the space.
Hierarchy
Space<CollisionObject,CollisionSolver>โณ
CollisionsSpace
Constructors
constructor
โข new CollisionsSpace(gravity)
Creates a {@link CollisionSpace} instance.
Parameters
| Name | Type | Description |
|---|---|---|
gravity | vec2 | The gravity vector to use in the collision space |
Overrides
Defined in
src/physics/spaces/collisions.ts:47
Properties
aabbTree
โข aabbTree: AABBTree
The AABBTree used for broadphase and raycasting.
Defined in
src/physics/spaces/collisions.ts:40
collisionManifolds
โข collisionManifolds: Manifold[] = []
Defined in
src/physics/spaces/collisions.ts:19
collisionPairs
โข collisionPairs: CollisionPair[]
Array used to store pairs of objects which may be colliding.
Defined in
src/physics/spaces/collisions.ts:35
collisions
โข collisions: ManifoldMap
Collision manifolds map.
Defined in
src/physics/spaces/collisions.ts:25
gravity
โข gravity: vec2
Defined in
src/physics/spaces/collisions.ts:17
objects
โข objects: CollisionObject[] = []
Inherited from
Defined in
src/physics/spaces/space.ts:8
solvers
โข solvers: Object = {}
Index signature
โช [index: string]: { cb: S ; iterations: number }
Inherited from
Defined in
src/physics/spaces/space.ts:9
triggerManifolds
โข triggerManifolds: Manifold[] = []
Defined in
src/physics/spaces/collisions.ts:20
triggers
โข triggers: ManifoldMap
Trigger manifolds map.
Defined in
src/physics/spaces/collisions.ts:30
Methods
addObject
โธ addObject(obj): void
Adds an object to the space.
Parameters
| Name | Type | Description |
|---|---|---|
obj | CollisionObject | The CollisionObject to add to the space |
Returns
void
Overrides
Defined in
src/physics/spaces/collisions.ts:174
addSolver
โธ addSolver(id, cb, iterations): void
Adds a solver to the space.
Parameters
| Name | Type | Description |
|---|---|---|
id | string | The solver's identifier |
cb | CollisionSolver | The solver to add |
iterations | number | The number of times to run the solver, per time step |
Returns
void
Inherited from
Defined in
src/physics/spaces/space.ts:91
broadphase
โธ broadphase(): void
Performs the broadphase collision detection.
The broadphase will update the AABBTree and then obtain possible collision pairs for the narrow phase.
Returns
void
Defined in
src/physics/spaces/collisions.ts:97
clearObjects
โธ clearObjects(): void
Removes all objects from the space.
Returns
void
Inherited from
Defined in
src/physics/spaces/space.ts:41
clearSolvers
โธ clearSolvers(): void
Removes all solvers from the space.
Returns
void
Inherited from
Defined in
src/physics/spaces/space.ts:80
fireEvents
โธ fireEvents(): void
Fire "collision" and "trigger" events on objects in this.manifolds.
If both objects in a collision are triggers object a will recieve the "trigger" the event.
Returns
void
Defined in
src/physics/spaces/collisions.ts:77
getCollisionManifolds
โธ Private getCollisionManifolds(): void
Gets all the manifolds in the collisions ManifoldMap and stores them in this.collisionManifolds.
Returns
void
Defined in
src/physics/spaces/collisions.ts:158
getObjects
โธ getObjects(): CollisionObject[]
Gets all objects in the space.
Returns
All objects in the space
Inherited from
Defined in
src/physics/spaces/space.ts:34
getSolvers
โธ getSolvers(): Object
Gets all solvers in the space.
Returns
Object
All solvers in the space
Inherited from
Defined in
src/physics/spaces/space.ts:73
getTriggerManifolds
โธ Private getTriggerManifolds(): void
Gets all the manifolds in the triggers ManifoldMap and stores them in this.triggersManifolds.
Returns
void
Defined in
src/physics/spaces/collisions.ts:165
obtainManifolds
โธ obtainManifolds(delta): void
Obtains all collision and trigger manifolds for the current frame.
Manifolds are stored in this.manifolds
obtainManifolds should only be called once per frame.
Parameters
| Name | Type | Description |
|---|---|---|
delta | number | Time since last frame |
Returns
void
Defined in
src/physics/spaces/collisions.ts:111
removeObject
โธ removeObject(obj): boolean
Removes an object from the space and deletes any manifolds associated with it.
Parameters
| Name | Type | Description |
|---|---|---|
obj | CollisionObject | The CollisionObject to remove from the space |
Returns
boolean
Overrides
Defined in
src/physics/spaces/collisions.ts:187
removeSolver
โธ removeSolver(id): boolean
Removes a solver from the space.
Parameters
| Name | Type | Description |
|---|---|---|
id | string | The id of the solver to remove |
Returns
boolean
Wether or not the solver was removed
Inherited from
Defined in
src/physics/spaces/space.ts:101
setSolverIterations
โธ setSolverIterations(id, iterations): void
Sets the number of iterations a solver should run.
Parameters
| Name | Type | Description |
|---|---|---|
id | string | The id of the solver to update |
iterations | number | The new number of iterations |
Returns
void
Inherited from
Defined in
src/physics/spaces/space.ts:112
solve
โธ solve(id, delta): void
Executes a solver on every collision manifold in the space.
Make sure to call this.obtainManifolds before executing any solvers.
Parameters
| Name | Type | Description |
|---|---|---|
id | string | The id of the solver to execute |
delta | number | The time since the last update |
Returns
void
Overrides
Defined in
src/physics/spaces/collisions.ts:61