Package org.dyn4j.world
The dynamics engine is an impulse based rigid body physics simulator. The simulation
by default uses SI (m/kg/s) units. This can be changed, but all settings within the
Settings
singleton must be set to the new units. Instead
its recommended to use the UnitConversion
class to convert all
values to MKS.
A constraint based approach is used to solving contacts and joints.
Create a World
object to gain access the dynamics engine. Create
Body
s and add them to the World
.
Add the AbstractPhysicsWorld.update(double)
method to your game loop (notice the
AbstractPhysicsWorld.update(double)
method requires the elapsed time to
be in seconds).
Upon creating a World
a Bounds
object may be supplied. The Bounds
will determine when
Body
s go out of bounds and deactivate them. Using the
World()
constructor will create a world that has no bounds,
in which case the AbstractCollisionWorld.getBounds()
method will return null.
A World
object also contains a number listeners that can be used to
respond to events that happen within the world, contact for instance.
BoundsListener
for responding to out of bounds bodiesDestructionListener
for responding to bodies and joints that are implicitly destroyed by some other actionStepListener
for performing logic at the end/beginning of a time stepCollisionListener
for responding to collision detection eventsContactListener
for responding to contact eventsTimeOfImpactListener
for responding to time of impact events
World
object may not be allowed inside the listener methods.
The gravity of the World
object can be changed, and can be in any
direction via the AbstractPhysicsWorld.setGravity(org.dyn4j.geometry.Vector2)
method.
The dynamics engine may require some configuration. The defaults should cover most applications,
however, they can be changed using the Settings
class on the
World
. Any setting can be changed at runtime so that no source code
modification is needed. Refer to the source of Settings
and the
Sandbox for details on what each individual setting controls.
- Since:
- 4.0.0
- Version:
- 4.0.0
- Author:
- William Bittle
-
Interface Summary Interface Description BroadphaseCollisionData<T extends CollisionBody<E>,E extends Fixture> Represents a broadphase collision.BroadphaseFilter<T extends CollisionBody<E>,E extends Fixture> Represents a class that defines rules to exclude results fromBroadphaseDetector
.CoefficientMixer Interface used to customize the way friction and restitution coefficients are mixed.CollisionData<T extends CollisionBody<E>,E extends Fixture> Represents a container for all the collision information between aCollisionPair
.CollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>> Represents a world whereCollisionBody
s are added to participate in collision detection.ContactCollisionData<T extends PhysicsBody> Interaface for collision data that contains aContactConstraint
.ManifoldCollisionData<T extends CollisionBody<E>,E extends Fixture> Represents a manifold collision.NarrowphaseCollisionData<T extends CollisionBody<E>,E extends Fixture> Represents a narrowphase collision.PhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>> Represents aCollisionWorld
that resolves collision using Newton's laws of physics. -
Class Summary Class Description AbstractCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>> Abstract implementation of theCollisionWorld
interface.AbstractPhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>> Abstract implementation of thePhysicsWorld
interface.BroadphaseFilterAdapter<T extends CollisionBody<E>,E extends Fixture> Helper class to avoid having to override all the methods of theBroadphaseFilter
interface.CollisionBodyBroadphaseFilter<T extends CollisionBody<E>,E extends Fixture> The default filter forCollisionWorld
s that filtersFixture
s by theirFilter
s and their enable flags.ConstraintGraph<T extends PhysicsBody> Represents an undirected graph of constraints involvingPhysicsBody
s with the desire to split the simulation into smaller, solvable chunks.ConstraintGraphNode<T extends PhysicsBody> Represents a node in the constraint graph.DetectFilter<T extends CollisionBody<E>,E extends Fixture> Represents the filters for queries against aCollisionWorld
.Island<T extends PhysicsBody> Used to solve the contact constraints and joints for a group of interconnected bodies.PhysicsBodyBroadphaseFilter<T extends PhysicsBody> Encapsulates logic used to filter the broadphase pairs based on filters, body state, etc.World<T extends PhysicsBody> Full implementation of both theCollisionWorld
andPhysicsWorld
interfaces.WorldCollisionData<T extends PhysicsBody> Represents the collision data for theWorld
class.