Package org.jbox2d.dynamics
Class Body
java.lang.Object
org.jbox2d.dynamics.Body
A rigid body. These are created via World.createBody.
- Author:
- Daniel Murphy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intfloatAngular damping is used to reduce the angular velocity.floatThe angular velocity of the body.static final intstatic final intstatic final intstatic final intintintfinal Vec2floatScale the gravity applied to this body.floatThe rotational inertia about the center of mass.floatThe inverse rotational inertia about the center of mass.floatThe inverse mass (1 / mass).static final intintfloatLinear damping is used to reduce the linear velocity.final Vec2floatThe mass.The next body in the world's body list.The previous body in the world's body list.floatfinal SweepThe swept motion for CCDstatic final intfloatThe body type: static, kinematic, or dynamic.Use this to store application specific body data.final TransformThe body origin transform.final TransformThe previous transform for particle simulation -
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, boolean wake) 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 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 sleep?final 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(Object data) Set the user data.booleanshouldCollide(Body other) This is used to prevent connected bodies from colliding.protected final voidfinal void
-
Field Details
-
islandFlag
public static final int islandFlag- See Also:
-
awakeFlag
public static final int awakeFlag- See Also:
-
autoSleepFlag
public static final int autoSleepFlag- See Also:
-
bulletFlag
public static final int bulletFlag- See Also:
-
fixedRotationFlag
public static final int fixedRotationFlag- See Also:
-
activeFlag
public static final int activeFlag- See Also:
-
toiFlag
public static final int toiFlag- See Also:
-
type
The body type: static, kinematic, or dynamic. Note: if a dynamic body would have zero mass, the mass is set to one. -
flags
public int flags -
islandIndex
public int islandIndex -
xf
The body origin transform. -
xf0
The previous transform for particle simulation -
sweep
The swept motion for CCD -
linearVelocity
-
angularVelocity
public float angularVelocityThe angular velocity of the body. -
force
-
torque
public float torque -
world
-
prev
The previous body in the world's body list. -
next
The next body in the world's body list. -
fixtureList
-
fixtureCount
public int fixtureCount -
jointList
-
contactList
-
mass
public float massThe mass. -
invMass
public float invMassThe inverse mass (1 / mass). -
I
public float IThe rotational inertia about the center of mass.The moment of inertia, otherwise known as the mass moment of inertia,https://github.com/erincatto/box2d/blob/411acc32eb6d4f2e96fc70ddbdf01fe5f9b16230/include/box2d/b2_body.h#L459-L460 angular/rotational mass, second moment of mass, or most accurately, rotational inertia, of a rigid body is a quantity that determines the torque needed for a desired angular acceleration about a rotational axis, akin to how mass determines the force needed for a desired acceleration.
Wikipedia: Moment of inertia -
invI
public float invIThe inverse rotational inertia about the center of mass. -
linearDamping
public float linearDampingLinear damping is used to reduce the linear velocity. The damping parameter can be larger than 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is large. Units are1 / time. -
angularDamping
public float angularDampingAngular damping is used to reduce the angular velocity. The damping parameter can be larger than 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is large. Units are1 / time. -
gravityScale
public float gravityScaleScale the gravity applied to this body. -
sleepTime
public float sleepTime -
userData
Use this to store application specific body data.
-
-
Constructor Details
-
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.- Repolink:
- Github: erincatto/box2d src/dynamics/b2_body.cpp Lines 204 - 211
- Warning:
- This function is locked during callbacks.
-
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).- Repolink:
- Github: erincatto/box2d src/dynamics/b2_body.cpp Lines 204 - 211
- Warning:
- This function is locked during callbacks.
-
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.- Repolink:
- Github: erincatto/box2d src/dynamics/b2_body.cpp Lines 213 - 288
- Warning:
- This function is locked during callbacks.
-
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. Note: contacts are updated on the next call to World.step().- 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:
w- 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. -
setGravityScale
public void setGravityScale(float gravityScale) Set the gravity scale of the body. -
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 if 'wake' is set to true. If the body is sleeping and 'wake' is false, then there is no effect.- Parameters:
impulse- The world impulse vector, usually in N-seconds or kg-m/s.point- The world position of the point of application.wake- Also wake up the body.
-
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
Get the world coordinates of a point given the local coordinates.- Parameters:
localPoint- A point on the body measured relative the body's origin.- Returns:
- The same point expressed in world coordinates.
-
getWorldPointToOut
-
getWorldVector
Get the world coordinates of a vector given the local coordinates.- Parameters:
localVector- A vector fixed in the body.- Returns:
- The same vector expressed in world coordinates.
-
getWorldVectorToOut
-
getWorldVectorToOutUnsafe
-
getLocalPoint
Gets a local point relative to the body's origin given a world point.- Parameters:
worldPoint- Point in world coordinates.- Returns:
- The corresponding local point relative to the body's origin.
-
getLocalPointToOut
-
getLocalVector
Gets a local vector given a world vector.- Parameters:
worldVector- A vector in world coordinates.- Returns:
- The corresponding local vector.
-
getLocalVectorToOut
-
getLocalVectorToOutUnsafe
-
getLinearVelocityFromWorldPoint
Get the world linear velocity of a world point attached to this body.- Parameters:
worldPoint- A point in world coordinates.- Returns:
- The world velocity of a point.
-
getLinearVelocityFromWorldPointToOut
-
getLinearVelocityFromLocalPoint
Get the world velocity of a local point.- Parameters:
localPoint- A point in local coordinates.- Returns:
- The world velocity of a point.
-
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. -
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. -
isSleepingAllowed
public boolean isSleepingAllowed()Is this body allowed to sleep? -
setAwake
public void setAwake(boolean flag) Set the sleep state of the body. A sleeping body has very low CPU cost. Note that putting it to sleep will set its velocities and forces to zero.- Parameters:
flag- Set to true to wake the body, false to put it to sleep.
-
isAwake
public boolean isAwake()Get the sleeping state of this body.- Returns:
- true if the body is awake.
-
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. -
isActive
public boolean isActive()Get the active state of the body. -
setFixedRotation
public void setFixedRotation(boolean flag) Set this body to have fixed rotation. This causes the mass to be reset. -
isFixedRotation
public boolean isFixedRotation()Does this body have fixed rotation? -
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.- Repolink:
- Github: erincatto/box2d include/box2d/b2_body.h Lines 713 - 721
- Warning:
- this list changes during the time step, and you may miss some collisions if you don't use ContactListener.
-
getNext
Get the next body in the world's body list. -
getUserData
Get the user data pointer that was provided in the body definition. -
setUserData
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. -
advance
protected final void advance(float t)
-