net.phys2d.raw
Class Body

java.lang.Object
  extended bynet.phys2d.raw.Body
Direct Known Subclasses:
StaticBody

public class Body
extends java.lang.Object

A single body within the physics model


Field Summary
static float INFINITE_MASS
          The maximum value indicating that body won't move
 
Constructor Summary
  Body(DynamicShape shape, float m)
          Create a new un-named body
protected Body(Shape shape, float m)
          Create a new un-named body
  Body(java.lang.String name, DynamicShape shape, float m)
          Create a named body
protected Body(java.lang.String name, Shape shape, float m)
          Create a named body
 
Method Summary
 void addBit(long bitmask)
          Set one or more individual bits.
 boolean added()
          Check the added to simulation flag
 void addExcludedBody(Body other)
          Add a body that this body is not allowed to collide with, i.e.
 void addForce(Vector2f f)
          Add a force to this body
 void adjustAngularVelocity(float delta)
          Adjust the angular velocity of this body
 void adjustBiasedAngularVelocity(float delta)
          Adjust the bias angular velocity of this body
 void adjustBiasedVelocity(Vector2f delta)
          Adjust the bias velocity of this body
 void adjustPosition(ROVector2f delta, float scale)
          Adjust the position of this body.
 void adjustPosition(Vector2f delta)
          Adjust the position of this body The previous position will be set to the position before this function was called.
 void adjustRotation(float delta)
          Adjust the rotation of this body
 void adjustVelocity(Vector2f delta)
          Adjust the velocity of this body
 boolean canRest()
          Check if this body can come to a resting state
 void collided(Body other)
          Notification that this body collided with another
 boolean disabled()
          Check if this body is disabled
 void endFrame()
          Notification that we've ended an update frame/iteration
 boolean equals(java.lang.Object other)
           
 float getAngularVelocity()
          Get the angular velocity of this body
 float getAngularVelocityDelta()
          Get the change in angular velocity in the last update
 float getBiasedAngularVelocity()
          Get the bias angular velocity of this body
 ROVector2f getBiasedVelocity()
          Get the bias velocity of this body
 long getBitmask()
          Get this shape's bitmask
 BodyList getConnected()
          Get the list of bodies that this body is connected to.
 BodyList getConnected(boolean stopAtStatic)
          Get the list of bodies that this body is connected to.
 float getDamping()
          Get the friction of the 'air' on this body that slows down the object.
 float getEnergy()
          Get the energy contained in this body
 BodyList getExcludedList()
          Get the list of bodies that can not collide with this body
 ROVector2f getForce()
          Get the force applied to this body
 float getFriction()
          Get the friction on the surface of this body
 boolean getGravityEffected()
          Check if this body is effected by gravity
 float getI()
          Get the inertia of this body
 int getID()
          Get the ID of this body
 float getLastAngularVelocity()
          Get the angular velocity before the last update.
 ROVector2f getLastPosition()
          Get the position of this body before it was moved
 ROVector2f getLastVelocity()
          Get the velocity before the last update.
 float getMass()
          Get the mass of this body
 ROVector2f getPosition()
          Get the position of this body
 ROVector2f getPositionDelta()
          Get the change in position in the last update
 float getRestitution()
          Get the "restitution" of the body.
 float getRotation()
          Get the rotation in radians of this body
 float getRotDamping()
          Get the rotational damping, similar to normal damping.
 Shape getShape()
          Get the shape representing this body
 float getTorque()
          Get the torque applied to this body
 BodyList getTouching()
          Get the list of bodies that this body is touching.
 java.lang.Object getUserData()
          Retrieved the attached object which initially will be null.
 ROVector2f getVelocity()
          Get the velocity of this body
 ROVector2f getVelocityDelta()
          Get the change in velocity in the last update
 int hashCode()
           
 boolean isMoveable()
          Check if this body can move
 boolean isResting()
          Check if this body has been detected as resting and hence is considered static.
 boolean isRotatable()
          Check if this body can rotate.
 boolean isStatic()
          Check if this body is static
 boolean isTouchingStatic(java.util.ArrayList path)
          Check if this body is touching a static body directly or indirectly
 void move(float x, float y)
          Set the position of this body after it has moved this means the last position will contain the position before this function was called.
 void removeBit(long bitmask)
          Remove one or more individual bits.
 void removeExcludedBody(Body other)
          Remove a body from the excluded list of this body.
 void resetBias()
          Reset the bias velocity (done every time step)
 void set(Shape shape, float m)
          Reconfigure the body
 void setAdded(boolean added)
          Set the added to simulation flag
 void setBitmask(long bitmask)
          Set the bismask for this shape.
 void setCanRest(boolean canRest)
          Indicate whether this body can come to a resting state.
 void setDamping(float damping)
          Set the friction of the 'air' on this body that slows down the object.
 void setEnabled(boolean enabled)
          Indicates whether this body should be active, collide, move/rotate
 void setForce(float x, float y)
          Set the force being applied to this body
 void setFriction(float friction)
          Set the friction on the surface of this body
 void setGravityEffected(boolean gravity)
          Indicate whether this body should be effected by gravity
 void setIsResting(boolean isResting)
          Force this body into resting or not resting mode.
 void setMaxVelocity(float maxX, float maxY)
          Set the maximum velocity this body can reach.
 void setMoveable(boolean moveable)
          Indicate whether this body should be able to moe.
 void setPosition(float x, float y)
          Set the position of this body, this will also set the previous position to the same value.
 void setRestitution(float rest)
          Set the "restitution" of the body.
 void setRotatable(boolean rotatable)
          Indicate whether this body should be able to rotate.
 void setRotation(float rotation)
          Set the rotation in radians of this body
 void setRotDamping(float damping)
          Set the rotational damping, similar to normal damping.
 void setShape(Shape shape)
          Reset the shape of this body
 void setTorque(float t)
          Set the torque being applied to this body
 void setUserData(java.lang.Object o)
          Attach an object to this Body.
 java.lang.String toString()
           
