World Class
The dynamics world, where all bodies and constraints lives.
Constructor
World
-
[options]
Parameters:
-
[options]
Object optional-
solver
SolverDefaults to GSSolver.
-
gravity
Float32ArrayDefaults to [0,-9.78]
-
broadphase
BroadphaseDefaults to NaiveBroadphase
-
Item Index
Methods
Methods
addBody
-
body
Add a body to the simulation
Parameters:
-
body
Body
Example:
var world = new World(),
body = new Body();
world.addBody(body);
addContactMaterial
-
contactMaterial
Add a ContactMaterial to the simulation.
Parameters:
-
contactMaterial
ContactMaterial
clear
()
Resets the World, removes all bodies, constraints and springs.
fromJSON
-
json
Load a scene from a serialized state in JSON format.
Parameters:
-
json
Object
Returns:
True on success, else false.
getContactMaterial
-
materialA
-
materialB
Get a contact material given two materials
Returns:
The matching ContactMaterial, or false on fail.
hitTest
-
worldPoint
-
bodies
-
precision
Test if a world point overlaps bodies
Parameters:
-
worldPoint
ArrayPoint to use for intersection tests
-
bodies
ArrayA list of objects to check for intersection
-
precision
NumberUsed for matching against particles and lines. Adds some margin to these infinitesimal objects.
Returns:
Array of bodies that overlap the point
runNarrowphase
-
np
-
bi
-
si
-
xi
-
ai
-
bj
-
sj
-
xj
-
aj
-
mu
-
glen
Runs narrowphase for the shape pair i and j.
Parameters:
-
np
Narrowphase -
bi
Body -
si
Shape -
xi
Array -
ai
Number -
bj
Body -
sj
Shape -
xj
Array -
aj
Number -
mu
Number -
glen
Number
step
-
dt
Step the physics world forward in time.
Parameters:
-
dt
NumberThe time step size to use.
Example:
var world = new World();
world.step(0.01);
toJSON
()
Object
Convert the world to a JSON-serializable Object.
Returns:
upgradeJSON
-
json
Upgrades a JSON object to current version
Parameters:
-
json
Object
Returns:
New json object, or false on failure.
Properties
applySpringForces
Boolean
Enable to automatically apply spring forces each step.
bodies
Array
All bodies in the world.
constraints
Array
User-added constraints.
Gravity in the world. This is applied on all bodies in the beginning of each step().
contactMaterials
Array
The ContactMaterials added to the World.
defaultFriction
Number
Friction between colliding bodies. This value is used if no matching ContactMaterial is found for the body pair.
doPofiling
Boolean
Whether to do timing measurements during the step() or not.
lastStepTime
Number
How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.
lastTimeStep
Number
For keeping track of what time step size we used last step
solveConstraints
Boolean
Enable/disable constraint solving in each step.
springs
Array
All springs in the world.