Skip to main content

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

Constructors

constructor

โ€ข new CollisionsSpace(gravity)

Creates a {@link CollisionSpace} instance.

Parameters

NameTypeDescription
gravityvec2The gravity vector to use in the collision space

Overrides

Space.constructor

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

Space.objects

Defined in

src/physics/spaces/space.ts:8


solvers

โ€ข solvers: Object = {}

Index signature

โ–ช [index: string]: { cb: S ; iterations: number }

Inherited from

Space.solvers

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

NameTypeDescription
objCollisionObjectThe CollisionObject to add to the space

Returns

void

Overrides

Space.addObject

Defined in

src/physics/spaces/collisions.ts:174


addSolver

โ–ธ addSolver(id, cb, iterations): void

Adds a solver to the space.

Parameters

NameTypeDescription
idstringThe solver's identifier
cbCollisionSolverThe solver to add
iterationsnumberThe number of times to run the solver, per time step

Returns

void

Inherited from

Space.addSolver

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

Space.clearObjects

Defined in

src/physics/spaces/space.ts:41


clearSolvers

โ–ธ clearSolvers(): void

Removes all solvers from the space.

Returns

void

Inherited from

Space.clearSolvers

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

CollisionObject[]

All objects in the space

Inherited from

Space.getObjects

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

Space.getSolvers

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

NameTypeDescription
deltanumberTime 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

NameTypeDescription
objCollisionObjectThe CollisionObject to remove from the space

Returns

boolean

Overrides

Space.removeObject

Defined in

src/physics/spaces/collisions.ts:187


removeSolver

โ–ธ removeSolver(id): boolean

Removes a solver from the space.

Parameters

NameTypeDescription
idstringThe id of the solver to remove

Returns

boolean

Wether or not the solver was removed

Inherited from

Space.removeSolver

Defined in

src/physics/spaces/space.ts:101


setSolverIterations

โ–ธ setSolverIterations(id, iterations): void

Sets the number of iterations a solver should run.

Parameters

NameTypeDescription
idstringThe id of the solver to update
iterationsnumberThe new number of iterations

Returns

void

Inherited from

Space.setSolverIterations

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

NameTypeDescription
idstringThe id of the solver to execute
deltanumberThe time since the last update

Returns

void

Overrides

Space.solve

Defined in

src/physics/spaces/collisions.ts:61