protected  void validateVelocity()
          Validate the velocity value thats just been applied.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INFINITE_MASS

public static final float INFINITE_MASS
The maximum value indicating that body won't move

See Also:
Constant Field Values
Constructor Detail

Body

public Body(DynamicShape shape,
            float m)
Create a new un-named body

Parameters:
shape - The shape describing this body
m - The mass of the body

Body

protected Body(Shape shape,
               float m)
Create a new un-named body

Parameters:
shape - The shape describing this body
m - The mass of the body

Body

public Body(java.lang.String name,
            DynamicShape shape,
            float m)
Create a named body

Parameters:
name - The name to assign to the body
shape - The shape describing this body
m - The mass of the body

Body

protected Body(java.lang.String name,
               Shape shape,
               float m)
Create a named body

Parameters:
name - The name to assign to the body
shape - The shape describing this body
m - The mass of the body
Method Detail

disabled

public boolean disabled()
Check if this body is disabled

Returns:
True if this body is disabled

setEnabled

public void setEnabled(boolean enabled)
Indicates whether this body should be active, collide, move/rotate

Parameters:
enabled - True if this body should be active

getID

public int getID()
Get the ID of this body

Returns:
The unique ID of this body

setUserData

public void setUserData(java.lang.Object o)
Attach an object to this Body. Any previously set userdata will be lost.

Parameters:
o - The (new) userdata.

getUserData

public java.lang.Object getUserData()
Retrieved the attached object which initially will be null.

Returns:
The attached userdata.

isRotatable

public boolean isRotatable()
Check if this body can rotate.

Returns:
True if this body can rotate

isMoveable

public boolean isMoveable()
Check if this body can move

Returns:
True if this body can move

setRotatable

public void setRotatable(boolean rotatable)
Indicate whether this body should be able to rotate. Use this feature at you own risk - other bodies will react as tho this body has rotated when hit so there may be artefacts involved with it's use. Note also that this only prevents rotations caused by physics model updates. It is still possible to explicitly set the rotation of the body with #setRotation() The default value is true

Parameters:
rotatable - True if this body is rotatable

setMoveable

public void setMoveable(boolean moveable)
Indicate whether this body should be able to moe. Use this feature at you own risk - other bodies will react as tho this body has moved when hit so there may be artefacts involved with it's use. Note also that this only prevents movement caused by physics model updates. It is still possible to explicitly set the position of the body with #setPosition() The default value is true

Parameters:
moveable - True if this body is rotatable

setCanRest

public void setCanRest(boolean canRest)
Indicate whether this body can come to a resting state. The default is true, but it is sometimes useful for dynamic objects to prevent them resting.

Parameters:
canRest - True if the body can come to a resting state

canRest

public boolean canRest()
Check if this body can come to a resting state

Returns:
True if the body can come to a resting state

collided

public void collided(Body other)
Notification that this body collided with another

Parameters:
other - The other body that this body collided with

endFrame

public void endFrame()
Notification that we've ended an update frame/iteration


isTouchingStatic

public boolean isTouchingStatic(java.util.ArrayList path)
Check if this body is touching a static body directly or indirectly

Parameters:
path - The path of bodies we've used to get here
Returns:
True if we're touching a static body

