Class Body
java.lang.Object
org.jbox2d.dynamics.Body
public class Body
extends java.lang.Object
A rigid body. These are created via World.createBody.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprivate final FixtureDeffloatfloatintintfinal Vec2floatfloatfloatfloatintfloatfinal Vec2floatfloatfinal SweepThe swept motion for CCDfloatjava.lang.Objectfinal TransformThe body origin transform.private final MassDataprivate final Transform -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidadvance(float t) voidapplyAngularImpulse(float impulse) Apply an angular impulse.final voidapplyForce(Vec2 force, Vec2 point) Apply a force at a world point.final voidapplyForceToCenter(Vec2 force) Apply a force to the center of mass.final voidapplyLinearImpulse(Vec2 impulse, Vec2 point) Apply an impulse at a point.final voidapplyTorque(float torque) Apply a torque.final FixturecreateFixture(Shape shape, float density) Creates a fixture from a shape and attach it to this body.final FixturecreateFixture(FixtureDef def) Creates a fixture and attach it to this body.final voiddestroyFixture(Fixture fixture) Destroy a fixture.final floatgetAngle()Get the angle in radians.final floatGet the angular damping of the body.final floatGet the angular velocity.final ContactEdgeGet the list of all contacts attached to this body.final FixtureGet the list of all fixtures attached to this body.floatGet the gravity scale of the body.final floatGet the central rotational inertia of the body.final JointEdgeGet the list of all joints attached to this body.final floatGet the linear damping of the body.final Vec2Get the linear velocity of the center of mass.final Vec2getLinearVelocityFromLocalPoint(Vec2 localPoint) Get the world velocity of a local point.final voidgetLinearVelocityFromLocalPointToOut(Vec2 localPoint, Vec2 out) final Vec2getLinearVelocityFromWorldPoint(Vec2 worldPoint) Get the world linear velocity of a world point attached to this body.final voidgetLinearVelocityFromWorldPointToOut(Vec2 worldPoint, Vec2 out) final Vec2Get the local position of the center of mass.final Vec2getLocalPoint(Vec2 worldPoint) Gets a local point relative to the body's origin given a world point.final voidgetLocalPointToOut(Vec2 worldPoint, Vec2 out) final Vec2getLocalVector(Vec2 worldVector) Gets a local vector given a world vector.final voidgetLocalVectorToOut(Vec2 worldVector, Vec2 out) final voidgetLocalVectorToOutUnsafe(Vec2 worldVector, Vec2 out) final floatgetMass()Get the total mass of the body.final voidgetMassData(MassData data) Get the mass data of the body.final BodygetNext()Get the next body in the world's body list.final Vec2Get the world body origin position.final TransformGet the body transform for the body's origin.getType()final java.lang.ObjectGet the user data pointer that was provided in the body definition.final WorldgetWorld()Get the parent world of this body.final Vec2Get the world position of the center of mass.final Vec2getWorldPoint(Vec2 localPoint) Get the world coordinates of a point given the local coordinates.final voidgetWorldPointToOut(Vec2 localPoint, Vec2 out) final Vec2getWorldVector(Vec2 localVector) Get the world coordinates of a vector given the local coordinates.final voidgetWorldVectorToOut(Vec2 localVector, Vec2 out) final voidgetWorldVectorToOutUnsafe(Vec2 localVector, Vec2 out) booleanisActive()Get the active state of the body.booleanisAwake()Get the sleeping state of this body.final booleanisBullet()Is this body treated like a bullet for continuous collision detection?booleanDoes this body have fixed rotation?booleanIs this body allowed to sleepfinal voidThis resets the mass properties to the sum of the mass properties of the fixtures.voidsetActive(boolean flag) Set the active state of the body.final voidsetAngularDamping(float angularDamping) Set the angular damping of the body.final voidsetAngularVelocity(float w) Set the angular velocity.voidsetAwake(boolean flag) Set the sleep state of the body.final voidsetBullet(boolean flag) Should this body be treated like a bullet for continuous collision detection?voidsetFixedRotation(boolean flag) Set this body to have fixed rotation.voidsetGravityScale(float gravityScale) Set the gravity scale of the body.final voidsetLinearDamping(float linearDamping) Set the linear damping of the body.final voidSet the linear velocity of the center of mass.final voidsetMassData(MassData massData) Set the mass properties to override the mass properties of the fixtures.voidsetSleepingAllowed(boolean flag) You can disable sleeping on this body.final voidsetTransform(Vec2 position, float angle) Set the position of the body's origin and rotation.voidSet the type of this body.final voidsetUserData(java.lang.Object data) Set the user data.booleanshouldCollide(Body other) This is used to prevent connected bodies from colliding.protected final voidfinal voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
e_islandFlag
public static final int e_islandFlag- See Also:
-
e_awakeFlag
public static final int e_awakeFlag- See Also:
-
e_autoSleepFlag
public static final int e_autoSleepFlag- See Also:
-
e_bulletFlag
public static final int e_bulletFlag- See Also:
-
e_fixedRotationFlag
public static final int e_fixedRotationFlag- See Also:
-
e_activeFlag
public static final int e_activeFlag- See Also:
-
e_toiFlag
public static final int e_toiFlag- See Also:
-
m_type
-
m_flags
public int m_flags -
m_islandIndex
public int m_islandIndex -
m_xf
The body origin transform. -
m_sweep
The swept motion for CCD -
m_linearVelocity
-
m_angularVelocity
public float m_angularVelocity -
m_force
-
m_torque
public float m_torque -
m_world
-
m_prev
-
m_next
-
m_fixtureList
-
m_fixtureCount
public int m_fixtureCount -
m_jointList
-
m_contactList
-
m_mass
public float m_mass -
m_invMass
public float m_invMass -
m_I
public float m_I -
m_invI
public float m_invI -
m_linearDamping
public float m_linearDamping -
m_angularDamping
public float m_angularDamping -
m_gravityScale
public float m_gravityScale -
m_sleepTime
public float m_sleepTime -
m_userData
public java.lang.Object m_userData -
fixDef
-
pmd
-
pxf
-
-
Constructor Details
-
Body
-
-
Method Details
-
createFixture
Creates a fixture and attach it to this body. Use this function if you need to set some fixture parameters, like friction. Otherwise you can create the fixture directly from a shape. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.- Parameters:
def- the fixture definition.
-
createFixture
Creates a fixture from a shape and attach it to this body. This is a convenience function. Use FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. If the density is non-zero, this function automatically updates the mass of the body.- Parameters:
shape- the shape to be cloned.density- the shape density (set to zero for static bodies).
-
destroyFixture
Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All fixtures attached to a body are implicitly destroyed when the body is destroyed.- Parameters:
fixture- the fixture to be removed.
-
setTransform
Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior.- Parameters:
position- the world position of the body's local origin.angle- the world rotation in radians.
-
getTransform
Get the body transform for the body's origin.- Returns:
- the world transform of the body's origin.
-
getPosition
Get the world body origin position. Do not modify.- Returns:
- the world position of the body's origin.
-
getAngle
public final float getAngle()Get the angle in radians.- Returns:
- the current world rotation angle in radians.
-
getWorldCenter
Get the world position of the center of mass. Do not modify. -
getLocalCenter
Get the local position of the center of mass. Do not modify. -
setLinearVelocity
Set the linear velocity of the center of mass.- Parameters:
v- the new linear velocity of the center of mass.
-
getLinearVelocity
Get the linear velocity of the center of mass. Do not modify, instead usesetLinearVelocity(Vec2).- Returns:
- the linear velocity of the center of mass.
-
setAngularVelocity
public final void setAngularVelocity(float w) Set the angular velocity.- Parameters:
omega- the new angular velocity in radians/second.
-
getAngularVelocity
public final float getAngularVelocity()Get the angular velocity.- Returns:
- the angular velocity in radians/second.
-
getGravityScale
public float getGravityScale()Get the gravity scale of the body.- Returns:
-
setGravityScale
public void setGravityScale(float gravityScale) Set the gravity scale of the body.- Parameters:
gravityScale-
-
applyForce
Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.- Parameters:
force- the world force vector, usually in Newtons (N).point- the world position of the point of application.
-
applyForceToCenter
Apply a force to the center of mass. This wakes up the body.- Parameters:
force- the world force vector, usually in Newtons (N).
-
applyTorque
public final void applyTorque(float torque) Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.- Parameters:
torque- about the z-axis (out of the screen), usually in N-m.
-
applyLinearImpulse
Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body.- Parameters:
impulse- the world impulse vector, usually in N-seconds or kg-m/s.point- the world position of the point of application.
-
applyAngularImpulse
public void applyAngularImpulse(float impulse) Apply an angular impulse.- Parameters:
impulse- the angular impulse in units of kg*m*m/s
-
getMass
public final float getMass()Get the total mass of the body.- Returns:
- the mass, usually in kilograms (kg).
-
getInertia
public final float getInertia()Get the central rotational inertia of the body.- Returns:
- the rotational inertia, usually in kg-m^2.
-
getMassData
Get the mass data of the body. The rotational inertia is relative to the center of mass. -
setMassData
Set the mass properties to override the mass properties of the fixtures. Note that this changes the center of mass position. Note that creating or destroying fixtures can also alter the mass. This function has no effect if the body isn't dynamic.- Parameters:
massData- the mass properties.
-
resetMassData
public final void resetMassData()This resets the mass properties to the sum of the mass properties of the fixtures. This normally does not need to be called unless you called setMassData to override the mass and you later want to reset the mass. -
getWorldPoint
-
getWorldPointToOut
-
getWorldVector
-
getWorldVectorToOut
-
getWorldVectorToOutUnsafe
-
getLocalPoint
-
getLocalPointToOut
-
getLocalVector
-
getLocalVectorToOut
-
getLocalVectorToOutUnsafe
-
getLinearVelocityFromWorldPoint
-
getLinearVelocityFromWorldPointToOut
-
getLinearVelocityFromLocalPoint
-
getLinearVelocityFromLocalPointToOut
-
getLinearDamping
public final float getLinearDamping()Get the linear damping of the body. -
setLinearDamping
public final void setLinearDamping(float linearDamping) Set the linear damping of the body. -
getAngularDamping
public final float getAngularDamping()Get the angular damping of the body. -
setAngularDamping
public final void setAngularDamping(float angularDamping) Set the angular damping of the body. -
getType
-
setType
Set the type of this body. This may alter the mass and velocity.- Parameters:
type-
-
isBullet
public final boolean isBullet()Is this body treated like a bullet for continuous collision detection? -
setBullet
public final void setBullet(boolean flag) Should this body be treated like a bullet for continuous collision detection? -
setSleepingAllowed
public void setSleepingAllowed(boolean flag) You can disable sleeping on this body. If you disable sleeping, the body will be woken.- Parameters:
flag-
-
isSleepingAllowed
public boolean isSleepingAllowed()Is this body allowed to sleep- Returns:
-
setAwake
public void setAwake(boolean flag) Set the sleep state of the body. A sleeping body has very low CPU cost.- Parameters:
flag- set to true to put body to sleep, false to wake it.flag-
-
isAwake
public boolean isAwake()Get the sleeping state of this body.- Returns:
- true if the body is sleeping.
-
setActive
public void setActive(boolean flag) Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a World object and remains in the body list.- Parameters:
flag-
-
isActive
public boolean isActive()Get the active state of the body.- Returns:
-
setFixedRotation
public void setFixedRotation(boolean flag) Set this body to have fixed rotation. This causes the mass to be reset.- Parameters:
flag-
-
isFixedRotation
public boolean isFixedRotation()Does this body have fixed rotation?- Returns:
-
getFixtureList
Get the list of all fixtures attached to this body. -
getJointList
Get the list of all joints attached to this body. -
getContactList
Get the list of all contacts attached to this body. -
getNext
Get the next body in the world's body list. -
getUserData
public final java.lang.Object getUserData()Get the user data pointer that was provided in the body definition. -
setUserData
public final void setUserData(java.lang.Object data) Set the user data. Use this to store your application specific data. -
getWorld
Get the parent world of this body. -
synchronizeFixtures
protected final void synchronizeFixtures() -
synchronizeTransform
public final void synchronizeTransform() -
shouldCollide
This is used to prevent connected bodies from colliding. It may lie, depending on the collideConnected flag.- Parameters:
other-- Returns:
-
advance
protected final void advance(float t)
-