- 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.0.0
- Author:
- William Bittle
-
-
Field Summary
-
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 Deprecated Methods Modifier and Type Method Description 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
.AABB
createSweptAABB()
Returns an AABB that contains the maximal space in which theCollisionBody
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
isActive()
Deprecated.boolean
isAsleep()
Deprecated.boolean
isAtRest()
Returns true if thisPhysicsBody
is at-rest.boolean
isAtRestDetectionEnabled()
Returns true if thisPhysicsBody
can participate in automatic at-rest detection.boolean
isAutoSleepingEnabled()
Deprecated.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
setActive(boolean flag)
Deprecated.void
setAngularDamping(double angularDamping)
Sets the angular damping.void
setAngularVelocity(double angularVelocity)
Sets the angular velocity in radians per secondvoid
setAsleep(boolean flag)
Deprecated.void
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
setAutoSleepingEnabled(boolean flag)
Deprecated.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()
Deprecated.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, 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, setTransform, setUserData, shift, translate, translate, translateToOrigin
-
Methods inherited from interface CollisionBody
addFixture, 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
-
-
-
-
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)
-
setMass
@Deprecated public AbstractPhysicsBody setMass()
Deprecated.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 fixtures.
This method will always set this body's mass type to Normal.
- Specified by:
setMass
in interfacePhysicsBody
- Returns:
PhysicsBody
this body
-
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
-
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
-
isActive
@Deprecated public boolean isActive()
Deprecated.Description copied from interface:PhysicsBody
Returns true if thisPhysicsBody
is active.- Specified by:
isActive
in interfacePhysicsBody
- Returns:
- boolean
-
setActive
@Deprecated public void setActive(boolean flag)
Deprecated.Description copied from interface:PhysicsBody
Sets whether thisPhysicsBody
is active or not.- Specified by:
setActive
in interfacePhysicsBody
- Parameters:
flag
- true if thisPhysicsBody
should be active
-
setAutoSleepingEnabled
@Deprecated public void setAutoSleepingEnabled(boolean flag)
Deprecated.Description copied from interface:PhysicsBody
Sets thePhysicsBody
to allow or disallow automatic sleeping.- Specified by:
setAutoSleepingEnabled
in interfacePhysicsBody
- Parameters:
flag
- true if thePhysicsBody
is allowed to sleep
-
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
-
isAutoSleepingEnabled
@Deprecated public boolean isAutoSleepingEnabled()
Deprecated.Description copied from interface:PhysicsBody
Returns true if thisPhysicsBody
is allowed to be put to sleep automatically.- Specified by:
isAutoSleepingEnabled
in interfacePhysicsBody
- Returns:
- boolean
-
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
-
isAsleep
@Deprecated public boolean isAsleep()
Deprecated.Description copied from interface:PhysicsBody
Returns true if thisPhysicsBody
is sleeping.- Specified by:
isAsleep
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
-
setAsleep
@Deprecated public void setAsleep(boolean flag)
Deprecated.Description copied from interface:PhysicsBody
Sets whether thisPhysicsBody
is awake or not.If flag is true, this body's velocity, angular velocity, force, torque, and accumulators are cleared.
- Specified by:
setAsleep
in interfacePhysicsBody
- Parameters:
flag
- true if the body should be put to sleep
-
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 an AABB that contains the maximal space in which theCollisionBody
exists from the initial transform to the final transform.This method takes the bounding circle, using the world center and rotation disc radius, at the initial and final transforms and creates an AABB containing both.
This method will return a degenerate AABB if the body has zero fixtures. If this body has one or more fixtures, but didn't move, an AABB with a width and height equal to the rotation disc radius is returned.
NOTE: To get an accurate result from this method, one of the
setMass
methods should be called to set the rotation disc radius 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
.This method takes the bounding circle, using the world center and rotation disc radius, at the initial and final transforms and creates an AABB containing both.
This method will return a degenerate AABB if the body has zero fixtures. If this body has one or more fixtures, but didn't move, an AABB with a width and height equal to the rotation disc radius is returned.
NOTE: To get an accurate result from this method, one of the
setMass
methods should be called to set the rotation disc radius before calling this method.- Specified by:
createSweptAABB
in interfacePhysicsBody
- Parameters:
initialTransform
- the initialTransform
finalTransform
- the finalTransform
- Returns:
AABB
-
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.setAsleep(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.setAsleep(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.setAsleep(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
-
-