getTouching

public BodyList getTouching()
Get the list of bodies that this body is touching. Only works if resting body detection is turned on

Returns:
The list of bodies this body touches

getConnected

public BodyList getConnected()
Get the list of bodies that this body is connected to. Only works if resting body detection is turned on

Returns:
The list of bodies this body touches

getConnected

public BodyList getConnected(boolean stopAtStatic)
Get the list of bodies that this body is connected to. Only works if resting body detection is turned on

Parameters:
stopAtStatic - True if we should stop traversing and looking for elements one you find a static one
Returns:
The list of bodies this body touches

isStatic

public boolean isStatic()
Check if this body is static

Returns:
True if this body is static

isResting

public boolean isResting()
Check if this body has been detected as resting and hence is considered static.

Returns:
True if the body is considered static since it's resting

setIsResting

public void setIsResting(boolean isResting)
Force this body into resting or not resting mode.

Parameters:
isResting - True if this body should be seen as resting

setGravityEffected

public void setGravityEffected(boolean gravity)
Indicate whether this body should be effected by gravity

Parameters:
gravity - True if this body should be effected by gravity

getGravityEffected

public boolean getGravityEffected()
Check if this body is effected by gravity

Returns:
True if this body is effected by gravity

addExcludedBody

public void addExcludedBody(Body other)
Add a body that this body is not allowed to collide with, i.e. the body specified will collide with this body

Parameters:
other - The body to exclude from collisions with this body

removeExcludedBody

public void removeExcludedBody(Body other)
Remove a body from the excluded list of this body. i.e. the body specified will be allowed to collide with this body again

Parameters:
other - The body to remove from the exclusion list

getExcludedList

public BodyList getExcludedList()
Get the list of bodies that can not collide with this body

Returns:
The list of bodies that can not collide with this body

getMass

public float getMass()
Get the mass of this body

Returns:
The mass of this body

getI

public float getI()
Get the inertia of this body

Returns:
The inertia of this body

setRestitution

public void setRestitution(float rest)
Set the "restitution" of the body. Hard bodies transfer momentum well. A value of 1.0 would be a pool ball. The default is 1f

Parameters:
rest - The restitution of this body

getRestitution

public float getRestitution()
Get the "restitution" of the body. Hard bodies transfer momentum well. A value of 1.0 would be a pool ball. The default is 0f

Returns:
The "restitution" of the body

set

public void set(Shape shape,
                float m)
Reconfigure the body

Parameters:
shape - The shape describing this body
m - The mass of the body

setShape

public void setShape(Shape shape)
Reset the shape of this body

Parameters:
shape - The new shape of this body

setFriction

public void setFriction(float friction)
Set the friction on the surface of this body

Parameters:
friction - The friction on the surface of this body

setRotation

public void setRotation(float rotation)
Set the rotation in radians of this body

Parameters:
rotation - The new rotation of the body

setDamping

public void setDamping(float damping)
Set the friction of the 'air' on this body that slows down the object. TODO: check how this works together with the gravity The friction force F will be F = -v * damping / m

Parameters:
damping - The friction damping factor which represents the body's airodynamic properties.

getDamping

public float getDamping()
Get the friction of the 'air' on this body that slows down the object.

Returns:
The friction damping factor which represents the body's airodynamic properties.

setRotDamping

public void setRotDamping(float damping)
Set the rotational damping, similar to normal damping. The torque F for this damping would be: F = -av * damping / m where av is the angular velocity.

Parameters:
damping - The rotational damping which represents the body's airodynamic properties when rotating.
See Also:
setDamping(float)

getRotDamping

public float getRotDamping()
Get the rotational damping, similar to normal damping.

Returns:
damping The rotational damping which represents the body's airodynamic properties when rotating.

getShape

public Shape getShape()
Get the shape representing this body

Returns:
The shape representing this body

setPosition

public void setPosition(float x,
                        float y)
Set the position of this body, this will also set the previous position to the same value.

Parameters:
x - The x position of this body
y - The y position of this body

move

public void move(float x,
                 float y)
Set the position of this body after it has moved this means the last position will contain the position before this function was called.

Parameters:
x - The x position of this body
y - The y position of this body

getPosition

public ROVector2f getPosition()
Get the position of this body

Returns:
The position of this body

getLastPosition

public ROVector2f getLastPosition()
Get the position of this body before it was moved

Returns:
The last position of this body

getPositionDelta

public ROVector2f getPositionDelta()
Get the change in position in the last update

Returns:
The change in position in the last update

getLastVelocity

