Class AbstractPhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Object
-
- AbstractCollisionWorld<T,BodyFixture,V>
-
- AbstractPhysicsWorld<T,V>
-
- Type Parameters:
T
- thePhysicsBody
typeV
- theContactCollisionData
type
- All Implemented Interfaces:
DataContainer
,Shiftable
,CollisionWorld<T,BodyFixture,V>
,PhysicsWorld<T,V>
- Direct Known Subclasses:
World
public abstract class AbstractPhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>> extends AbstractCollisionWorld<T,BodyFixture,V> implements PhysicsWorld<T,V>, Shiftable, DataContainer
Abstract implementation of thePhysicsWorld
interface.This class builds on top of the
AbstractCollisionWorld
class adding a physics pipeline to the collision detection pipeline. This class implements theprocessCollisions(Iterator)
method and uses it to build aConstraintGraph
which is then used to solveContactConstraint
s andJoint
s.Extenders only need to implement the
AbstractCollisionWorld.createCollisionData(org.dyn4j.collision.CollisionPair)
method to ensure the correct type of collision data is used for tracking.NOTE: This class uses the
AbstractCollisionBody.setOwner(Object)
andAbstractCollisionBody.setFixtureModificationHandler(org.dyn4j.collision.FixtureModificationHandler)
methods to handle certain scenarios like fixture removal on a body or bodies added to more than one world. Likewise, theJoint.setOwner(Object)
method is used to handle joints being added to the world. Callers should NOT use the methods.- Since:
- 4.0.0
- Version:
- 4.2.1
- Author:
- William Bittle
-
-
Field Summary
Fields Modifier and Type Field Description protected BroadphaseDetector<T>
ccdBroadphase
The CCDBroadphaseDetector
protected Set<CollisionPair<T>>
ccdCollisionData
The full set of tracked CCD collision dataprotected ConstraintGraph<T>
constraintGraph
The constraint graph between bodiesprotected List<V>
contactCollisions
A temporary list of only theContactConstraint
collisions from the last detection; cleared and refilled each stepprotected ContactConstraintSolver<T>
contactConstraintSolver
protected List<ContactListener<T>>
contactListeners
The list ofContactListener
sprotected List<ContactListener<T>>
contactListenersUnmodifiable
The unmodifiable list ofContactListener
sprotected List<DestructionListener<T>>
destructionListeners
The list ofDestructionListener
sprotected List<DestructionListener<T>>
destructionListenersUnmodifiable
The unmodifiable list ofDestructionListener
sprotected Vector2
gravity
The world gravity vectorprotected List<Joint<T>>
joints
TheJoint
listprotected List<Joint<T>>
jointsUnmodifiable
The unmodifiableJoint
listprotected Settings
settings
The dynamics settings for this worldprotected List<StepListener<T>>
stepListeners
The list ofStepListener
sprotected List<StepListener<T>>
stepListenersUnmodifiable
The unmodifiable list ofStepListener
sprotected double
time
The accumulated timeprotected List<TimeOfImpactListener<T>>
timeOfImpactListeners
The list ofTimeOfImpactListener
sprotected List<TimeOfImpactListener<T>>
timeOfImpactListenersUnmodifiable
The unmodifiable list ofTimeOfImpactListener
sprotected TimeOfImpactSolver<T>
timeOfImpactSolver
protected TimeStep
timeStep
TheTimeStep
used by the dynamics calculationsprotected boolean
updateRequired
True if an update to the collision data or interaction graph is needed before a step of the engineprotected ValueMixer
valueMixer
TheValueMixer
-
Fields inherited from class AbstractCollisionWorld
bodies, bodiesUnmodifiable, bounds, boundsListeners, boundsListenersUnmodifiable, broadphaseDetector, broadphaseFilter, collisionData, collisionListeners, collisionListenersUnmodifiable, manifoldSolver, narrowphaseDetector, narrowphasePostProcessor, raycastDetector, timeOfImpactDetector, userData
-
Fields inherited from interface CollisionWorld
DEFAULT_INITIAL_BODY_CAPACITY
-
Fields inherited from interface PhysicsWorld
DEFAULT_INITIAL_JOINT_CAPACITY, EARTH_GRAVITY, ZERO_GRAVITY
-
-
Constructor Summary
Constructors Constructor Description AbstractPhysicsWorld()
Default constructor.AbstractPhysicsWorld(int initialBodyCapacity, int initialJointCapacity)
Optional constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addBody(T body)
Adds the givenCollisionBody
to thisCollisionWorld
.boolean
addContactListener(ContactListener<T> listener)
Adds the givenContactListener
to this world.boolean
addDestructionListener(DestructionListener<T> listener)
Adds the givenDestructionListener
to this world.void
addJoint(Joint<T> joint)
boolean
addStepListener(StepListener<T> listener)
Adds the givenStepListener
to this world.boolean
addTimeOfImpactListener(TimeOfImpactListener<T> listener)
Adds the givenTimeOfImpactListener
to this world.protected void
clear()
Helper method to clear the world of bodies and joints.boolean
containsJoint(Joint<T> joint)
Returns true if this world contains the given joint.protected void
destroyContacts(ConstraintGraphNode<T> node, BodyFixture fixture, boolean notify)
Destroys the contacts for the given graph node.protected void
destroyJoints(ConstraintGraphNode<T> node, boolean notify)
Destroys all joints associated with the given constraint graph node.double
getAccumulatedTime()
Returns the current accumulated time.CoefficientMixer
getCoefficientMixer()
Deprecated.ContactConstraintSolver<T>
getContactConstraintSolver()
Returns theContactConstraintSolver
.List<ContactListener<T>>
getContactListeners()
Returns an unmodifiable list of all the contact listeners registered to this world.List<ContactConstraint<T>>
getContacts(T body)
Returns theContactConstraint
s for the givenPhysicsBody
.BroadphaseDetector<T>
getContinuousCollisionDetectionBroadphaseDetector()
Returns the CCD broad-phase collision detection algorithm.List<DestructionListener<T>>
getDestructionListeners()
Returns an unmodifiable list of all the destruction listeners registered to this world.Vector2
getGravity()
Returns the acceleration due to gravity.List<T>
getInContactBodies(T body, boolean includeSensedContact)
Returns a list of allPhysicsBody
s that are in contact with the givenPhysicsBody
.List<T>
getJoinedBodies(T body)
Joint<T>
getJoint(int index)
Returns theJoint
at the given index.int
getJointCount()
Iterator<Joint<T>>
getJointIterator()
Returns an iterator for iterating over the joints in this world.List<Joint<T>>
getJoints()
Returns an unmodifiable list containing all the joints in this world.List<Joint<T>>
getJoints(T body)
Returns theJoint
s the givenPhysicsBody
is a member of.Settings
getSettings()
Returns the settings for this world.List<StepListener<T>>
getStepListeners()
Returns an unmodifiable list of all the step listeners registered to this world.List<TimeOfImpactListener<T>>
getTimeOfImpactListeners()
Returns an unmodifiable list of all the time of impact listeners registered to this world.TimeOfImpactSolver<T>
getTimeOfImpactSolver()
Returns theTimeOfImpactSolver
.TimeStep
getTimeStep()
Returns theTimeStep
object used to advance the simulation.ValueMixer
getValueMixer()
Returns theValueMixer
.protected void
handleAllFixturesRemoved(T body)
Handler for all fixture removal.protected void
handleFixtureRemoved(T body, BodyFixture fixture)
Handler for fixture removal.boolean
isEmpty()
Returns true if this world doesn't contain any bodies or joints.boolean
isInContact(T body1, T body2)
Returns true if the givenPhysicsBody
s are currently in collision.boolean
isJoined(T body1, T body2)
Returns true if the twoPhysicsBody
s are joined via aJoint
.boolean
isJointCollisionAllowed(T body1, T body2)
Returns true if the twoPhysicsBody
s are joined by at least oneJoint
where the collision allowed property is true.boolean
isUpdateRequired()
Returns true if upon the next time step the contacts must be updated.protected void
processCollisions(Iterator<V> iterator)
This method should process the collisions returned by the given iterator.void
removeAllBodies()
Removes all bodies from this world.void
removeAllBodies(boolean notify)
This is a convenience method for thePhysicsWorld.removeAllBodiesAndJoints(boolean)
method since all joints will be removed when all bodies are removed anyway.void
removeAllBodiesAndJoints()
Removes all the joints and bodies from this world.void
removeAllBodiesAndJoints(boolean notify)
Removes all the joints and bodies from this world.void
removeAllContactListeners()
Removes all contact listeners from this world.void
removeAllDestructionListeners()
Removes all destruction listeners from this world.void
removeAllJoints()
void
removeAllJoints(boolean notify)
void
removeAllListeners()
Removes all listeners from this world.void
removeAllStepListeners()
Removes all step listeners from this world.void
removeAllTimeOfImpactListeners()
Removes all time of impact listeners from this world.boolean
removeBody(int index)
Removes theCollisionBody
at the given index from thisCollisionWorld
.boolean
removeBody(int index, boolean notify)
Removes theCollisionBody
at the given index from thisCollisionWorld
.boolean
removeBody(T body)
Removes the givenCollisionBody
from thisCollisionWorld
.boolean
removeBody(T body, boolean notify)
Removes the givenCollisionBody
from thisCollisionWorld
.boolean
removeContactListener(ContactListener<T> listener)
Removes the given contact listener from this world and returns true if it was removed.boolean
removeDestructionListener(DestructionListener<T> listener)
Removes the given destruction listener from this world and returns true if it was removed.boolean
removeJoint(int index)
boolean
removeJoint(Joint<T> joint)
boolean
removeStepListener(StepListener<T> listener)
Removes the given step listener from this world and returns true if it was removed.boolean
removeTimeOfImpactListener(TimeOfImpactListener<T> listener)
Removes the given time of impact listener from this world and returns true if it was removed.void
setAccumulatedTime(double elapsedTime)
Sets the current accumulated time.void
setCoefficientMixer(CoefficientMixer coefficientMixer)
Deprecated.void
setContactConstraintSolver(ContactConstraintSolver<T> constraintSolver)
Sets theContactConstraintSolver
for this world.void
setContinuousCollisionDetectionBroadphaseDetector(BroadphaseDetector<T> broadphaseDetector)
Sets the CCD broad-phase collision detection algorithm.void
setGravity(double x, double y)
Sets the acceleration due to gravity.void
setGravity(Vector2 gravity)
Sets the acceleration due to gravity.void
setSettings(Settings settings)
Sets the dynamics settings for this world.void
setTimeOfImpactSolver(TimeOfImpactSolver<T> timeOfImpactSolver)
Sets theTimeOfImpactSolver
for this world.void
setUpdateRequired(boolean flag)
Sets the update required flag.void
setValueMixer(ValueMixer valueMixer)
Sets theValueMixer
.void
shift(Vector2 shift)
Translates the object to match the given coordinate shift.protected boolean
solveTOI(ContinuousDetectionMode mode)
Solves any Time-of-Impact events (collision events that were missed by the discrete collision detection algorithms).protected boolean
solveTOI(T body1, List<T> others, List<TimeOfImpactListener<T>> listeners)
Solves the time of impact for the givenPhysicsBody
.protected void
step()
Performs a full step of the engine.void
step(int steps)
Performs the given number of simulation steps using the step frequency inSettings
.void
step(int steps, double elapsedTime)
Performs the given number of simulation steps using the given elapsed time for each step.boolean
update(double elapsedTime)
Updates thePhysicsWorld
.boolean
update(double elapsedTime, double stepElapsedTime)
Updates theWorld
.boolean
update(double elapsedTime, double stepElapsedTime, int maximumSteps)
Updates theWorld
.boolean
update(double elapsedTime, int maximumSteps)
Updates theWorld
.void
updatev(double elapsedTime)
Updates theWorld
.-
Methods inherited from class AbstractCollisionWorld
addBoundsListener, addCollisionListener, containsBody, convexCast, convexCastClosest, convexCastClosest, convexCastIterator, createCollisionData, detect, detect, detect, detect, detect, detectIterator, detectIterator, detectIterator, detectIterator, getBodies, getBody, getBodyCount, getBodyIterator, getBounds, getBoundsListeners, getBroadphaseCollisionDataFilter, getBroadphaseDetector, getCollisionData, getCollisionDataIterator, getCollisionListeners, getManifoldSolver, getNarrowphaseDetector, getNarrowphasePostProcessor, getRaycastDetector, getTimeOfImpactDetector, getUserData, handleFixtureAdded, raycast, raycast, raycastClosest, raycastClosest, raycastIterator, raycastIterator, removeAllBoundsListeners, removeAllCollisionListeners, removeBoundsListener, removeCollisionListener, setBounds, setBroadphaseCollisionDataFilter, setBroadphaseDetector, setManifoldSolver, setNarrowphaseDetector, setNarrowphasePostProcessor, setRaycastDetector, setTimeOfImpactDetector, setUserData
-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface CollisionWorld
addBoundsListener, addCollisionListener, containsBody, convexCast, convexCastClosest, convexCastClosest, convexCastIterator, detect, detect, detect, detect, detectIterator, detectIterator, detectIterator, detectIterator, getBodies, getBody, getBodyCount, getBodyIterator, getBounds, getBoundsListeners, getBroadphaseCollisionDataFilter, getBroadphaseDetector, getCollisionData, getCollisionDataIterator, getCollisionListeners, getManifoldSolver, getNarrowphaseDetector, getNarrowphasePostProcessor, getRaycastDetector, getTimeOfImpactDetector, raycast, raycast, raycastClosest, raycastClosest, raycastIterator, raycastIterator, removeAllBoundsListeners, removeAllCollisionListeners, removeBoundsListener, removeCollisionListener, setBounds, setBroadphaseCollisionDataFilter, setBroadphaseDetector, setManifoldSolver, setNarrowphaseDetector, setNarrowphasePostProcessor, setRaycastDetector, setTimeOfImpactDetector
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
-
-
-
Field Detail
-
settings
protected final Settings settings
The dynamics settings for this world
-
gravity
protected final Vector2 gravity
The world gravity vector
-
valueMixer
protected ValueMixer valueMixer
TheValueMixer
-
contactConstraintSolver
protected ContactConstraintSolver<T extends PhysicsBody> contactConstraintSolver
-
timeOfImpactSolver
protected TimeOfImpactSolver<T extends PhysicsBody> timeOfImpactSolver
-
ccdBroadphase
protected BroadphaseDetector<T extends PhysicsBody> ccdBroadphase
The CCDBroadphaseDetector
-
joints
protected final List<Joint<T extends PhysicsBody>> joints
TheJoint
list
-
jointsUnmodifiable
protected final List<Joint<T extends PhysicsBody>> jointsUnmodifiable
The unmodifiableJoint
list
-
contactListeners
protected final List<ContactListener<T extends PhysicsBody>> contactListeners
The list ofContactListener
s
-
contactListenersUnmodifiable
protected final List<ContactListener<T extends PhysicsBody>> contactListenersUnmodifiable
The unmodifiable list ofContactListener
s
-
destructionListeners
protected final List<DestructionListener<T extends PhysicsBody>> destructionListeners
The list ofDestructionListener
s
-
destructionListenersUnmodifiable
protected final List<DestructionListener<T extends PhysicsBody>> destructionListenersUnmodifiable
The unmodifiable list ofDestructionListener
s
-
timeOfImpactListeners
protected final List<TimeOfImpactListener<T extends PhysicsBody>> timeOfImpactListeners
The list ofTimeOfImpactListener
s
-
timeOfImpactListenersUnmodifiable
protected final List<TimeOfImpactListener<T extends PhysicsBody>> timeOfImpactListenersUnmodifiable
The unmodifiable list ofTimeOfImpactListener
s
-
stepListeners
protected final List<StepListener<T extends PhysicsBody>> stepListeners
The list ofStepListener
s
-
stepListenersUnmodifiable
protected final List<StepListener<T extends PhysicsBody>> stepListenersUnmodifiable
The unmodifiable list ofStepListener
s
-
time
protected double time
The accumulated time
-
updateRequired
protected boolean updateRequired
True if an update to the collision data or interaction graph is needed before a step of the engine
-
constraintGraph
protected final ConstraintGraph<T extends PhysicsBody> constraintGraph
The constraint graph between bodies
-
contactCollisions
protected final List<V extends ContactCollisionData<T>> contactCollisions
A temporary list of only theContactConstraint
collisions from the last detection; cleared and refilled each step
-
ccdCollisionData
protected final Set<CollisionPair<T extends PhysicsBody>> ccdCollisionData
The full set of tracked CCD collision data
-
-
Constructor Detail
-
AbstractPhysicsWorld
public AbstractPhysicsWorld()
Default constructor.Uses the
CollisionWorld.DEFAULT_INITIAL_BODY_CAPACITY
andPhysicsWorld.DEFAULT_INITIAL_JOINT_CAPACITY
as the initial capacity.
-
AbstractPhysicsWorld
public AbstractPhysicsWorld(int initialBodyCapacity, int initialJointCapacity)
Optional constructor.- Parameters:
initialBodyCapacity
- the initial body capacityinitialJointCapacity
- the initial joint capacity
-
-
Method Detail
-
update
public boolean update(double elapsedTime)
Description copied from interface:PhysicsWorld
Updates thePhysicsWorld
.This method will only update the world given the step frequency contained in the
Settings
object. You can use theStepListener
interface to listen for when a step is actually performed. In addition, this method will return true if a step was performed.This method performs, at maximum, one simulation step. Any remaining time from the previous call of this method is added to the given elapsed time to determine if a step needs to be performed. If the given elapsed time is usually greater than the step frequency, consider using the
PhysicsWorld.update(double, int)
method instead.Alternatively you can call the
PhysicsWorld.updatev(double)
method to use a variable time step.- Specified by:
update
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
elapsedTime
- the elapsed time in seconds- Returns:
- boolean true if the
World
performed a simulation step - See Also:
PhysicsWorld.update(double, int)
,PhysicsWorld.updatev(double)
,PhysicsWorld.getAccumulatedTime()
-
update
public boolean update(double elapsedTime, int maximumSteps)
Description copied from interface:PhysicsWorld
Updates theWorld
.This method will only update the world given the step frequency contained in the
Settings
object. You can use theStepListener
interface to listen for when a step is actually performed.Unlike the
PhysicsWorld.update(double)
method, this method will perform more than one step based on the given elapsed time. For example, if the given elapsed time + the remaining time from the last call of this method is 2 * step frequency, then 2 steps will be performed. Use the maximumSteps parameter to put an upper bound on the number of steps performed.Alternatively you can call the
PhysicsWorld.updatev(double)
method to use a variable time step.- Specified by:
update
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
elapsedTime
- the elapsed time in secondsmaximumSteps
- the maximum number of steps to perform- Returns:
- boolean true if the
World
performed at least one simulation step - See Also:
PhysicsWorld.update(double)
,PhysicsWorld.updatev(double)
,PhysicsWorld.getAccumulatedTime()
-
update
public boolean update(double elapsedTime, double stepElapsedTime)
Description copied from interface:PhysicsWorld
Updates theWorld
.This method will only update the world given the step frequency contained in the
Settings
object. You can use theStepListener
interface to listen for when a step is actually performed. In addition, this method will return true if a step was performed.This method performs, at maximum, one simulation step. Any remaining time from the previous call of this method is added to the given elapsed time to determine if a step needs to be performed. If the given elapsed time is usually greater than the step frequency, consider using the
PhysicsWorld.update(double, int)
method instead.The stepElapsedTime parameter provides a way for the
World
to continue to update at the frequency defined in theSettings
object, but advance the simulation by the given time.Alternatively you can call the
PhysicsWorld.updatev(double)
method to use a variable time step.- Specified by:
update
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
elapsedTime
- the elapsed time in secondsstepElapsedTime
- the time, in seconds, that the simulation should be advanced- Returns:
- boolean true if the
World
performed at least one simulation step - See Also:
PhysicsWorld.update(double)
,PhysicsWorld.updatev(double)
,PhysicsWorld.getAccumulatedTime()
-
update
public boolean update(double elapsedTime, double stepElapsedTime, int maximumSteps)
Description copied from interface:PhysicsWorld
Updates theWorld
.This method will only update the world given the step frequency contained in the
Settings
object. You can use theStepListener
interface to listen for when a step is actually performed.Unlike the
PhysicsWorld.update(double)
method, this method will perform more than one step based on the given elapsed time. For example, if the given elapsed time + the remaining time from the last call of this method is 2 * step frequency, then 2 steps will be performed. Use the maximumSteps parameter to put an upper bound on the number of steps performed.The stepElapsedTime parameter provides a way for the
World
to continue to update at the frequency defined in theSettings
object, but advance the simulation by the given time.Alternatively you can call the
PhysicsWorld.updatev(double)
method to use a variable time step.- Specified by:
update
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
elapsedTime
- the elapsed time in secondsstepElapsedTime
- the time, in seconds, that the simulation should be advanced for each step; if less than or equal to zeroSettings.getStepFrequency()
will be usedmaximumSteps
- the maximum number of steps to perform- Returns:
- boolean true if the
World
performed at least one simulation step - See Also:
PhysicsWorld.update(double)
,PhysicsWorld.updatev(double)
,PhysicsWorld.getAccumulatedTime()
-
updatev
public void updatev(double elapsedTime)
Description copied from interface:PhysicsWorld
Updates theWorld
.This method will update the world on every call. Unlike the
PhysicsWorld.update(double)
method, this method uses the given elapsed time and does not attempt to update the world on a set interval.This method immediately returns if the given elapsedTime is less than or equal to zero.
- Specified by:
updatev
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
elapsedTime
- the elapsed time in seconds- See Also:
PhysicsWorld.update(double)
,PhysicsWorld.update(double, int)
-
step
public void step(int steps)
Description copied from interface:PhysicsWorld
Performs the given number of simulation steps using the step frequency inSettings
.This method immediately returns if the given step count is less than or equal to zero.
- Specified by:
step
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
steps
- the number of simulation steps to perform
-
step
public void step(int steps, double elapsedTime)
Description copied from interface:PhysicsWorld
Performs the given number of simulation steps using the given elapsed time for each step.This method immediately returns if the given elapsedTime or step count is less than or equal to zero.
- Specified by:
step
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
steps
- the number of simulation steps to performelapsedTime
- the elapsed time for each step
-
addBody
public void addBody(T body)
Description copied from interface:CollisionWorld
Adds the givenCollisionBody
to thisCollisionWorld
.- Specified by:
addBody
in interfaceCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Overrides:
addBody
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Parameters:
body
- theCollisionBody
to add
-
addJoint
public void addJoint(Joint<T> joint)
Description copied from interface:PhysicsWorld
- Specified by:
addJoint
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
joint
- theJoint
to add
-
containsJoint
public boolean containsJoint(Joint<T> joint)
Description copied from interface:PhysicsWorld
Returns true if this world contains the given joint.- Specified by:
containsJoint
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
joint
- theJoint
to test for- Returns:
- boolean true if the joint is contained in this world
-
removeJoint
public boolean removeJoint(int index)
Description copied from interface:PhysicsWorld
Removes theJoint
at the given index from thisWorld
.No other objects are implicitly destroyed with joints are removed.
- Specified by:
removeJoint
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
index
- the index of theJoint
to remove- Returns:
- boolean true if the
Joint
was removed
-
removeAllBodies
public void removeAllBodies()
Description copied from interface:CollisionWorld
Removes all bodies from this world.- Specified by:
removeAllBodies
in interfaceCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Overrides:
removeAllBodies
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
-
removeBody
public boolean removeBody(int index)
Description copied from interface:CollisionWorld
Removes theCollisionBody
at the given index from thisCollisionWorld
.- Specified by:
removeBody
in interfaceCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Overrides:
removeBody
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Parameters:
index
- the index of the body to remove.- Returns:
- boolean true if the body was removed
-
removeBody
public boolean removeBody(int index, boolean notify)
Description copied from interface:PhysicsWorld
Removes theCollisionBody
at the given index from thisCollisionWorld
.When a body is removed, joints and contacts may be implicitly destroyed. Pass true to the notify parameter to be notified of the destruction of these objects via the
DestructionListener
s.- Specified by:
removeBody
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
index
- the index of the body to remove.notify
- true if implicit destruction should be notified- Returns:
- boolean true if the body was removed
-
removeBody
public boolean removeBody(T body)
Description copied from interface:CollisionWorld
Removes the givenCollisionBody
from thisCollisionWorld
.- Specified by:
removeBody
in interfaceCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Overrides:
removeBody
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Parameters:
body
- theCollisionBody
to remove.- Returns:
- boolean true if the body was removed
-
removeAllBodiesAndJoints
public void removeAllBodiesAndJoints()
Description copied from interface:PhysicsWorld
Removes all the joints and bodies from this world.This method does not notify of destroyed objects.
- Specified by:
removeAllBodiesAndJoints
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- See Also:
PhysicsWorld.removeAllBodiesAndJoints(boolean)
-
removeAllJoints
public void removeAllJoints()
Description copied from interface:PhysicsWorld
- Specified by:
removeAllJoints
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- See Also:
PhysicsWorld.removeAllJoints(boolean)
-
removeAllBodiesAndJoints
public void removeAllBodiesAndJoints(boolean notify)
Description copied from interface:PhysicsWorld
Removes all the joints and bodies from this world.- Specified by:
removeAllBodiesAndJoints
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
notify
- true if destruction of joints and contacts should be notified of by theDestructionListener
-
destroyJoints
protected void destroyJoints(ConstraintGraphNode<T> node, boolean notify)
Destroys all joints associated with the given constraint graph node.- Parameters:
node
- the nodenotify
- true if destruction should emit notifications
-
destroyContacts
protected void destroyContacts(ConstraintGraphNode<T> node, BodyFixture fixture, boolean notify)
Destroys the contacts for the given graph node.- Parameters:
node
- the nodefixture
- the fixture of the contacts to destroy; null means to destroy allnotify
- true if destruction should emit notifications
-
removeBody
public boolean removeBody(T body, boolean notify)
Description copied from interface:PhysicsWorld
Removes the givenCollisionBody
from thisCollisionWorld
.When a body is removed, joints and contacts may be implicitly destroyed. Pass true to the notify parameter to be notified of the destruction of these objects via the
DestructionListener
s.- Specified by:
removeBody
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
body
- theCollisionBody
to removenotify
- true if implicit destruction should be notified- Returns:
- boolean true if the body was removed
-
removeJoint
public boolean removeJoint(Joint<T> joint)
Description copied from interface:PhysicsWorld
Removes the givenJoint
from thisWorld
.No other objects are implicitly destroyed with joints are removed.
- Specified by:
removeJoint
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
joint
- theJoint
to remove- Returns:
- boolean true if the
Joint
was removed
-
removeAllBodies
public void removeAllBodies(boolean notify)
Description copied from interface:PhysicsWorld
This is a convenience method for thePhysicsWorld.removeAllBodiesAndJoints(boolean)
method since all joints will be removed when all bodies are removed anyway.- Specified by:
removeAllBodies
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
notify
- true if destruction of joints and contacts should be notified of by theDestructionListener
-
clear
protected void clear()
Helper method to clear the world of bodies and joints.
-
removeAllJoints
public void removeAllJoints(boolean notify)
Description copied from interface:PhysicsWorld
- Specified by:
removeAllJoints
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
notify
- true if destruction of joints should be notified of by theDestructionListener
-
handleFixtureRemoved
protected void handleFixtureRemoved(T body, BodyFixture fixture)
Description copied from class:AbstractCollisionWorld
Handler for fixture removal.- Overrides:
handleFixtureRemoved
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Parameters:
body
- the body the fixture was removed fromfixture
- the fixture that was removed
-
handleAllFixturesRemoved
protected void handleAllFixturesRemoved(T body)
Description copied from class:AbstractCollisionWorld
Handler for all fixture removal.- Overrides:
handleAllFixturesRemoved
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Parameters:
body
- the body the fixtures were removed from
-
getSettings
public Settings getSettings()
Description copied from interface:PhysicsWorld
Returns the settings for this world.- Specified by:
getSettings
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
Settings
-
setSettings
public void setSettings(Settings settings)
Description copied from interface:PhysicsWorld
Sets the dynamics settings for this world.- Specified by:
setSettings
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
settings
- the desired settings
-
setGravity
public void setGravity(Vector2 gravity)
Description copied from interface:PhysicsWorld
Sets the acceleration due to gravity.- Specified by:
setGravity
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
gravity
- the gravity in meters/second2
-
setGravity
public void setGravity(double x, double y)
Description copied from interface:PhysicsWorld
Sets the acceleration due to gravity.- Specified by:
setGravity
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
x
- the x component of gravityy
- the y component of gravity
-
getGravity
public Vector2 getGravity()
Description copied from interface:PhysicsWorld
Returns the acceleration due to gravity.- Specified by:
getGravity
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
Vector2
the gravity in meters/second2
-
getCoefficientMixer
@Deprecated public CoefficientMixer getCoefficientMixer()
Deprecated.Description copied from interface:PhysicsWorld
Returns theCoefficientMixer
.- Specified by:
getCoefficientMixer
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
CoefficientMixer
- See Also:
PhysicsWorld.setCoefficientMixer(CoefficientMixer)
-
setCoefficientMixer
@Deprecated public void setCoefficientMixer(CoefficientMixer coefficientMixer)
Deprecated.Description copied from interface:PhysicsWorld
Sets theCoefficientMixer
.A
CoefficientMixer
is an implementation of mixing functions for various coefficients used in contact solving. Common coefficients are restitution and friction. Since eachBodyFixture
can have it's own value for these coefficients, theCoefficientMixer
is used to mathematically combine them into one coefficient to be used in contact resolution.ValueMixer.DEFAULT_MIXER
is the default.- Specified by:
setCoefficientMixer
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
coefficientMixer
- the coefficient mixer- See Also:
CoefficientMixer
-
getValueMixer
public ValueMixer getValueMixer()
Description copied from interface:PhysicsWorld
Returns theValueMixer
.- Specified by:
getValueMixer
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
ValueMixer
- See Also:
PhysicsWorld.setValueMixer(ValueMixer)
-
setValueMixer
public void setValueMixer(ValueMixer valueMixer)
Description copied from interface:PhysicsWorld
Sets theValueMixer
.A
ValueMixer
is an implementation of mixing functions for various values used in contact solving. Common mixed values are restitution and friction. Since eachBodyFixture
can have it's own value for these metrics, theValueMixer
is used to mathematically combine them into one value to be used in contact resolution.ValueMixer.DEFAULT_MIXER
is the default.- Specified by:
setValueMixer
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
valueMixer
- the value mixer- See Also:
ValueMixer
-
setContactConstraintSolver
public void setContactConstraintSolver(ContactConstraintSolver<T> constraintSolver)
Description copied from interface:PhysicsWorld
Sets theContactConstraintSolver
for this world.- Specified by:
setContactConstraintSolver
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
constraintSolver
- the contact constraint solver- See Also:
ContactConstraintSolver
-
getContactConstraintSolver
public ContactConstraintSolver<T> getContactConstraintSolver()
Description copied from interface:PhysicsWorld
Returns theContactConstraintSolver
.- Specified by:
getContactConstraintSolver
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
ContactConstraintSolver
- See Also:
PhysicsWorld.setContactConstraintSolver(ContactConstraintSolver)
-
getContinuousCollisionDetectionBroadphaseDetector
public BroadphaseDetector<T> getContinuousCollisionDetectionBroadphaseDetector()
Description copied from interface:PhysicsWorld
Returns the CCD broad-phase collision detection algorithm.- Specified by:
getContinuousCollisionDetectionBroadphaseDetector
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
BroadphaseDetector
<T>
-
setContinuousCollisionDetectionBroadphaseDetector
public void setContinuousCollisionDetectionBroadphaseDetector(BroadphaseDetector<T> broadphaseDetector)
Description copied from interface:PhysicsWorld
Sets the CCD broad-phase collision detection algorithm.- Specified by:
setContinuousCollisionDetectionBroadphaseDetector
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
broadphaseDetector
- the broad-phase detection algorithm
-
setTimeOfImpactSolver
public void setTimeOfImpactSolver(TimeOfImpactSolver<T> timeOfImpactSolver)
Description copied from interface:PhysicsWorld
Sets theTimeOfImpactSolver
for this world.- Specified by:
setTimeOfImpactSolver
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
timeOfImpactSolver
- the time of impact solver
-
getTimeOfImpactSolver
public TimeOfImpactSolver<T> getTimeOfImpactSolver()
Description copied from interface:PhysicsWorld
Returns theTimeOfImpactSolver
.- Specified by:
getTimeOfImpactSolver
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
TimeOfImpactSolver
-
getJointCount
public int getJointCount()
Description copied from interface:PhysicsWorld
- Specified by:
getJointCount
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- int the number of joints
-
getJoint
public Joint<T> getJoint(int index)
Description copied from interface:PhysicsWorld
Returns theJoint
at the given index.- Specified by:
getJoint
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
index
- the index- Returns:
Joint
-
getJoints
public List<Joint<T>> getJoints()
Description copied from interface:PhysicsWorld
Returns an unmodifiable list containing all the joints in this world.The returned list is backed by the internal list, therefore adding or removing joints while iterating through the returned list is not permitted. Use the
PhysicsWorld.getJointIterator()
method instead.- Specified by:
getJoints
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- List<
Joint
> - See Also:
PhysicsWorld.getJointIterator()
-
getJointIterator
public Iterator<Joint<T>> getJointIterator()
Description copied from interface:PhysicsWorld
Returns an iterator for iterating over the joints in this world.The returned iterator supports the
remove
method.- Specified by:
getJointIterator
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- Iterator<
Joint
>
-
getTimeStep
public TimeStep getTimeStep()
Description copied from interface:PhysicsWorld
Returns theTimeStep
object used to advance the simulation.The returned object contains the step information (elapsed time) for the last and the previous time step.
- Specified by:
getTimeStep
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
TimeStep
the current step object
-
getAccumulatedTime
public double getAccumulatedTime()
Description copied from interface:PhysicsWorld
Returns the current accumulated time.This is the time that has elapsed since the last step of the engine.
This time is used and/or accumulated on each call of the
PhysicsWorld.update(double)
andPhysicsWorld.update(double, int)
methods.This time is reduced by the step frequency for each step of the engine.
- Specified by:
getAccumulatedTime
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- double
-
setAccumulatedTime
public void setAccumulatedTime(double elapsedTime)
Description copied from interface:PhysicsWorld
Sets the current accumulated time.A typical use case would be to throw away any remaining time that the
PhysicsWorld.update(double)
orPhysicsWorld.update(double, int)
methods didn't use:boolean updated = world.update(elapsedTime); // the check if the world actually updated is crutial in this example if (updated) { // throw away any remaining time we didnt use world.setAccumulatedTime(0); }
Or, in the case of reusing the same World object, you could use this method to clear any accumulated time.If elapsedTime is less than zero, this method immediately returns.
- Specified by:
setAccumulatedTime
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
elapsedTime
- the desired elapsed time- See Also:
PhysicsWorld.getAccumulatedTime()
-
setUpdateRequired
public void setUpdateRequired(boolean flag)
Description copied from interface:PhysicsWorld
Sets the update required flag.This flag indicates that changes have been made to the bodies, fixtures, joints, etc. of this
PhysicsWorld
that require another collision detection cycle. The following conditions outline the common reasons a user would set this flag to true:- If a Body has been added or removed from the World
- If a Body has been translated or rotated
- If a Body's state has been manually changed via the Body.setActive(boolean) method
- If a BodyFixture has been added or removed from a Body
- If a BodyFixture's sensor flag has been manually changed via the BodyFixture.setSensor(boolean) method
- If a BodyFixture's filter has been manually changed via the BodyFixture.setFilter(boolean) method
- If a BodyFixture's restitution or friction coefficient has changed
- If a BodyFixture's Shape has been translated or rotated
- If a BodyFixture's Shape has been changed (vertices, radius, etc.)
- If a Body's type has changed to or from Static (this is caused by the using setMassType(Mass.INFINITE/Mass.NORMAL) method)
- If a Joint has been added or removed from the World in which the joined bodies should not be allowed to collide
- If the World's CoefficientMixer has been changed
- Specified by:
setUpdateRequired
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
flag
- the flag
-
isUpdateRequired
public boolean isUpdateRequired()
Description copied from interface:PhysicsWorld
Returns true if upon the next time step the contacts must be updated.- Specified by:
isUpdateRequired
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- boolean
- See Also:
PhysicsWorld.setUpdateRequired(boolean)
-
isEmpty
public boolean isEmpty()
Description copied from interface:CollisionWorld
Returns true if this world doesn't contain any bodies or joints.- Specified by:
isEmpty
in interfaceCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Overrides:
isEmpty
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Returns:
- boolean
-
shift
public void shift(Vector2 shift)
Description copied from interface:Shiftable
Translates the object to match the given coordinate shift.- Specified by:
shift
in interfaceShiftable
- Overrides:
shift
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Parameters:
shift
- the amount to shift along the x and y axes
-
isInContact
public boolean isInContact(T body1, T body2)
Description copied from interface:PhysicsWorld
Returns true if the givenPhysicsBody
s are currently in collision.Collision is defined as the two bodies interacting to the level of
ContactConstraint
generation and solving.- Specified by:
isInContact
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
body1
- the first bodybody2
- the second body- Returns:
- boolean
-
getContacts
public List<ContactConstraint<T>> getContacts(T body)
Description copied from interface:PhysicsWorld
Returns theContactConstraint
s for the givenPhysicsBody
.These represent the contact pairs between the given body and the others it's colliding with. Each
ContactConstraint
could have 1 or 2 contacts associated with it.- Specified by:
getContacts
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
body
- the body- Returns:
- List<
ContactConstraint
>
-
getInContactBodies
public List<T> getInContactBodies(T body, boolean includeSensedContact)
Description copied from interface:PhysicsWorld
Returns a list of allPhysicsBody
s that are in contact with the givenPhysicsBody
.- Specified by:
getInContactBodies
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
body
- the bodyincludeSensedContact
- true if sensed contacts should be included in the results- Returns:
- List<
PhysicsBody
>
-
isJointCollisionAllowed
public boolean isJointCollisionAllowed(T body1, T body2)
Description copied from interface:PhysicsWorld
Returns true if the twoPhysicsBody
s are joined by at least oneJoint
where the collision allowed property is true.- Specified by:
isJointCollisionAllowed
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
body1
- the first bodybody2
- the second body- Returns:
- boolean
-
isJoined
public boolean isJoined(T body1, T body2)
Description copied from interface:PhysicsWorld
Returns true if the twoPhysicsBody
s are joined via aJoint
.- Specified by:
isJoined
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
body1
- the first bodybody2
- the second body- Returns:
- boolean
-
getJoints
public List<Joint<T>> getJoints(T body)
Description copied from interface:PhysicsWorld
Returns theJoint
s the givenPhysicsBody
is a member of.- Specified by:
getJoints
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
body
- the body- Returns:
- List<
Joint
>
-
getJoinedBodies
public List<T> getJoinedBodies(T body)
Description copied from interface:PhysicsWorld
- Specified by:
getJoinedBodies
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
body
- the body- Returns:
- List<
PhysicsBody
>
-
getContactListeners
public List<ContactListener<T>> getContactListeners()
Description copied from interface:PhysicsWorld
Returns an unmodifiable list of all the contact listeners registered to this world.- Specified by:
getContactListeners
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- List<
ContactListener
>
-
getDestructionListeners
public List<DestructionListener<T>> getDestructionListeners()
Description copied from interface:PhysicsWorld
Returns an unmodifiable list of all the destruction listeners registered to this world.- Specified by:
getDestructionListeners
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- List<
DestructionListener
>
-
getStepListeners
public List<StepListener<T>> getStepListeners()
Description copied from interface:PhysicsWorld
Returns an unmodifiable list of all the step listeners registered to this world.- Specified by:
getStepListeners
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- List<
StepListener
>
-
getTimeOfImpactListeners
public List<TimeOfImpactListener<T>> getTimeOfImpactListeners()
Description copied from interface:PhysicsWorld
Returns an unmodifiable list of all the time of impact listeners registered to this world.- Specified by:
getTimeOfImpactListeners
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Returns:
- List<
TimeOfImpactListener
>
-
removeAllListeners
public void removeAllListeners()
Description copied from interface:CollisionWorld
Removes all listeners from this world.- Specified by:
removeAllListeners
in interfaceCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Overrides:
removeAllListeners
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
-
removeAllContactListeners
public void removeAllContactListeners()
Description copied from interface:PhysicsWorld
Removes all contact listeners from this world.- Specified by:
removeAllContactListeners
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
-
removeAllDestructionListeners
public void removeAllDestructionListeners()
Description copied from interface:PhysicsWorld
Removes all destruction listeners from this world.- Specified by:
removeAllDestructionListeners
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
-
removeAllStepListeners
public void removeAllStepListeners()
Description copied from interface:PhysicsWorld
Removes all step listeners from this world.- Specified by:
removeAllStepListeners
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
-
removeAllTimeOfImpactListeners
public void removeAllTimeOfImpactListeners()
Description copied from interface:PhysicsWorld
Removes all time of impact listeners from this world.- Specified by:
removeAllTimeOfImpactListeners
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
-
removeContactListener
public boolean removeContactListener(ContactListener<T> listener)
Description copied from interface:PhysicsWorld
Removes the given contact listener from this world and returns true if it was removed.This method will return false if the listener was not found in this world.
- Specified by:
removeContactListener
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
listener
- the listener- Returns:
- boolean
-
removeDestructionListener
public boolean removeDestructionListener(DestructionListener<T> listener)
Description copied from interface:PhysicsWorld
Removes the given destruction listener from this world and returns true if it was removed.This method will return false if the listener was not found in this world.
- Specified by:
removeDestructionListener
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
listener
- the listener- Returns:
- boolean
-
removeStepListener
public boolean removeStepListener(StepListener<T> listener)
Description copied from interface:PhysicsWorld
Removes the given step listener from this world and returns true if it was removed.This method will return false if the listener was not found in this world.
- Specified by:
removeStepListener
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
listener
- the listener- Returns:
- boolean
-
removeTimeOfImpactListener
public boolean removeTimeOfImpactListener(TimeOfImpactListener<T> listener)
Description copied from interface:PhysicsWorld
Removes the given time of impact listener from this world and returns true if it was removed.This method will return false if the listener was not found in this world.
- Specified by:
removeTimeOfImpactListener
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
listener
- the listener- Returns:
- boolean
-
addContactListener
public boolean addContactListener(ContactListener<T> listener)
Description copied from interface:PhysicsWorld
Adds the givenContactListener
to this world.NOTE: No effort is made to prevent duplicate listeners from being added.
- Specified by:
addContactListener
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
listener
- the listener to add- Returns:
- boolean
-
addDestructionListener
public boolean addDestructionListener(DestructionListener<T> listener)
Description copied from interface:PhysicsWorld
Adds the givenDestructionListener
to this world.NOTE: No effort is made to prevent duplicate listeners from being added.
- Specified by:
addDestructionListener
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
listener
- the listener to add- Returns:
- boolean
-
addStepListener
public boolean addStepListener(StepListener<T> listener)
Description copied from interface:PhysicsWorld
Adds the givenStepListener
to this world.NOTE: No effort is made to prevent duplicate listeners from being added.
- Specified by:
addStepListener
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
listener
- the listener to add- Returns:
- boolean
-
addTimeOfImpactListener
public boolean addTimeOfImpactListener(TimeOfImpactListener<T> listener)
Description copied from interface:PhysicsWorld
Adds the givenTimeOfImpactListener
to this world.NOTE: No effort is made to prevent duplicate listeners from being added.
- Specified by:
addTimeOfImpactListener
in interfacePhysicsWorld<T extends PhysicsBody,V extends ContactCollisionData<T>>
- Parameters:
listener
- the listener to add- Returns:
- boolean
-
step
protected void step()
Performs a full step of the engine.
-
processCollisions
protected void processCollisions(Iterator<V> iterator)
Description copied from class:AbstractCollisionWorld
This method should process the collisions returned by the given iterator.The given iterator will emit collision data for all collision pairs and it's the responsibility of the sub class to do something with these.
At a minimum, sub classes should drain the given iterator:
while (iterator.hasNext()) { iterator.next(); }
- Specified by:
processCollisions
in classAbstractCollisionWorld<T extends PhysicsBody,BodyFixture,V extends ContactCollisionData<T>>
- Parameters:
iterator
- the collision iterator
-
solveTOI
protected boolean solveTOI(ContinuousDetectionMode mode)
Solves any Time-of-Impact events (collision events that were missed by the discrete collision detection algorithms).Returns true if any TOI event was resolved. When true, the bodies involved had their transforms modified an another discrete collision detection is required.
- Parameters:
mode
- the mode- Returns:
- boolean
-
solveTOI
protected boolean solveTOI(T body1, List<T> others, List<TimeOfImpactListener<T>> listeners)
Solves the time of impact for the givenPhysicsBody
.This method will find the first
PhysicsBody
that the givenPhysicsBody
collides with unless ignored via theTimeOfImpactListener
.If any
TimeOfImpactListener
doesn't allow the collision then the collision is ignored.After the first
PhysicsBody
is found the twoPhysicsBody
s are interpolated to the time of impact.Then the
PhysicsBody
s are position solved using theTimeOfImpactSolver
to force thePhysicsBody
s into collision. This causes the discrete collision detector to detect the collision on the next time step.- Parameters:
body1
- thePhysicsBody
others
- the other bodies to test againstlisteners
- the list ofTimeOfImpactListener
s- Returns:
- boolean true if a time of impact event was resolved
- Since:
- 3.1.0
-
-