Table Of Contents

Previous topic

19.3. The Constraint Object

Next topic

19.5. The PhysicsDevice Object

This Page

19.4. The DynamicsWorld object

19.4.1. Constructor

A DynamicsWorld object can be constructed with PhysicsDevice.createDynamicsWorld.

19.4.2. Methods

19.4.2.1. update

Summary

Updates the state of the physics simulation. Only needs to be called once per frame.

Syntax

dynamicsWorld.update();

19.4.2.2. rayTest

Summary

Performs a ray query against the physics world.

Syntax

var rayHit = dynamicsWorld.rayTest({
        from: hitScanStart,
        to: hitScanEndPoint,
        group: physicsDevice.FILTER_PROJECTILE,
        exclude: ownerPhysicsObject
    });
if (rayHit)
{
}
group
A filter value.

Returns a RayHit object if the test succeeded, null otherwise.

19.4.2.3. convexSweepTest

Summary

Performs a convex sweep query against the physics world.

Syntax

var hit = dynamicsWorld.convexSweepTest({
        shape: queryShape,
        from: transformStart,
        to: transformEnd,
        group: physicsDevice.FILTER_PROJECTILE,
        exclude: myRigidBody
    });
shape
A Shape object.
group
A filter value.

Returns a RayHit object if the test succeeded, null otherwise.

19.4.2.4. addCollisionObject

Summary

Adds a collision object to the simulation.

Syntax

dynamicsWorld.addCollisionObject(collisionObject);
collisionObject
A CollisionObject.

Returns true if the collision object was added to the simulation, false otherwise.

19.4.2.5. removeCollisionObject

Summary

Removes a collision object from the simulation.

Syntax

dynamicsWorld.removeCollisionObject(collisionObject);
collisionObject
A CollisionObject.

Returns true if the collision object was removed from the simulation, false otherwise.

19.4.2.6. addRigidBody

Summary

Adds a rigid body to the simulation.

Syntax

dynamicsWorld.addRigidBody(rigidBody);
rigidBody
A RigidBody object.

Returns true if the rigid body was added to the simulation, false otherwise.

19.4.2.7. removeRigidBody

Summary

Removes a rigid body from the simulation.

Syntax

dynamicsWorld.removeRigidBody(rigidBody);
rigidBody
A RigidBody object.

Returns true if the rigid body was removed from the simulation, false otherwise.

19.4.2.8. addConstraint

Summary

Adds a constraint to the simulation.

Syntax

dynamicsWorld.addConstraint(constraint);
constraint
A Constraint object.

Returns true if the constraint was added to the simulation, false otherwise.

19.4.2.9. removeConstraint

Summary

Removes a constraint from the simulation.

Syntax

dynamicsWorld.removeConstraint(constraint);
constraint
A Constraint object.

Returns true if the constraint was removed from the simulation, false otherwise.

19.4.2.10. addCharacter

Summary

Adds a Character object to the simulation.

Syntax

dynamicsWorld.addCharacter(character);
character
A Character object.

Returns true if the character was added to the simulation, false otherwise.

19.4.2.11. removeCharacter

Summary

Removes a Character object from the simulation.

Syntax

dynamicsWorld.removeCharacter(character);
character
A Character object.

Returns true if the character was removed from the simulation, false otherwise.

19.4.2.12. flush

Summary

Removes all objects from the DynamicsWorld.

Syntax

dynamicsWorld.flush();

19.4.3. Properties

19.4.3.1. maxSubSteps

Summary

The maximum number of substeps the simulation will perform per frame.

Syntax

var maxSubSteps = dynamicsWorld.maxSubSteps;

Note

Read Only

19.4.3.2. fixedTimeStep

Summary

Fixed simulation time in seconds per substep.

Syntax

var fixedTimeStep = dynamicsWorld.fixedTimeStep;

Note

Read Only

19.4.3.3. maxGiveUpTimeStep

Summary

Should the number of sub steps required exceed maxSubSteps then whether using fixed or variable time steps, the size of a time step will be permitted to reach a maximum of this amount to prevent loss of simulation time.

Setting to 0 means that we will not permit time step to be increased.

Syntax

var maxGiveUpTimeStep = dynamicsWorld.maxGiveUpTimeStep;

Note

Read Only, Canvas Only

19.4.3.4. minimumTimeStep

Summary

Minimum simulation time in seconds per substep.

Syntax

var minimumTimeStep = dynamicsWorld.minimumTimeStep;

Note

Read Only, Canvas Only.

19.4.3.5. maximumTimeStep

Summary

Maximum simulation time in seconds per substep.

Syntax

var maximumTimeStep = dynamicsWorld.maximumTimeStep;

Note

Read Only, Canvas Only.

19.4.3.6. gravity

Summary

The direction and magnitude of a global gravity force applied to the whole scene per frame.

Syntax

var gravity = dynamicsWorld.gravity;

Note

Read Only

19.4.3.7. performanceData

Summary

Performance data about internal stages of the update() method, this is available only in Canvas.

Each field records the approximate number of seconds spent in the corresponding area for the previous call to update(). If more than one substep occured, this information will relate to the summation of sub-step costs.

Fields

discrete
The time spent performing discrete collision detection.
sleepComputation
The time spent evaluating which objects can be put to sleep.
prestepContacts
The time spent performing precomputations on contacts.
prestepConstraints
The time spent performing precomputations on constraints.
integrateVelocities
The time spent integrating body velocities
warmstartContacts
The time spent applying previous update’s cached impulses for contacts.
warmstartConstraints
The time spent applying previous update’s cached impulses for constraints.
physicsIterations
The time spent solving constraint errors for impulses for both contacts and constraints.
integratePositions
The time spent integrating body positions and preparing bodies for continous collision detection.
continuous
The time spent performing the actual continuous collision detection.

Note

Read Only