public ROVector2f getLastVelocity()
Get the velocity before the last update. This is useful during collisions to determine the change in velocity on impact

Returns:
The last velocity

getVelocityDelta

public ROVector2f getVelocityDelta()
Get the change in velocity in the last update

Returns:
The change in velocity in the last update

getLastAngularVelocity

public float getLastAngularVelocity()
Get the angular velocity before the last update. This is useful during collisions to determine the change in angular velocity on impact

Returns:
The last velocity

getAngularVelocityDelta

public float getAngularVelocityDelta()
Get the change in angular velocity in the last update

Returns:
The change in angular velocity in the last update

getRotation

public float getRotation()
Get the rotation in radians of this body

Returns:
The rotation of this body

adjustPosition

public void adjustPosition(ROVector2f delta,
                           float scale)
Adjust the position of this body. The previous position will be set to the position before this function was called.

Parameters:
delta - The amount to change the position by
scale - The amount to scale the delta by

adjustPosition

public void adjustPosition(Vector2f delta)
Adjust the position of this body The previous position will be set to the position before this function was called.

Parameters:
delta - The amount to change the position by

adjustRotation

public void adjustRotation(float delta)
Adjust the rotation of this body

Parameters:
delta - The amount to change the rotation by

setForce

public void setForce(float x,
                     float y)
Set the force being applied to this body

Parameters:
x - The x component of the force
y - The y component of the force

setTorque

public void setTorque(float t)
Set the torque being applied to this body

Parameters:
t - The torque being applied to this body

getVelocity

public ROVector2f getVelocity()
Get the velocity of this body

Returns:
The velocity of this body

getAngularVelocity

public float getAngularVelocity()
Get the angular velocity of this body

Returns:
The angular velocity of this body

adjustVelocity

public void adjustVelocity(Vector2f delta)
Adjust the velocity of this body

Parameters:
delta - The amount to change the velocity by

adjustAngularVelocity

public void adjustAngularVelocity(float delta)
Adjust the angular velocity of this body

Parameters:
delta - The amount to change the velocity by

getFriction

public float getFriction()
Get the friction on the surface of this body

Returns:
The friction of this surface of this body

getForce

public ROVector2f getForce()
Get the force applied to this body

Returns:
The force applied to this body

getTorque

public float getTorque()
Get the torque applied to this body

Returns:
The torque applied to this body

addForce

public void addForce(Vector2f f)
Add a force to this body

Parameters:
f - The force to be applied

toString

public java.lang.String toString()
See Also:
Object.toString()

hashCode

public int hashCode()
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object other)
See Also:
Object.equals(java.lang.Object)

getBiasedVelocity

public ROVector2f getBiasedVelocity()
Get the bias velocity of this body

Returns:
The bias velocity of this body

getBiasedAngularVelocity

public float getBiasedAngularVelocity()
Get the bias angular velocity of this body

Returns:
The bias angular velocity of this body

adjustBiasedVelocity

public void adjustBiasedVelocity(Vector2f delta)
Adjust the bias velocity of this body

Parameters:
delta - The amount to change the velocity by

adjustBiasedAngularVelocity

public void adjustBiasedAngularVelocity(float delta)
Adjust the bias angular velocity of this body

Parameters:
delta - The amount to change the velocity by

resetBias

public void resetBias()
Reset the bias velocity (done every time step)


getEnergy

public float getEnergy()
Get the energy contained in this body

Returns:
The energy contained in this body

getBitmask

public long getBitmask()
Get this shape's bitmask

Returns:
This shape's bitmask

setBitmask

public void setBitmask(long bitmask)
Set the bismask for this shape.

Parameters:
bitmask - The new bitmask for this shape

addBit

public void addBit(long bitmask)
Set one or more individual bits.

Parameters:
bitmask - A bitmask with the bits that will be switched on.

removeBit

public void removeBit(long bitmask)
Remove one or more individual bits. The set bits will be removed.

Parameters:
bitmask - A bitmask with the bits that will be switched off.

added

public boolean added()
Check the added to simulation flag

Returns:
The added to simulation flag

setAdded

public void setAdded(boolean added)
Set the added to simulation flag

Parameters:
added - The added to simulation flag

setMaxVelocity

public void setMaxVelocity(float maxX,
                           float maxY)
Set the maximum velocity this body can reach. Note that these values arn't signed since they're magnitudes.

Parameters:
maxX - The maximum velocity on the X axis
maxY - The maximum veloicty on the Y axis

validateVelocity

protected void validateVelocity()
Validate the velocity value thats just been applied. Correct it if it breaks any rules. The primary rule is maximum velocity setting