World class

The physics world

Inheritance

Constructors

World({Vec3? gravity, Vec3? frictionGravity, bool allowSleep = false, Broadphase? broadphase, Solver? solver, bool quatNormalizeFast = false, int quatNormalizeSkip = 0, bool verbose = false})

Properties

accumulator double
Time accumulator for interpolation. @see https://gafferongames.com/game-physics/fix-your-timestep/
getter/setter pair
addBodyEvent BodyEvent
Dispatched after a body has been added to the world.
getter/setter pair
additions List<int>
final
allowSleep bool
Makes bodies go to sleep when they've been inactive.
getter/setter pair
beginContactEvent ContactEvent
final
beginShapeContactEvent ShapeContactEvent
final
bodies List<Body>
All bodies in this world
getter/setter pair
bodyOverlapKeeper OverlapKeeper
getter/setter pair
broadphase Broadphase
The broadphase algorithm to use.
getter/setter pair
collisionMatrix ArrayCollisionMatrix
getter/setter pair
collisionMatrixPrevious ArrayCollisionMatrix
CollisionMatrix from the previous step.
getter/setter pair
constraints List<Constraint>
getter/setter pair
contactmaterials List<ContactMaterial>
All added contactmaterials.
getter/setter pair
contactMaterialTable TupleDictionary
Used to look up a ContactMaterial given two instances of Material.
getter/setter pair
contacts List<ContactEquation>
All the current contacts (instances of ContactEquation) in the world.
getter/setter pair
defaultContactMaterial ContactMaterial
This contact material is used if no suitable contactmaterial is found for a contact.
getter/setter pair
defaultDt double
Default and last timestep sizes.
getter/setter pair
defaultMaterial Material
The default material of the bodies.
getter/setter pair
doProfiling bool
getter/setter pair
dt double
Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is "fresh" inside event callbacks.
getter/setter pair
endContactEvent ContactEvent
final
endShapeContactEvent ShapeContactEvent
final
frictionEquations List<FrictionEquation>
getter/setter pair
frictionGravity Vec3?
Gravity to use when approximating the friction max force (mumassgravity). If undefined, global gravity will be used. Use to enable friction in a World with a null gravity vector (no gravity).
getter/setter pair
gravity Vec3
The gravity of the world.
getter/setter pair
hasActiveBodies bool
True if any bodies are not sleeping, false if every body is sleeping.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
idToBodyMap Map<int, Body>
getter/setter pair
lastCallTime double?
getter/setter pair
narrowphase Narrowphase
getter/setter pair
nextId int
getter/setter pair
performance Performance
final
profile Profile
getter/setter pair
quatNormalizeFast bool
Set to true to use fast quaternion normalization. It is often enough accurate to use. If bodies tend to explode, set to false.
getter/setter pair
quatNormalizeSkip int
How often to normalize quaternions. Set to 0 for every step, 1 for every second etc.. A larger value increases performance. If bodies tend to explode, set to a smaller value (zero to be sure nothing can go wrong).
getter/setter pair
removals List<int>
final
removeBodyEvent BodyEvent
Dispatched after a body has been removed from the world.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shapeOverlapKeeper OverlapKeeper
getter/setter pair
solver Solver
The solver algorithm to use.
getter/setter pair
stepnumber int
Number of timesteps taken since start.
getter/setter pair
subsystems List
getter/setter pair
time double
The wall-clock time since simulation start.
getter/setter pair
verbose bool
getter/setter pair
worldStepFrictionEquationPool List<FrictionEquation>
getter/setter pair
worldStepOldContacts List<ContactEquation>
getter/setter pair
worldStepP1 List<Body>
getter/setter pair
worldStepP2 List<Body>
getter/setter pair

Methods

addBody(Body body) → void
Add a rigid body to the simulation. @todo If the simulation has not yet started, why recrete and copy arrays for each body? Accumulate in dynamic arrays in this case. @todo Adding an array of bodies should be possible. This would save some loops too
addConstraint(Constraint c) → void
Add a constraint to the simulation.
addContactMaterial(ContactMaterial cmat) → void
Adds a contact material to the World
addEventListener(String type, dynamic listener(dynamic)) EventTarget
Add an event listener @return The self object, for chainability.
inherited
clearForces() → void
Sets all body forces in the world to zero.
collisionMatrixTick() → void
Store old collision state info
dispatchEvent(Event event) EventTarget
Emit an event. @return The self object, for chainability.
inherited
emitContactEvents() → void
fixedStep([double dt = 1 / 60, int maxSubSteps = 10]) → void
Step the simulation forward keeping track of last called time to be able to step the world at a fixed rate, independently of framerate.
getBodyById(int id) Body
getContactMaterial(Material m1, Material m2) ContactMaterial?
Get the contact material between materials m1 and m2 @return The contact material if it was found.
getShapeById(int id) Shape?
@todo Make a faster map
hasAnyEventListener(String type) bool
Check if any event listener of the given type is added
inherited
hasEventListener(String type, void listener()) bool
Check if an event listener is added
inherited
internalStep(double dt) → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
raycastAll([Vec3? from, Vec3? to, RayOptions? options, RaycastCallback? callback]) bool
Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument. @return True if any body was hit.
raycastAny([Vec3? from, Vec3? to, RayOptions? options, RaycastResult? result]) bool
Ray cast, and stop at the first result. Note that the order is random - but the method is fast. @return True if any body was hit.
raycastClosest([Vec3? from, Vec3? to, RayOptions? options, RaycastResult? result]) bool
Ray cast, and return information of the closest hit. @return True if any body was hit.
rayTest(Vec3 from, Vec3 to, dynamic result) → void
Raycast test @deprecated Use .raycastAll, .raycastClosest or .raycastAny instead.
removeBody(Body body) → void
Remove a rigid body from the simulation.
removeConstraint(Constraint c) → void
Removes a constraint
removeContactMaterial(ContactMaterial cmat) → void
Removes a contact material from the World.
removeEventListener(String type, Function listener) EventTarget
Remove an event listener @return The self object, for chainability.
inherited
step(double dt, [double? timeSinceLastCalled, int maxSubSteps = 10]) → void
Step the physics world forward in time.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited