com.badlogic.gdx.physics.box2d
Class Body

java.lang.Object
  extended by com.badlogic.gdx.physics.box2d.Body

public class Body
extends Object

A rigid body. These are created via World.CreateBody.

Author:
mzechner

Field Summary
 Vector2 linVelLoc
           
 Vector2 linVelWorld
           
 Vector2 localPoint2
           
 Vector2 localVector
           
 
Method Summary
 void applyAngularImpulse(float impulse, boolean wake)
          Apply an angular impulse.
 void applyForce(float forceX, float forceY, float pointX, float pointY, boolean wake)
          Apply a force at a world point.
 void applyForce(Vector2 force, Vector2 point, boolean wake)
          Apply a force at a world point.
 void applyForceToCenter(float forceX, float forceY, boolean wake)
          Apply a force to the center of mass.
 void applyForceToCenter(Vector2 force, boolean wake)
          Apply a force to the center of mass.
 void applyLinearImpulse(float impulseX, float impulseY, float pointX, float pointY, boolean wake)
          Apply an impulse at a point.
 void applyLinearImpulse(Vector2 impulse, Vector2 point, boolean wake)
          Apply an impulse at a point.
 void applyTorque(float torque, boolean wake)
          Apply a torque.
 Fixture createFixture(FixtureDef def)
          Creates a fixture and attach it to this body.
 Fixture createFixture(Shape shape, float density)
          Creates a fixture from a shape and attach it to this body.
 void destroyFixture(Fixture fixture)
          Destroy a fixture.
 float getAngle()
          Get the angle in radians.
 float getAngularDamping()
          Get the angular damping of the body.
 float getAngularVelocity()
          Get the angular velocity.
 Array<Fixture> getFixtureList()
          Get the list of all fixtures attached to this body.
 float getGravityScale()
           
 float getInertia()
          Get the rotational inertia of the body about the local origin.
 Array<JointEdge> getJointList()
          Get the list of all joints attached to this body.
 float getLinearDamping()
          Get the linear damping of the body.
 Vector2 getLinearVelocity()
          Get the linear velocity of the center of mass.
 Vector2 getLinearVelocityFromLocalPoint(Vector2 localPoint)
          Get the world velocity of a local point.
 Vector2 getLinearVelocityFromWorldPoint(Vector2 worldPoint)
          Get the world linear velocity of a world point attached to this body.
 Vector2 getLocalCenter()
          Get the local position of the center of mass.
 Vector2 getLocalPoint(Vector2 worldPoint)
          Gets a local point relative to the body's origin given a world point.
 Vector2 getLocalVector(Vector2 worldVector)
          Gets a local vector given a world vector.
 float getMass()
          Get the total mass of the body.
 MassData getMassData()
          Get the mass data of the body.
 Vector2 getPosition()
          Get the world body origin position.
 Transform getTransform()
          Get the body transform for the body's origin.
 BodyDef.BodyType getType()
          Get the type of this body.
 Object getUserData()
          Get the user data
 World getWorld()
          Get the parent world of this body.
 Vector2 getWorldCenter()
          Get the world position of the center of mass.
 Vector2 getWorldPoint(Vector2 localPoint)
          Get the world coordinates of a point given the local coordinates.
 Vector2 getWorldVector(Vector2 localVector)
          Get the world coordinates of a vector given the local coordinates.
 boolean isActive()
          Get the active state of the body.
 boolean isAwake()
          Get the sleeping state of this body.
 boolean isBullet()
          Is this body treated like a bullet for continuous collision detection?
 boolean isFixedRotation()
          Does this body have fixed rotation?
 boolean isSleepingAllowed()
          Is this body allowed to sleep
 void resetMassData()
          This resets the mass properties to the sum of the mass properties of the fixtures.
 void setActive(boolean flag)
          Set the active state of the body.
 void setAngularDamping(float angularDamping)
          Set the angular damping of the body.
 void setAngularVelocity(float omega)
          Set the angular velocity.
 void setAwake(boolean flag)
          Set the sleep state of the body.
 void setBullet(boolean flag)
          Should this body be treated like a bullet for continuous collision detection?
 void setFixedRotation(boolean flag)
          Set this body to have fixed rotation.
 void setGravityScale(float scale)
          Sets the gravity scale of the body
 void setLinearDamping(float linearDamping)
          Set the linear damping of the body.
 void setLinearVelocity(float vX, float vY)
          Set the linear velocity of the center of mass.
 void setLinearVelocity(Vector2 v)
          Set the linear velocity of the center of mass.
 void setMassData(MassData data)
          Set the mass properties to override the mass properties of the fixtures.
 void setSleepingAllowed(boolean flag)
          You can disable sleeping on this body.
 void setTransform(float x, float y, float angle)
          Set the position of the body's origin and rotation.
 void setTransform(Vector2 position, float angle)
          Set the position of the body's origin and rotation.
 void setType(BodyDef.BodyType type)
          Set the type of this body.
 void setUserData(Object userData)
          Set the user data
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

localPoint2

public final Vector2 localPoint2

localVector

public final Vector2 localVector

linVelWorld

public final Vector2 linVelWorld

linVelLoc

public final Vector2 linVelLoc
Method Detail

createFixture

public Fixture createFixture(FixtureDef def)
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

public Fixture createFixture(Shape shape,
                             float density)
Creates a fixture from a shape and attach it to this body. This is a convenience function. Use b2FixtureDef 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

public void destroyFixture(Fixture fixture)
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

public void setTransform(Vector2 position,
                         float angle)
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.

setTransform

public void setTransform(float x,
                         float y,
                         float angle)
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:
x - the world position on the x-axis
y - the world position on the y-axis
angle - the world rotation in radians.

getTransform

public Transform getTransform()
Get the body transform for the body's origin.


getPosition

public Vector2 getPosition()
Get the world body origin position.

Returns:
the world position of the body's origin.

getAngle

public float getAngle()
Get the angle in radians.

Returns:
the current world rotation angle in radians.

getWorldCenter

public Vector2 getWorldCenter()
Get the world position of the center of mass.


getLocalCenter

public Vector2 getLocalCenter()
Get the local position of the center of mass.


setLinearVelocity

public void setLinearVelocity(Vector2 v)
Set the linear velocity of the center of mass.


setLinearVelocity

public void setLinearVelocity(float vX,
                              float vY)
Set the linear velocity of the center of mass.


getLinearVelocity

public Vector2 getLinearVelocity()
Get the linear velocity of the center of mass.


setAngularVelocity

public void setAngularVelocity(float omega)
Set the angular velocity.


getAngularVelocity

public float getAngularVelocity()
Get the angular velocity.


applyForce

public void applyForce(Vector2 force,
                       Vector2 point,
                       boolean wake)
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.
wake - up the body

applyForce

public void applyForce(float forceX,
                       float forceY,
                       float pointX,
                       float pointY,
                       boolean wake)
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:
forceX - the world force vector on x, usually in Newtons (N).
forceY - the world force vector on y, usually in Newtons (N).
pointX - the world position of the point of application on x.
pointY - the world position of the point of application on y.
wake - up the body

applyForceToCenter

public void applyForceToCenter(Vector2 force,
                               boolean wake)
Apply a force to the center of mass. This wakes up the body.

Parameters:
force - the world force vector, usually in Newtons (N).

applyForceToCenter

public void applyForceToCenter(float forceX,
                               float forceY,
                               boolean wake)
Apply a force to the center of mass. This wakes up the body.

Parameters:
forceX - the world force vector, usually in Newtons (N).
forceY - the world force vector, usually in Newtons (N).

applyTorque

public void applyTorque(float torque,
                        boolean wake)
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.
wake - up the body

applyLinearImpulse

public void applyLinearImpulse(Vector2 impulse,
                               Vector2 point,
                               boolean wake)
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.
wake - up the body

applyLinearImpulse

public void applyLinearImpulse(float impulseX,
                               float impulseY,
                               float pointX,
                               float pointY,
                               boolean wake)
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:
impulseX - the world impulse vector on the x-axis, usually in N-seconds or kg-m/s.
impulseY - the world impulse vector on the y-axis, usually in N-seconds or kg-m/s.
pointX - the world position of the point of application on the x-axis.
pointY - the world position of the point of application on the y-axis.
wake - up the body

applyAngularImpulse

public void applyAngularImpulse(float impulse,
                                boolean wake)
Apply an angular impulse.

Parameters:
impulse - the angular impulse in units of kg*m*m/s

getMass

public float getMass()
Get the total mass of the body.

Returns:
the mass, usually in kilograms (kg).

getInertia

public float getInertia()
Get the rotational inertia of the body about the local origin.

Returns:
the rotational inertia, usually in kg-m^2.

getMassData

public MassData getMassData()
Get the mass data of the body.

Returns:
a struct containing the mass, inertia and center of the body.

setMassData

public void setMassData(MassData data)
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:
data - the mass properties.

resetMassData

public 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

public Vector2 getWorldPoint(Vector2 localPoint)
Get the world coordinates of a point given the local coordinates.

Parameters:
localPoint - a point on the body measured relative the the body's origin.
Returns:
the same point expressed in world coordinates.

getWorldVector

public Vector2 getWorldVector(Vector2 localVector)
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.

getLocalPoint

public Vector2 getLocalPoint(Vector2 worldPoint)
Gets a local point relative to the body's origin given a world point.

Parameters:
worldPoint - a point in world coordinates.
Returns:
the corresponding local point relative to the body's origin.

getLocalVector

public Vector2 getLocalVector(Vector2 worldVector)
Gets a local vector given a world vector.

Parameters:
worldVector - a vector in world coordinates.
Returns:
the corresponding local vector.

getLinearVelocityFromWorldPoint

public Vector2 getLinearVelocityFromWorldPoint(Vector2 worldPoint)
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.

getLinearVelocityFromLocalPoint

public Vector2 getLinearVelocityFromLocalPoint(Vector2 localPoint)
Get the world velocity of a local point.

Parameters:
localPoint - a point in local coordinates.
Returns:
the world velocity of a point.

getLinearDamping

public float getLinearDamping()
Get the linear damping of the body.


setLinearDamping

public void setLinearDamping(float linearDamping)
Set the linear damping of the body.


getAngularDamping

public float getAngularDamping()
Get the angular damping of the body.


setAngularDamping

public void setAngularDamping(float angularDamping)
Set the angular damping of the body.


setType

public void setType(BodyDef.BodyType type)
Set the type of this body. This may alter the mass and velocity.


getType

public BodyDef.BodyType getType()
Get the type of this body.


setBullet

public void setBullet(boolean flag)
Should this body be treated like a bullet for continuous collision detection?


isBullet

public boolean isBullet()
Is this body 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


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.

Parameters:
flag - set to true to put body to sleep, false to wake it.

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 b2World 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

public Array<Fixture> getFixtureList()
Get the list of all fixtures attached to this body. Do not modify the list!


getJointList

public Array<JointEdge> getJointList()
Get the list of all joints attached to this body. Do not modify the list!


getGravityScale

public float getGravityScale()
Returns:
Get the gravity scale of the body.

setGravityScale

public void setGravityScale(float scale)
Sets the gravity scale of the body


getWorld

public World getWorld()
Get the parent world of this body.


getUserData

public Object getUserData()
Get the user data


setUserData

public void setUserData(Object userData)
Set the user data



Copyright © 2013. All Rights Reserved.