- Object
-
- AbstractCollisionBody<BodyFixture>
-
- AbstractPhysicsBody
-
- All Implemented Interfaces:
CollisionBody<BodyFixture>
,DataContainer
,PhysicsBody
,Rotatable
,Shiftable
,Transformable
,Translatable
,Ownable
- Direct Known Subclasses:
Body
public abstract class AbstractPhysicsBody extends AbstractCollisionBody<BodyFixture> implements PhysicsBody, CollisionBody<BodyFixture>, Transformable, DataContainer, Ownable
Abstract implementation of thePhysicsBody
interface.- Since:
- 4.0.0
- Version:
- 4.1.0
- Author:
- William Bittle
-
-
Field Summary
Fields Modifier and Type Field Description protected double
angularDamping
TheAbstractPhysicsBody
's angular dampingprotected double
angularVelocity
The current angular velocityprotected boolean
atRest
True if the body is at-restprotected boolean
atRestDetectionEnabled
True if at-rest detection is enabledprotected double
atRestTime
The time that thePhysicsBody
has been at-restprotected boolean
bullet
True if the body is fast, small or bothprotected Vector2
force
The current forceprotected List<Force>
forces
The force accumulatorprotected double
gravityScale
The per body gravity scale factorprotected double
linearDamping
TheAbstractPhysicsBody
's linear dampingprotected Vector2
linearVelocity
The current linear velocityprotected Mass
mass
TheMass
informationprotected double
torque
The current torqueprotected List<Torque>
torques
The torque accumulator-
Fields inherited from class AbstractCollisionBody
enabled, fixtureModificationHandler, fixtures, fixturesUnmodifiable, owner, radius, transform, transform0, userData
-
Fields inherited from interface CollisionBody
TYPICAL_FIXTURE_COUNT
-
Fields inherited from interface PhysicsBody
DEFAULT_ANGULAR_DAMPING, DEFAULT_LINEAR_DAMPING
-
-
Constructor Summary
Constructors Constructor Description AbstractPhysicsBody()
Default constructor.AbstractPhysicsBody(int fixtureCount)
Optional constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
accumulate(double elapsedTime)
Accumulates the forces and torques.BodyFixture
addFixture(Convex convex)
BodyFixture
addFixture(Convex convex, double density)
Creates aBodyFixture
for the givenConvex
Shape
, adds it to thePhysicsBody
, and returns it for configuration.BodyFixture
addFixture(Convex convex, double density, double friction, double restitution)
Creates aBodyFixture
for the givenConvex
Shape
, adds it to thePhysicsBody
, and returns it for configuration.AbstractPhysicsBody
applyForce(Force force)
Applies the givenForce
to thisPhysicsBody
.AbstractPhysicsBody
applyForce(Vector2 force)
Applies the given force to thisPhysicsBody
.AbstractPhysicsBody
applyForce(Vector2 force, Vector2 point)
Applies the given force to thisPhysicsBody
at the given point (torque).AbstractPhysicsBody
applyImpulse(double impulse)
Applies an angular impulse to thisPhysicsBody
about its center of mass.AbstractPhysicsBody
applyImpulse(Vector2 impulse)
Applies a linear impulse to thisPhysicsBody
at its center of mass.AbstractPhysicsBody
applyImpulse(Vector2 impulse, Vector2 point)
Applies an impulse to thisPhysicsBody
at the given point.AbstractPhysicsBody
applyTorque(double torque)
Applies the given torque about the center of thisPhysicsBody
.AbstractPhysicsBody
applyTorque(Torque torque)
Applies the givenTorque
to thisPhysicsBody
.void
clearAccumulatedForce()
Clears the forces stored in the force accumulator.void
clearAccumulatedTorque()
Clears the torques stored in the torque accumulator.void
clearForce()
Clears the last time step's force on thePhysicsBody
.void
clearTorque()
Clears the last time step's torque on thePhysicsBody
.void
computeSweptAABB(AABB result)
Computes a sweptAABB
that contains the maximal space in which thePhysicsBody
exists from the initial transform to the final transform and places the result in the given AABB.void
computeSweptAABB(Transform initialTransform, Transform finalTransform, AABB result)
Computes a sweptAABB
from the given start and endTransform
s using the fixtures on thisPhysicsBody
and places the result in the given AABB.AABB
createSweptAABB()
Returns a sweptAABB
that contains the maximal space in which thePhysicsBody
exists from the initial transform to the final transform.AABB
createSweptAABB(Transform initialTransform, Transform finalTransform)
Creates a sweptAABB
from the given start and endTransform
s using the fixtures on thisPhysicsBody
.Vector2
getAccumulatedForce()
Returns the total force currently stored in the force accumulator.double
getAccumulatedTorque()
Returns the total torque currently stored in the torque accumulator.double
getAngularDamping()
Returns the angular damping.double
getAngularVelocity()
Returns the angular velocity.double
getChangeInOrientation()
Returns the change in orientation computed from last frame's transform and this frame's transform.Vector2
getChangeInPosition()
Returns the change in position computed from last frame's transform and this frame's transform.Vector2
getForce()
Returns the force applied in the last iteration.double
getGravityScale()
Returns the gravity scale.double
getLinearDamping()
Returns the linear damping.Vector2
getLinearVelocity()
Returns the linear velocity.Vector2
getLinearVelocity(Vector2 point)
Returns the velocity of this body at the given world space point.Vector2
getLocalCenter()
Returns the center for thisCollisionBody
in local coordinates.Mass
getMass()
Returns thisPhysicsBody
's mass information.double
getTorque()
Returns the torque applied in the last iteration.Vector2
getWorldCenter()
Returns the center for thisCollisionBody
in world coordinates.void
integratePosition(TimeStep timestep, Settings settings)
Integrates the linear and angular velocities to update the position and rotation of this bodyvoid
integrateVelocity(Vector2 gravity, TimeStep timestep, Settings settings)
Integrates the forces, torques, and gravity to update the linear and angular velocity of this body.boolean
isAtRest()
Returns true if thisPhysicsBody
is at-rest.boolean
isAtRestDetectionEnabled()
Returns true if thisPhysicsBody
can participate in automatic at-rest detection.boolean
isBullet()
Returns true if thisPhysicsBody
is a bullet.boolean
isDynamic()
Returns true if this body's mass type is NOTMassType.INFINITE
.boolean
isKinematic()
Returns true if this body's mass type isMassType.INFINITE
and either the linear or angular velocity are NOT zero (i.e.boolean
isStatic()
Returns true if this body's mass type isMassType.INFINITE
and the linear and angular velocity are close to zero (as determined byEpsilon.E
.void
setAngularDamping(double angularDamping)
Sets the angular damping.void
setAngularVelocity(double angularVelocity)
Sets the angular velocity in radians per secondvoid
setAtRest(boolean flag)
Sets whether thisPhysicsBody
is at-rest or not.void
setAtRestDetectionEnabled(boolean flag)
Determines whether thisPhysicsBody
can participate in automatic at-rest detection.void
setBullet(boolean flag)
Sets the bullet flag for thisPhysicsBody
.void
setGravityScale(double scale)
Sets the gravity scale.void
setLinearDamping(double linearDamping)
Sets the linear damping.void
setLinearVelocity(double x, double y)
Sets the linear velocity.void
setLinearVelocity(Vector2 velocity)
Sets the linear velocity.AbstractPhysicsBody
setMass(Mass mass)
Explicitly sets thisPhysicsBody
's mass information.AbstractPhysicsBody
setMass(MassType type)
This method should be called after fixture modification is complete.AbstractPhysicsBody
setMassType(MassType type)
Sets theMassType
of thisPhysicsBody
.String
toString()
double
updateAtRestTime(TimeStep timestep, Settings settings)
Updates the at-rest time for this body based on the given timestep and returns the current at-rest time.AbstractPhysicsBody
updateMass()
This is a shortcut method for thePhysicsBody.setMass(org.dyn4j.geometry.MassType)
method that will use the current mass type as the mass type and then recompute the mass from the body's fixtures.-
Methods inherited from class AbstractCollisionBody
addFixture, computeAABB, computeAABB, contains, containsFixture, createAABB, createAABB, getFixture, getFixture, getFixtureCount, getFixtureIterator, getFixtureModificationHandler, getFixtures, getFixtures, getLocalPoint, getLocalVector, getOwner, getPreviousTransform, getRotationDiscRadius, getTransform, getUserData, getWorldPoint, getWorldVector, isEnabled, removeAllFixtures, removeFixture, removeFixture, removeFixture, removeFixtures, rotate, rotate, rotate, rotate, rotate, rotate, rotateAboutCenter, setEnabled, setFixtureModificationHandler, setOwner, setRotationDiscRadius, setTransform, setUserData, shift, translate, translate, translateToOrigin
-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface CollisionBody
addFixture, computeAABB, computeAABB, contains, containsFixture, createAABB, createAABB, getFixture, getFixture, getFixtureCount, getFixtureIterator, getFixtureModificationHandler, getFixtures, getFixtures, getLocalPoint, getLocalVector, getPreviousTransform, getRotationDiscRadius, getTransform, getWorldPoint, getWorldVector, isEnabled, removeAllFixtures, removeFixture, removeFixture, removeFixture, removeFixtures, rotateAboutCenter, setEnabled, setFixtureModificationHandler, setTransform, translateToOrigin
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
Methods inherited from interface Translatable
translate, translate
-
-
-
-
Field Detail
-
linearVelocity
protected final Vector2 linearVelocity
The current linear velocity
-
angularVelocity
protected double angularVelocity
The current angular velocity
-
linearDamping
protected double linearDamping
TheAbstractPhysicsBody
's linear damping
-
angularDamping
protected double angularDamping
TheAbstractPhysicsBody
's angular damping
-
gravityScale
protected double gravityScale
The per body gravity scale factor
-
bullet
protected boolean bullet
True if the body is fast, small or both
-
atRestDetectionEnabled
protected boolean atRestDetectionEnabled
True if at-rest detection is enabled
-
atRest
protected boolean atRest
True if the body is at-rest
-
atRestTime
protected double atRestTime
The time that thePhysicsBody
has been at-rest
-
force
protected final Vector2 force
The current force
-
torque
protected double torque
The current torque
-
-
Constructor Detail
-
AbstractPhysicsBody
public AbstractPhysicsBody()
Default constructor.
-
AbstractPhysicsBody
public AbstractPhysicsBody(int fixtureCount)
Optional constructor.Creates a new
AbstractPhysicsBody
using the given estimated fixture count. Assignment of the initial fixture count allows sizing of internal structures for optimal memory/performance. This estimated fixture count is not a limit on the number of fixtures.- Parameters:
fixtureCount
- the estimated number of fixtures- Throws:
IllegalArgumentException
- if fixtureCount less than zero- Since:
- 3.1.1
-
-
Method Detail
-
addFixture
public BodyFixture addFixture(Convex convex)
Description copied from interface:CollisionBody
- Specified by:
addFixture
in interfaceCollisionBody<BodyFixture>
- Parameters:
convex
- theConvex
Shape
to add- Returns:
- T the fixture created
-
addFixture
public BodyFixture addFixture(Convex convex, double density)
Description copied from interface:PhysicsBody
Creates aBodyFixture
for the givenConvex
Shape
, adds it to thePhysicsBody
, and returns it for configuration.After adding or removing fixtures make sure to call the
PhysicsBody.updateMass()
orPhysicsBody.setMass(MassType)
method to compute the new totalMass
for the body.This is a convenience method for setting the density of a
BodyFixture
.- Specified by:
addFixture
in interfacePhysicsBody
- Parameters:
convex
- theConvex
Shape
to add to thePhysicsBody
density
- the density of the shape in kg/m2; in the range (0.0, ∞]- Returns:
BodyFixture
the fixture created using the givenShape
and added to thePhysicsBody
- See Also:
CollisionBody.addFixture(Convex)
,PhysicsBody.addFixture(Convex, double, double, double)
-
addFixture
public BodyFixture addFixture(Convex convex, double density, double friction, double restitution)
Description copied from interface:PhysicsBody
Creates aBodyFixture
for the givenConvex
Shape
, adds it to thePhysicsBody
, and returns it for configuration.After adding or removing fixtures make sure to call the
PhysicsBody.updateMass()
orPhysicsBody.setMass(MassType)
method to compute the new totalMass
for the body.This is a convenience method for setting the properties of a
BodyFixture
. Use theBodyFixture.DEFAULT_DENSITY
,BodyFixture.DEFAULT_FRICTION
, andBodyFixture.DEFAULT_RESTITUTION
values if you need to only set one of these properties.- Specified by:
addFixture
in interfacePhysicsBody
- Parameters:
convex
- theConvex
Shape
to add to thePhysicsBody
density
- the density of the shape in kg/m2; in the range (0.0, ∞]friction
- the coefficient of friction; in the range [0.0, ∞]restitution
- the coefficient of restitution; in the range [0.0, ∞]- Returns:
BodyFixture
the fixture created using the givenShape
and added to thePhysicsBody
- See Also:
CollisionBody.addFixture(Convex)
,PhysicsBody.addFixture(Convex, double)
-
updateMass
public AbstractPhysicsBody updateMass()
Description copied from interface:PhysicsBody
This is a shortcut method for thePhysicsBody.setMass(org.dyn4j.geometry.MassType)
method that will use the current mass type as the mass type and then recompute the mass from the body's fixtures.- Specified by:
updateMass
in interfacePhysicsBody
- Returns:
PhysicsBody
this body- See Also:
PhysicsBody.setMass(org.dyn4j.geometry.MassType)
-
setMass
public AbstractPhysicsBody setMass(MassType type)
Description copied from interface:PhysicsBody
This method should be called after fixture modification is complete.This method will calculate a total mass for the body given the masses of the attached fixtures.
A
MassType
can be used to create special mass types.- Specified by:
setMass
in interfacePhysicsBody
- Parameters:
type
- the mass type- Returns:
PhysicsBody
this body
-
setMass
public AbstractPhysicsBody setMass(Mass mass)
Description copied from interface:PhysicsBody
Explicitly sets thisPhysicsBody
's mass information.- Specified by:
setMass
in interfacePhysicsBody
- Parameters:
mass
- the newMass
- Returns:
PhysicsBody
this body
-
setMassType
public AbstractPhysicsBody setMassType(MassType type)
Description copied from interface:PhysicsBody
Sets theMassType
of thisPhysicsBody
.This method does not compute/recompute the mass of the body but solely sets the mass type to one of the special types.
Since its possible to create a
Mass
object with zero mass and/or zero inertia (Mass m = new Mass(new Vector2(), 0, 0);
for example), setting the type to something other than MassType.INFINITE can have undefined results.- Specified by:
setMassType
in interfacePhysicsBody
- Parameters:
type
- the desired type- Returns:
PhysicsBody
this body
-
getMass
public Mass getMass()
Description copied from interface:PhysicsBody
Returns thisPhysicsBody
's mass information.- Specified by:
getMass
in interfacePhysicsBody
- Returns:
Mass
-
applyForce
public AbstractPhysicsBody applyForce(Vector2 force)
Description copied from interface:PhysicsBody
Applies the given force to thisPhysicsBody
.This method will wake-up the body if its sleeping.
This method does not apply the force if this body returns zero from the
Mass.getMass()
method.The force is not applied immediately, but instead stored in the force accumulator (
PhysicsBody.getAccumulatedForce()
). This is to preserve the last time step's computed force (PhysicsBody.getForce()
.The force is assumed to be in world space coordinates.
- Specified by:
applyForce
in interfacePhysicsBody
- Parameters:
force
- the force- Returns:
PhysicsBody
this body
-
applyForce
public AbstractPhysicsBody applyForce(Force force)
Description copied from interface:PhysicsBody
Applies the givenForce
to thisPhysicsBody
.This method will wake-up the body if its sleeping.
This method does not apply the force if this body returns zero from the
Mass.getMass()
method.The force is not applied immediately, but instead stored in the force accumulator (
PhysicsBody.getAccumulatedForce()
). This is to preserve the last time step's computed force (PhysicsBody.getForce()
.The force is assumed to be in world space coordinates.
- Specified by:
applyForce
in interfacePhysicsBody
- Parameters:
force
- the force- Returns:
PhysicsBody
this body
-
applyTorque
public AbstractPhysicsBody applyTorque(double torque)
Description copied from interface:PhysicsBody
Applies the given torque about the center of thisPhysicsBody
.This method will wake-up the body if its sleeping.
This method does not apply the torque if this body returns zero from the
Mass.getInertia()
method.The torque is not applied immediately, but instead stored in the torque accumulator (
PhysicsBody.getAccumulatedTorque()
). This is to preserve the last time step's computed torque (PhysicsBody.getTorque()
.- Specified by:
applyTorque
in interfacePhysicsBody
- Parameters:
torque
- the torque about the center- Returns:
PhysicsBody
this body
-
applyTorque
public AbstractPhysicsBody applyTorque(Torque torque)
Description copied from interface:PhysicsBody
Applies the givenTorque
to thisPhysicsBody
.This method will wake-up the body if its sleeping.
This method does not apply the torque if this body returns zero from the
Mass.getInertia()
method.The torque is not applied immediately, but instead stored in the torque accumulator (
PhysicsBody.getAccumulatedTorque()
). This is to preserve the last time step's computed torque (PhysicsBody.getTorque()
.- Specified by:
applyTorque
in interfacePhysicsBody
- Parameters:
torque
- the torque- Returns:
PhysicsBody
this body
-
applyForce
public AbstractPhysicsBody applyForce(Vector2 force, Vector2 point)
Description copied from interface:PhysicsBody
Applies the given force to thisPhysicsBody
at the given point (torque).This method will wake-up the body if its sleeping.
This method does not apply the force if this body returns zero from the
Mass.getMass()
method nor will it apply the torque if this body returns zero from theMass.getInertia()
method.The force/torque is not applied immediately, but instead stored in the force/torque accumulators (
PhysicsBody.getAccumulatedForce()
andPhysicsBody.getAccumulatedTorque()
). This is to preserve the last time step's computed force (PhysicsBody.getForce()
and torque (PhysicsBody.getTorque()
).The force and point are assumed to be in world space coordinates.
- Specified by:
applyForce
in interfacePhysicsBody
- Parameters:
force
- the forcepoint
- the application point in world coordinates- Returns:
PhysicsBody
this body
-
applyImpulse
public AbstractPhysicsBody applyImpulse(Vector2 impulse)
Description copied from interface:PhysicsBody
Applies a linear impulse to thisPhysicsBody
at its center of mass.This method will wake-up the body if its sleeping.
This method does not apply the impulse if this body's mass returns zero from the
Mass.getInertia()
method.NOTE: Applying an impulse differs from applying a force and/or torque. Forces and torques are stored in accumulators, but impulses are applied to the velocities of the body immediately.
The impulse is assumed to be in world space coordinates.
- Specified by:
applyImpulse
in interfacePhysicsBody
- Parameters:
impulse
- the impulse to apply- Returns:
PhysicsBody
this body
-
applyImpulse
public AbstractPhysicsBody applyImpulse(double impulse)
Description copied from interface:PhysicsBody
Applies an angular impulse to thisPhysicsBody
about its center of mass.This method will wake-up the body if its sleeping.
This method does not apply the impulse if this body's inertia returns zero from the
Mass.getInertia()
method.NOTE: Applying an impulse differs from applying a force and/or torque. Forces and torques are stored in accumulators, but impulses are applied to the velocities of the body immediately.
- Specified by:
applyImpulse
in interfacePhysicsBody
- Parameters:
impulse
- the impulse to apply- Returns:
PhysicsBody
this body
-
applyImpulse
public AbstractPhysicsBody applyImpulse(Vector2 impulse, Vector2 point)
Description copied from interface:PhysicsBody
Applies an impulse to thisPhysicsBody
at the given point.This method will wake-up the body if its sleeping.
This method does not apply the linear impulse if this body returns zero from the
Mass.getMass()
method nor will it apply the angular impulse if this body returns zero from theMass.getInertia()
method.NOTE: Applying an impulse differs from applying a force and/or torque. Forces and torques are stored in accumulators, but impulses are applied to the velocities of the body immediately.
The impulse and point are assumed to be in world space coordinates.
- Specified by:
applyImpulse
in interfacePhysicsBody
- Parameters:
impulse
- the impulse to applypoint
- the world space point to apply the impulse- Returns:
PhysicsBody
this body
-
clearForce
public void clearForce()
Description copied from interface:PhysicsBody
Clears the last time step's force on thePhysicsBody
.- Specified by:
clearForce
in interfacePhysicsBody
-
clearAccumulatedForce
public void clearAccumulatedForce()
Description copied from interface:PhysicsBody
Clears the forces stored in the force accumulator.Renamed from clearForces (3.0.0 and below).
- Specified by:
clearAccumulatedForce
in interfacePhysicsBody
-
clearTorque
public void clearTorque()
Description copied from interface:PhysicsBody
Clears the last time step's torque on thePhysicsBody
.- Specified by:
clearTorque
in interfacePhysicsBody
-
clearAccumulatedTorque
public void clearAccumulatedTorque()
Description copied from interface:PhysicsBody
Clears the torques stored in the torque accumulator.Renamed from clearTorques (3.0.0 and below).
- Specified by:
clearAccumulatedTorque
in interfacePhysicsBody
-
accumulate
protected void accumulate(double elapsedTime)
Accumulates the forces and torques.- Parameters:
elapsedTime
- the elapsed time since the last call- Since:
- 3.1.0
-
integrateVelocity
public void integrateVelocity(Vector2 gravity, TimeStep timestep, Settings settings)
Description copied from interface:PhysicsBody
Integrates the forces, torques, and gravity to update the linear and angular velocity of this body.- Specified by:
integrateVelocity
in interfacePhysicsBody
- Parameters:
gravity
- the world gravitytimestep
- the timestep informationsettings
- the world settings
-
integratePosition
public void integratePosition(TimeStep timestep, Settings settings)
Description copied from interface:PhysicsBody
Integrates the linear and angular velocities to update the position and rotation of this body- Specified by:
integratePosition
in interfacePhysicsBody
- Parameters:
timestep
- the timestep informationsettings
- the world settings
-
updateAtRestTime
public double updateAtRestTime(TimeStep timestep, Settings settings)
Description copied from interface:PhysicsBody
Updates the at-rest time for this body based on the given timestep and returns the current at-rest time.For
PhysicsBody.isStatic()
bodies, this method will return -1 to indicate that this body can always be at-rest since it's velocity is zero and cannot be moved.- Specified by:
updateAtRestTime
in interfacePhysicsBody
- Parameters:
timestep
- the timestep informationsettings
- the world settings- Returns:
- double
-
isStatic
public boolean isStatic()
Description copied from interface:PhysicsBody
Returns true if this body's mass type isMassType.INFINITE
and the linear and angular velocity are close to zero (as determined byEpsilon.E
.- Specified by:
isStatic
in interfacePhysicsBody
- Returns:
- boolean
-
isKinematic
public boolean isKinematic()
Description copied from interface:PhysicsBody
Returns true if this body's mass type isMassType.INFINITE
and either the linear or angular velocity are NOT zero (i.e. it's moving).- Specified by:
isKinematic
in interfacePhysicsBody
- Returns:
- boolean
-
isDynamic
public boolean isDynamic()
Description copied from interface:PhysicsBody
Returns true if this body's mass type is NOTMassType.INFINITE
.- Specified by:
isDynamic
in interfacePhysicsBody
- Returns:
- boolean
-
setAtRestDetectionEnabled
public void setAtRestDetectionEnabled(boolean flag)
Description copied from interface:PhysicsBody
Determines whether thisPhysicsBody
can participate in automatic at-rest detection.- Specified by:
setAtRestDetectionEnabled
in interfacePhysicsBody
- Parameters:
flag
- true if it should
-
isAtRestDetectionEnabled
public boolean isAtRestDetectionEnabled()
Description copied from interface:PhysicsBody
Returns true if thisPhysicsBody
can participate in automatic at-rest detection.- Specified by:
isAtRestDetectionEnabled
in interfacePhysicsBody
- Returns:
- boolean
-
isAtRest
public boolean isAtRest()
Description copied from interface:PhysicsBody
Returns true if thisPhysicsBody
is at-rest.- Specified by:
isAtRest
in interfacePhysicsBody
- Returns:
- boolean
-
setAtRest
public void setAtRest(boolean flag)
Description copied from interface:PhysicsBody
Sets whether thisPhysicsBody
is at-rest or not.If flag is true, this body's velocity, angular velocity, force, torque, and accumulators are cleared.
- Specified by:
setAtRest
in interfacePhysicsBody
- Parameters:
flag
- true if the body should be at-rest
-
isBullet
public boolean isBullet()
Description copied from interface:PhysicsBody
Returns true if thisPhysicsBody
is a bullet.- Specified by:
isBullet
in interfacePhysicsBody
- Returns:
- boolean
- See Also:
PhysicsBody.setBullet(boolean)
-
setBullet
public void setBullet(boolean flag)
Description copied from interface:PhysicsBody
Sets the bullet flag for thisPhysicsBody
.A bullet is a very fast moving body that requires continuous collision detection with all other
PhysicsBody
s to ensure that no collisions are missed.- Specified by:
setBullet
in interfacePhysicsBody
- Parameters:
flag
- true if thisPhysicsBody
is a bullet
-
createSweptAABB
public AABB createSweptAABB()
Description copied from interface:PhysicsBody
Returns a sweptAABB
that contains the maximal space in which thePhysicsBody
exists from the initial transform to the final transform.The AABB returned from this method can vary based on the state of the body, the number of fixtures, whether the body was rotating or not, and so on. This method attempts to return the tightest fitting AABB possible, but it should not be relied on.
NOTE: This method is dependent upon the
CollisionBody.getRotationDiscRadius()
andCollisionBody.getWorldCenter()
methods in some scenarios, please ensure these are properly setup before calling this method.- Specified by:
createSweptAABB
in interfacePhysicsBody
- Returns:
AABB
-
createSweptAABB
public AABB createSweptAABB(Transform initialTransform, Transform finalTransform)
Description copied from interface:PhysicsBody
Creates a sweptAABB
from the given start and endTransform
s using the fixtures on thisPhysicsBody
.The AABB returned from this method can vary based on the state of the body, the number of fixtures, whether the body was rotating or not, and so on. This method attempts to return the tightest fitting AABB possible, but it should not be relied on.
NOTE: This method is dependent upon the
CollisionBody.getRotationDiscRadius()
andCollisionBody.getWorldCenter()
methods in some scenarios, please ensure these are properly setup before calling this method.- Specified by:
createSweptAABB
in interfacePhysicsBody
- Parameters:
initialTransform
- the initialTransform
finalTransform
- the finalTransform
- Returns:
AABB
-
computeSweptAABB
public void computeSweptAABB(AABB result)
Description copied from interface:PhysicsBody
Computes a sweptAABB
that contains the maximal space in which thePhysicsBody
exists from the initial transform to the final transform and places the result in the given AABB.The AABB returned from this method can vary based on the state of the body, the number of fixtures, whether the body was rotating or not, and so on. This method attempts to return the tightest fitting AABB possible, but it should not be relied on.
NOTE: This method is dependent upon the
CollisionBody.getRotationDiscRadius()
andCollisionBody.getWorldCenter()
methods in some scenarios, please ensure these are properly setup before calling this method.- Specified by:
computeSweptAABB
in interfacePhysicsBody
- Parameters:
result
- the AABB to set
-
computeSweptAABB
public void computeSweptAABB(Transform initialTransform, Transform finalTransform, AABB result)
Description copied from interface:PhysicsBody
Computes a sweptAABB
from the given start and endTransform
s using the fixtures on thisPhysicsBody
and places the result in the given AABB.The AABB returned from this method can vary based on the state of the body, the number of fixtures, whether the body was rotating or not, and so on. This method attempts to return the tightest fitting AABB possible, but it should not be relied on.
NOTE: This method is dependent upon the
CollisionBody.getRotationDiscRadius()
andCollisionBody.getWorldCenter()
methods in some scenarios, please ensure these are properly setup before calling this method.- Specified by:
computeSweptAABB
in interfacePhysicsBody
- Parameters:
initialTransform
- the initialTransform
finalTransform
- the finalTransform
result
- the AABB to set
-
getChangeInPosition
public Vector2 getChangeInPosition()
Description copied from interface:PhysicsBody
Returns the change in position computed from last frame's transform and this frame's transform.- Specified by:
getChangeInPosition
in interfacePhysicsBody
- Returns:
- Vector2
-
getChangeInOrientation
public double getChangeInOrientation()
Description copied from interface:PhysicsBody
Returns the change in orientation computed from last frame's transform and this frame's transform.This method will return a change in the range [0, 2π). This isn't as useful if the angular velocity is greater than 2π per time step. Since we don't have the timestep here, we can't compute the exact change in this case.
If the angular velocity is zero, this method returns the minimum difference in orientation.
- Specified by:
getChangeInOrientation
in interfacePhysicsBody
- Returns:
- double
-
getLocalCenter
public Vector2 getLocalCenter()
Description copied from interface:CollisionBody
Returns the center for thisCollisionBody
in local coordinates.- Specified by:
getLocalCenter
in interfaceCollisionBody<BodyFixture>
- Returns:
Vector2
the center in local coordinates
-
getWorldCenter
public Vector2 getWorldCenter()
Description copied from interface:CollisionBody
Returns the center for thisCollisionBody
in world coordinates.- Specified by:
getWorldCenter
in interfaceCollisionBody<BodyFixture>
- Overrides:
getWorldCenter
in classAbstractCollisionBody<BodyFixture>
- Returns:
Vector2
the center in world coordinates
-
getLinearVelocity
public Vector2 getLinearVelocity()
Description copied from interface:PhysicsBody
Returns the linear velocity.- Specified by:
getLinearVelocity
in interfacePhysicsBody
- Returns:
Vector2
-
getLinearVelocity
public Vector2 getLinearVelocity(Vector2 point)
Description copied from interface:PhysicsBody
Returns the velocity of this body at the given world space point.- Specified by:
getLinearVelocity
in interfacePhysicsBody
- Parameters:
point
- the point in world space- Returns:
Vector2
-
setLinearVelocity
public void setLinearVelocity(Vector2 velocity)
Description copied from interface:PhysicsBody
Sets the linear velocity.Call the
PhysicsBody.setAtRest(boolean)
method to wake up thePhysicsBody
if thePhysicsBody
is asleep and the velocity is not zero.- Specified by:
setLinearVelocity
in interfacePhysicsBody
- Parameters:
velocity
- the desired velocity
-
setLinearVelocity
public void setLinearVelocity(double x, double y)
Description copied from interface:PhysicsBody
Sets the linear velocity.Call the
PhysicsBody.setAtRest(boolean)
method to wake up thePhysicsBody
if thePhysicsBody
is asleep and the velocity is not zero.- Specified by:
setLinearVelocity
in interfacePhysicsBody
- Parameters:
x
- the linear velocity along the x-axisy
- the linear velocity along the y-axis
-
getAngularVelocity
public double getAngularVelocity()
Description copied from interface:PhysicsBody
Returns the angular velocity.- Specified by:
getAngularVelocity
in interfacePhysicsBody
- Returns:
- double
-
setAngularVelocity
public void setAngularVelocity(double angularVelocity)
Description copied from interface:PhysicsBody
Sets the angular velocity in radians per secondCall the
PhysicsBody.setAtRest(boolean)
method to wake up thePhysicsBody
if thePhysicsBody
is asleep and the velocity is not zero.- Specified by:
setAngularVelocity
in interfacePhysicsBody
- Parameters:
angularVelocity
- the angular velocity in radians per second
-
getForce
public Vector2 getForce()
Description copied from interface:PhysicsBody
Returns the force applied in the last iteration.This is the accumulated force from the last iteration.
- Specified by:
getForce
in interfacePhysicsBody
- Returns:
Vector2
-
getAccumulatedForce
public Vector2 getAccumulatedForce()
Description copied from interface:PhysicsBody
Returns the total force currently stored in the force accumulator.- Specified by:
getAccumulatedForce
in interfacePhysicsBody
- Returns:
Vector2
-
getTorque
public double getTorque()
Description copied from interface:PhysicsBody
Returns the torque applied in the last iteration.This is the accumulated torque from the last iteration.
- Specified by:
getTorque
in interfacePhysicsBody
- Returns:
- double
-
getAccumulatedTorque
public double getAccumulatedTorque()
Description copied from interface:PhysicsBody
Returns the total torque currently stored in the torque accumulator.- Specified by:
getAccumulatedTorque
in interfacePhysicsBody
- Returns:
- double
-
getLinearDamping
public double getLinearDamping()
Description copied from interface:PhysicsBody
Returns the linear damping.- Specified by:
getLinearDamping
in interfacePhysicsBody
- Returns:
- double
- See Also:
PhysicsBody.setLinearDamping(double)
-
setLinearDamping
public void setLinearDamping(double linearDamping)
Description copied from interface:PhysicsBody
Sets the linear damping.Linear damping is used to reduce the linear velocity over time. The default is zero and larger values will cause the linear velocity to reduce faster.
The units are seconds-1.
- Specified by:
setLinearDamping
in interfacePhysicsBody
- Parameters:
linearDamping
- the linear damping; must be greater than or equal to zero
-
getAngularDamping
public double getAngularDamping()
Description copied from interface:PhysicsBody
Returns the angular damping.- Specified by:
getAngularDamping
in interfacePhysicsBody
- Returns:
- double
- See Also:
PhysicsBody.setAngularDamping(double)
-
setAngularDamping
public void setAngularDamping(double angularDamping)
Description copied from interface:PhysicsBody
Sets the angular damping.Angular damping is used to reduce the angular velocity over time. The default is zero and larger values will cause the angular velocity to reduce faster.
The units are seconds-1.
- Specified by:
setAngularDamping
in interfacePhysicsBody
- Parameters:
angularDamping
- the angular damping; must be greater than or equal to zero
-
getGravityScale
public double getGravityScale()
Description copied from interface:PhysicsBody
Returns the gravity scale.- Specified by:
getGravityScale
in interfacePhysicsBody
- Returns:
- double
- See Also:
PhysicsBody.setGravityScale(double)
-
setGravityScale
public void setGravityScale(double scale)
Description copied from interface:PhysicsBody
Sets the gravity scale.The gravity scale is a multiplier applied to the acceleration due to gravity before applying the force of gravity to the body. This allows bodies to be affected differently under the same gravity.
- Specified by:
setGravityScale
in interfacePhysicsBody
- Parameters:
scale
- the gravity scale for this body
-
-