Class: Physics
physics/physics.Physics
Handles physics for bodies added to the engine.
Raycasting can only check against objects in the phsyics engine's collisions space.
At the start of each update
call the static G_CONF
variable is set to the instances CONFIG
variable.
This allows for easy access to the physics config from other parts of the physics system.
Implements
Constructors
constructor
โข new Physics(gravity?
)
Create an Physics instance.
Parameters
Name | Type | Description |
---|---|---|
gravity? | vec2 | The gravitional force applied to objects in the system |
Defined in
src/physics/physics.ts:169
Properties
CONFIG
โข CONFIG: Object
Type declaration
Name | Type |
---|---|
ACUMMULATE_IMPULSE | boolean |
CACHED_CONTACTS_TOLERANCE | number |
CONSTRAINT_ITERATIONS | number |
EPA_MAX_ITERATIONS | number |
EPA_TOLERANCE | number |
POINT_SIZE | number |
POSITION_DAMPING | number |
POSITION_ITERATIONS | number |
POSITION_SCALE | number |
POSITION_SLOP | number |
POSITION_WARMING | number |
RESTITUTION_THRESHOLD | number |
VELOCITY_ITERATIONS | number |
WARM_IMPULSE | boolean |
Defined in
src/physics/physics.ts:113
broadphaseTime
โข broadphaseTime: number
= 0
The time in ms that the last broadphase collision detection step took.
Defined in
src/physics/physics.ts:132
collisionSolveTime
โข collisionSolveTime: number
= 0
The time in ms that the last collision solving steps took.
Defined in
src/physics/physics.ts:142
collisionsSpace
โข collisionsSpace: CollisionsSpace
Defined in
src/physics/physics.ts:119
constraintSpace
โข constraintSpace: ConstraintSpace
Defined in
src/physics/physics.ts:120
constraintTime
โข constraintTime: number
= 0
The time in ms that the last constraint solving steps took.
Defined in
src/physics/physics.ts:147
debug
โข debug: boolean
= false
Enable/disable debug tools.
Defined in
src/physics/physics.ts:162
dynamicsSpace
โข dynamicsSpace: DynamicsSpace
Defined in
src/physics/physics.ts:118
dynamicsTime
โข dynamicsTime: number
= 0
The time in ms that the last dynamics solving steps took.
Defined in
src/physics/physics.ts:152
fluidTime
โข fluidTime: number
= 0
The time in ms that the last fluid solving steps took.
Defined in
src/physics/physics.ts:157
fluids
โข fluids: Fluid
[] = []
Defined in
src/physics/physics.ts:122
gravity
โข Private
gravity: vec2
Defined in
src/physics/physics.ts:115
narrowphaseTime
โข narrowphaseTime: number
= 0
The time in ms that the last narrowphase collision detection step took.
Defined in
src/physics/physics.ts:137
physicsTime
โข physicsTime: number
= 0
The amount of time in ms that the last physics step took.
Defined in
src/physics/physics.ts:127
G_CONF
โช Static
G_CONF: Object
Type declaration
Name | Type |
---|---|
ACUMMULATE_IMPULSE | boolean |
CACHED_CONTACTS_TOLERANCE | number |
CONSTRAINT_ITERATIONS | number |
EPA_MAX_ITERATIONS | number |
EPA_TOLERANCE | number |
POINT_SIZE | number |
POSITION_DAMPING | number |
POSITION_ITERATIONS | number |
POSITION_SCALE | number |
POSITION_SLOP | number |
POSITION_WARMING | number |
RESTITUTION_THRESHOLD | number |
VELOCITY_ITERATIONS | number |
WARM_IMPULSE | boolean |
Defined in
src/physics/physics.ts:111
Methods
addBodies
โธ addBodies(...bodies
): void
Adds the given bodies to the world's dynamics and collisions spaces.
Parameters
Name | Type | Description |
---|---|---|
...bodies | RigidBody [] | The bodies to add |
Returns
void
Defined in
src/physics/physics.ts:383
addBody
โธ addBody(body
): void
Adds a {@link Rigidbody} to the world's dynamics and collisions spaces.
Parameters
Name | Type | Description |
---|---|---|
body | RigidBody | The body to add |
Returns
void
Defined in
src/physics/physics.ts:373
addCollisionObj
โธ addCollisionObj(c
): void
Adds a CollisionObject to the world's collisions space.
Parameters
Name | Type | Description |
---|---|---|
c | CollisionObject | The collision object to add |
Returns
void
Defined in
src/physics/physics.ts:355
addConstraint
โธ addConstraint(constraint
): void
Adds a Constraint to the world's constraint space.
Parameters
Name | Type | Description |
---|---|---|
constraint | Constraint | The constraint to add |
Returns
void
Defined in
src/physics/physics.ts:441
addDynamicsObj
โธ addDynamicsObj(obj
): void
Adds a RigidBody to the world's dynamics space.
Parameters
Name | Type | Description |
---|---|---|
obj | RigidBody | The object to add |
Returns
void
Defined in
src/physics/physics.ts:364
addFluid
โธ addFluid(fluid
): void
Adds the given fluid to the physics world.
Parameters
Name | Type | Description |
---|---|---|
fluid | Fluid | The fluid to add |
Returns
void
Defined in
src/physics/physics.ts:466
drawDebug
โธ drawDebug(): void
Returns
void
Defined in
src/physics/physics.ts:273
getGravity
โธ getGravity(): vec2
Gets the gravity vector the physics world is using.
Returns
vec2
The gravity in use
Defined in
src/physics/physics.ts:513
pick
โธ pick(point
): CollisionObject
[]
Point pick objects.
NOTE: Picking only checks objects in the CollisionsSpace.
Parameters
Name | Type | Description |
---|---|---|
point | vec2 | The point to pick objects at |
Returns
Defined in
src/physics/physics.ts:311
raycast
โธ raycast(ray
): CollisionObject
[]
raycast objects.
NOTE: Raycast only checks objects in the CollisionsSpace.
Parameters
Name | Type | Description |
---|---|---|
ray | Ray | The ray to cast |
Returns
Defined in
src/physics/physics.ts:335
removeAllBodies
โธ removeAllBodies(): void
Removes all bodies from the world's dynamics and collision spaces.
Returns
void
Defined in
src/physics/physics.ts:431
removeAllConstraints
โธ removeAllConstraints(): void
Removes all constraints from the world.
Returns
void
Defined in
src/physics/physics.ts:457
removeAllFluids
โธ removeAllFluids(): void
Removes all fluids from the world.
Returns
void
Defined in
src/physics/physics.ts:491
removeBodies
โธ removeBodies(...bodies
): void
Removes the given bodies from the world's dynamics and collision spaces.
Parameters
Name | Type | Description |
---|---|---|
...bodies | RigidBody [] | The bodies to remove |
Returns
void
Defined in
src/physics/physics.ts:422
removeBody
โธ removeBody(body
): void
Removes a {@link Rigidbody} from the world's dynamics and collisions spaces.
Parameters
Name | Type | Description |
---|---|---|
body | RigidBody | The body to remove |
Returns
void
Defined in
src/physics/physics.ts:412
removeCollisionObj
โธ removeCollisionObj(c
): void
Removes a CollisionObject from the world's collisions space.
Parameters
Name | Type | Description |
---|---|---|
c | CollisionObject | The collision object to remove |
Returns
void
Defined in
src/physics/physics.ts:394
removeConstraint
โธ removeConstraint(constraint
): void
Removes a Constraint from the world's constraint space.
Parameters
Name | Type | Description |
---|---|---|
constraint | Constraint | The constraint to remove |
Returns
void
Defined in
src/physics/physics.ts:450
removeDynamicsObj
โธ removeDynamicsObj(obj
): void
Removes a RigidBody from the world's dynamics space.
Parameters
Name | Type | Description |
---|---|---|
obj | RigidBody | The object to remove |
Returns
void
Defined in
src/physics/physics.ts:403
removeFluid
โธ removeFluid(fluid
): void
Removes the given fluid from the physics world.
Parameters
Name | Type | Description |
---|---|---|
fluid | Fluid | The fluid to remove |
Returns
void
Defined in
src/physics/physics.ts:480
setGravity
โธ setGravity(gravity
): void
Sets the gravity to use in the physics world.
Parameters
Name | Type | Description |
---|---|---|
gravity | vec2 | The new gravity to use |
Returns
void
Defined in
src/physics/physics.ts:502
update
โธ update(ts
): void
Steps the physics world forward by the given delta time.
Order of updates is very important.
Parameters
Name | Type | Description |
---|---|---|
ts | TimeStep | The TimeStep for this update. |
Returns
void
Implementation of
Defined in
src/physics/physics.ts:195