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.0.1
- Author:
- William Bittle
-
-
Field Summary
-
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 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.boolean
containsJoint(Joint<T> joint)
Returns true if this world contains the given joint.double
getAccumulatedTime()
Returns the current accumulated time.CoefficientMixer
getCoefficientMixer()
Returns theCoefficientMixer
.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
.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.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.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)
Sets theCoefficientMixer
.void
setContactConstraintSolver(ContactConstraintSolver<T> constraintSolver)
Sets theContactConstraintSolver
for this world.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
shift(Vector2 shift)
Translates the object to match the given coordinate shift.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, detect, detect, detect, detect, detectIterator, detectIterator, detectIterator, detectIterator, getBodies, getBody, getBodyCount, getBodyIterator, getBounds, getBoundsListeners, getBroadphaseDetector, getBroadphaseFilter, getCollisionData, getCollisionDataIterator, getCollisionListeners, getManifoldSolver, getNarrowphaseDetector, getNarrowphasePostProcessor, getRaycastDetector, getTimeOfImpactDetector, getUserData, raycast, raycast, raycastClosest, raycastClosest, raycastIterator, raycastIterator, removeAllBoundsListeners, removeAllCollisionListeners, removeBoundsListener, removeCollisionListener, setBounds, setBroadphaseDetector, setBroadphaseFilter, setManifoldSolver, setNarrowphaseDetector, setNarrowphasePostProcessor, setRaycastDetector, setTimeOfImpactDetector, setUserData
-
Methods inherited from class Object
equals, 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, getBroadphaseDetector, getBroadphaseFilter, getCollisionData, getCollisionDataIterator, getCollisionListeners, getManifoldSolver, getNarrowphaseDetector, getNarrowphasePostProcessor, getRaycastDetector, getTimeOfImpactDetector, raycast, raycast, raycastClosest, raycastClosest, raycastIterator, raycastIterator, removeAllBoundsListeners, removeAllCollisionListeners, removeBoundsListener, removeCollisionListener, setBounds, setBroadphaseDetector, setBroadphaseFilter, setManifoldSolver, setNarrowphaseDetector, setNarrowphasePostProcessor, setRaycastDetector, setTimeOfImpactDetector
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
-
-
-
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
-
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
-
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
-
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
public CoefficientMixer getCoefficientMixer()
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
public void setCoefficientMixer(CoefficientMixer coefficientMixer)
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.CoefficientMixer.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
-
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)
-
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
-
-