fisica
Class FBody

java.lang.Object
  extended by fisica.FDrawable
      extended by fisica.FBody
Direct Known Subclasses:
FBlob, FBox, FCircle, FCompound, FLine, FPoly

public abstract class FBody
extends FDrawable

Represents a body in the world. A body is an object which may collide and react to forces in the world. The bodies have many properties such as density, velocity, position, etc... with which we can control their behavior. This class cannot be be instantiated, instead use one of the derived classes.


Constructor Summary
FBody()
           
 
Method Summary
 void addForce(float fx, float fy)
          Aply a force on the center of the body.
 void addForce(float fx, float fy, float px, float py)
          Apply a force to a given point of the body.
 void addImpulse(float fx, float fy)
          Apply an impulse on the center of the body.
 void addImpulse(float fx, float fy, float px, float py)
          Apply an impulse to a given point of the body.
 void addTorque(float torque)
          Add a rotation force (a torque) to the body.
 void addToWorld(FWorld world)
           
 void adjustAngularVelocity(float dw)
          Adjust the rotation velocity of the body.
 void adjustPosition(float dx, float dy)
          Adjust the position of the body.
 void adjustRotation(float dw)
          Adjust the rotation of the body.
 void adjustVelocity(float dvx, float dvy)
          Adjust the velocity of the body.
 float getAngularVelocity()
          Returns the rotation velocity of the body.
 org.jbox2d.dynamics.Body getBox2dBody()
          WARNING: This method is internal only and may change someday.
 int getCategoryBits()
           
 java.util.ArrayList getContacts()
          Return a list of contacts currently involving the body.
 float getDensity()
          Get the density of the body.
 int getFilterBits()
           
 float getForceX()
          Get the x coordinate of the force applied to the center of the body.
 float getForceY()
          Get the y coordinate of the force applied to the center of the body.
 int getGroupIndex()
          Get the group to which this body belongs.
 java.util.ArrayList getJoints()
          Returns a list with all the joints with a connection to the body
 float getMass()
          Returns the mass of the body.
 java.lang.String getName()
          Get the name of the body.
 FBody getParent()
           
 float getRotation()
          Returns the rotation of the body.
 java.util.ArrayList getTouching()
          Return a list of bodies currently touching the body.
 float getVelocityX()
          Returns the horizontal velocity of the body.
 float getVelocityY()
          Returns the vertical velocity of the body.
 float getX()
          Returns the horizontal position of the body.
 float getY()
          Returns the vertical position of the body.
 boolean isConnected(FBody other)
          Returns true if the body is joint to the body passed as argument
 boolean isResting()
          Deprecated.
 boolean isSensor()
          Returns whether the body is a sensor.
 boolean isSleeping()
          Indicates whether the body is in a sleeping state.
 boolean isStatic()
          Returns whether the body is static.
 boolean isTouchingBody(FBody b)
          Return whether the body is currently touching the body passed as argument.
 void recreateInWorld()
           
 void removeFromWorld()
           
 void resetForces()
          Remove all the forces that are applied to the body.
 void setAllowSleeping(boolean allowSleep)
          Set whether the body can sleep.
 void setAngularDamping(float damping)
          Set the damping of the rotation movement of the body.
 void setAngularVelocity(float w)
          Set the rotation velocity of the body.
 void setBullet(boolean value)
          Set whether the body is a bullet.
 void setCategoryBits(int mask)
           
 void setDamping(float damping)
          Set the damping of the translation movement of the body.
 void setDensity(float density)
          Set the density of the body.
 void setFilterBits(int mask)
           
 void setForce(float fx, float fy)
          Set the force applied to the center of the body.
 void setFriction(float friction)
          Set the friction of the body.
 void setGrabbable(boolean value)
          Control if this body can be grabbed by the mouse, when clicked on.
 void setGroupIndex(int index)
          Control the group to which this body belongs.
 void setName(java.lang.String name)
          Set the name of the body.
 void setParent(FBody b)
           
 void setPosition(float x, float y)
          Set the position of the body.
 void setRestitution(float restitution)
          Set the restitution of the body.
 void setRotatable(boolean rotatable)
          Set whether the body can rotate.
 void setRotation(float w)
          Set the rotation of the body.
 void setSensor(boolean value)
          Set whether the body is a sensor.
 void setState(FBody b)
           
 void setStateFromWorld()
           
 void setStatic(boolean value)
          Set whether the body is static.
 void setStaticBody(boolean value)
          Set whether the body is static.
 void setVelocity(float vx, float vy)
          Set the velocity of the body.
 void wakeUp()
          Wake up the body from a sleeping state.
 
Methods inherited from class fisica.FDrawable
attachImage, dettachImage, draw, draw, drawDebug, drawDebug, getFillColor, getImageAlpha, isDrawable, setDrawable, setFill, setFill, setFill, setFill, setFillColor, setImageAlpha, setNoFill, setNoStroke, setStroke, setStroke, setStroke, setStroke, setStrokeColor, setStrokeWeight
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FBody

public FBody()
Method Detail

getBox2dBody

public org.jbox2d.dynamics.Body getBox2dBody()
WARNING: This method is internal only and may change someday. If you are using this method please contact the developer since there should be a better way or we may add something to the library.

Returns:
the internal JBox2D body

getGroupIndex

public int getGroupIndex()
Get the group to which this body belongs. Groups allow to select the bodies that may collide together or with others. If the group index is negative then they will not collide with each other but they will collide with all the bodies of the other groups.

Returns:
the index of the group

addToWorld

public void addToWorld(FWorld world)

setState

public void setState(FBody b)

setStateFromWorld

public void setStateFromWorld()

recreateInWorld

public void recreateInWorld()

removeFromWorld

public void removeFromWorld()

setGroupIndex

public void setGroupIndex(int index)
Control the group to which this body belongs. Groups allow to select the bodies that may collide together or with others. If the group index is negative then they will not collide with each other but they will collide with all the bodies of the other groups.

Parameters:
index - the index of the group

setFilterBits

public void setFilterBits(int mask)

setCategoryBits

public void setCategoryBits(int mask)

getCategoryBits

public int getCategoryBits()

getFilterBits

public int getFilterBits()

setParent

public void setParent(FBody b)

getParent

public FBody getParent()

setGrabbable

public void setGrabbable(boolean value)
Control if this body can be grabbed by the mouse, when clicked on. This property only has effect if the world is grabbable. If a body is grabbable, then it can be dragged around by the mouse.

Parameters:
value - if true and the world it belongs to is grabbable, then the body is grabbable by the mouse
See Also:
FWorld.setGrabbable(boolean)

setForce

public void setForce(float fx,
                     float fy)
Set the force applied to the center of the body.

Parameters:
fx - the x coordinate of the force
fy - the y coordinate of the force
See Also:
addForce(float,float)

getForceX

public float getForceX()
Get the x coordinate of the force applied to the center of the body.

Returns:
the x coordinate of the force
See Also:
addForce(float,float), getForceY()

getForceY

public float getForceY()
Get the y coordinate of the force applied to the center of the body.

Returns:
the y coordinate of the force
See Also:
addForce(float,float), getForceX()

addTorque

public void addTorque(float torque)
Add a rotation force (a torque) to the body.

Parameters:
torque - the value of the torque
See Also:
addForce(float,float), addForce(float,float,float,float)

addForce

public void addForce(float fx,
                     float fy)
Aply a force on the center of the body.

Parameters:
fx - the x coordinate of the force
fy - the y coordinate of the force
See Also:
addTorque(float), addForce(float,float,float,float)

addImpulse

public void addImpulse(float fx,
                       float fy)
Apply an impulse on the center of the body.

Parameters:
fx - the x coordinate of the force
fy - the y coordinate of the force
See Also:
addTorque(float), addForce(float,float,float,float)

addForce

public void addForce(float fx,
                     float fy,
                     float px,
                     float py)
Apply a force to a given point of the body. If the force is not applied on the center of the body this force might induce a rotation change. It would be as applying a force on the center of the body and a torque.

Parameters:
fx - the x coordinate of the force
fy - the y coordinate of the force
px - the x position relative to the body's center, where to apply the force
py - the y position relative to the body's center, where to apply the force
See Also:
addTorque(float), addImpulse(float,float,float,float)

addImpulse

public void addImpulse(float fx,
                       float fy,
                       float px,
                       float py)
Apply an impulse to a given point of the body. If the impulse is not applied on the center of the body this force might induce a rotation change. It would be as applying a force on the center of the body and a torque.

Parameters:
fx - the x coordinate of the force
fy - the y coordinate of the force
px - the x position relative to the body's center, where to apply the force
py - the y position relative to the body's center, where to apply the force
See Also:
addTorque(float), addForce(float,float,float,float)

resetForces

public void resetForces()
Remove all the forces that are applied to the body.


getVelocityX

public float getVelocityX()
Returns the horizontal velocity of the body.

Returns:
the horizontal velocity of the body in pixels per second

getVelocityY

public float getVelocityY()
Returns the vertical velocity of the body.

Returns:
the vertical velocity of the body in pixels per second

setVelocity

public void setVelocity(float vx,
                        float vy)
Set the velocity of the body.

Parameters:
vx - the horizontal velocity of the body in pixels per second
vy - the vertical velocity of the body in pixels per second

adjustVelocity

public void adjustVelocity(float dvx,
                           float dvy)
Adjust the velocity of the body.

Parameters:
dvx - the horizontal velocity to be added to the body in pixels per second
dvy - the vertical velocity to be added to the body in pixels per second

getX

public float getX()
Returns the horizontal position of the body.

Returns:
the horizontal position of the body in pixels
See Also:
getY(), setPosition(float,float)

getY

public float getY()
Returns the vertical position of the body.

Returns:
the vertical position of the body in pixels
See Also:
getX(), setPosition(float,float)

setPosition

public void setPosition(float x,
                        float y)
Set the position of the body.

Parameters:
x - the horizontal position of the body in pixels
y - the vertical position of the body in pixels

adjustPosition

public void adjustPosition(float dx,
                           float dy)
Adjust the position of the body.

Parameters:
dx - the horizontal position to be added to the body in pixels
dy - the vertical position to be added to the body in pixels

getRotation

public float getRotation()
Returns the rotation of the body.

Returns:
the rotation of the body in radians
See Also:
setRotation(float)

setRotation

public void setRotation(float w)
Set the rotation of the body.

Parameters:
w - the rotation of the body in radians
See Also:
getRotation()

adjustRotation

public void adjustRotation(float dw)
Adjust the rotation of the body.

Parameters:
dw - the rotation to be added to the body in radians
See Also:
getRotation(), setRotation(float)

isResting

public boolean isResting()
Deprecated. Please use isSleeping().

Returns:
true if the body is resting

isSleeping

public boolean isSleeping()
Indicates whether the body is in a sleeping state. The sleeping state of a body is reached when it has not moved or has not received any forces nor collisions for some time.

Returns:
true if the body is sleeping
See Also:
wakeUp(), setAllowSleeping(boolean)

wakeUp

public void wakeUp()
Wake up the body from a sleeping state.

See Also:
isSleeping(), setAllowSleeping(boolean)

getAngularVelocity

public float getAngularVelocity()
Returns the rotation velocity of the body.

Returns:
the rotation velocity of the body in radians per second
See Also:
setAngularVelocity(float), adjustAngularVelocity(float)

setAngularVelocity

public void setAngularVelocity(float w)
Set the rotation velocity of the body.

Parameters:
w - the rotation velocity of the body in radians per second

adjustAngularVelocity

public void adjustAngularVelocity(float dw)
Adjust the rotation velocity of the body.

Parameters:
dw - the rotation velocity to be added to the body in radians per second
See Also:
getAngularVelocity(), setAngularVelocity(float)

setAngularDamping

public void setAngularDamping(float damping)
Set the damping of the rotation movement of the body. The damping constantly reduces the rotation velocity of the body.

Parameters:
damping - the damping of the rotation movement of the body
See Also:
setDamping(float)

setDamping

public void setDamping(float damping)
Set the damping of the translation movement of the body. The damping constantly reduces the translation velocity of the body.

Parameters:
damping - the damping of the translation movement of the body
See Also:
setAngularDamping(float)

setName

public void setName(java.lang.String name)
Set the name of the body.

Parameters:
name - the name of the body

getName

public java.lang.String getName()
Get the name of the body.

Returns:
name the name of the body

setDensity

public void setDensity(float density)
Set the density of the body. The density will determine the total mass of the body and thus it's behavior with respect to collisions, bounces, inertia, joints,... When the density is set, the mass of the body is recalculated automatically given it's area. Note that a density of 0.0 corresponds to a mass of 0.0 independently of the area and the body will be considered static.

Parameters:
density - the density of the body

getDensity

public float getDensity()
Get the density of the body. The density determines the total mass of the body and thus it's behavior with respect to collisions, bounces, inertia, joints,... Note that a density of 0.0 corresponds to a mass of 0.0 independently of the area and the body will be considered static.

Returns:
density the density of the body

setSensor

public void setSensor(boolean value)
Set whether the body is a sensor. Sensor bodies act as normal bodies in the sense that they notify about contacts, however they do not collide with other bodies (they act like ghost bodies).

Parameters:
value - if true the body will be a sensor. It will not collide when enters contact with other bodies

isSensor

public boolean isSensor()
Returns whether the body is a sensor. Sensor bodies act as normal bodies in the sense that they notify about contacts, however they do not collide with other bodies (they act like ghost bodies).

Returns:
if true the body is a sensor. It will not collide when enters contact with other bodies

setStaticBody

public void setStaticBody(boolean value)
Set whether the body is static. Static bodies do not move or rotate, unless done manually using setPosition or setRotation.

Parameters:
value - if true the body will be static

setStatic

public void setStatic(boolean value)
Set whether the body is static. Static bodies do not move or rotate, unless done manually using setPosition or setRotation.

Parameters:
value - if true the body will be static

getMass

public float getMass()
Returns the mass of the body. Static bodies or bodies not added to the world return 0.

Returns:
the mass of the body or 0 if static

isStatic

public boolean isStatic()
Returns whether the body is static. Static bodies do not move or rotate, unless done manually using setPosition or setRotation.

Returns:
if true the body is static

setBullet

public void setBullet(boolean value)
Set whether the body is a bullet. Bullet bodies are computationally more expensive but more accurate in their movement. Use this only with fast objects.

Parameters:
value - if true the body will be a bullet

setRestitution

public void setRestitution(float restitution)
Set the restitution of the body. The restitution determines the ratio of the reaction force normal to a contact, when the body collides with another body. Basically it can be seen as a coefficient that will control the strength with which the body bounces back from a collision. The resititution of a contact of two bodies in a collision is calculated as the maximum of the restitution values of the 2 bodies involved.

Parameters:
restitution - a positive value. A value of 0 means no bounce after a collision, and a value of 1 means bounce with it's full speed from a collision

setFriction

public void setFriction(float friction)
Set the friction of the body. The friction determines the ratio of the reaction force tangent to a contact, when the body collides with another body. Basically it can be seen as a coefficient that will control how the body gets slown down when the body slides against another body. The friction of a contact of two bodies in a collision is calculated from the friction values of the 2 bodies involved.

Parameters:
friction - a positive value. A value of 0 means no friction and thus the body will not be slown down if no other forces are applied

setRotatable

public void setRotatable(boolean rotatable)
Set whether the body can rotate.

Parameters:
rotatable - if true the body will not rotate

setAllowSleeping

public void setAllowSleeping(boolean allowSleep)
Set whether the body can sleep.

Parameters:
allowSleep - if true the body will be able to sleep

getTouching

public java.util.ArrayList getTouching()
Return a list of bodies currently touching the body.

Returns:
list of bodies (ArrayList of FBody) touching the body

getContacts

public java.util.ArrayList getContacts()
Return a list of contacts currently involving the body.

Returns:
list of contacts (ArrayList of FContact) touching the body

getJoints

public java.util.ArrayList getJoints()
Returns a list with all the joints with a connection to the body

Returns:
an ArrayList (of FJoint) connected to the body

isConnected

public boolean isConnected(FBody other)
Returns true if the body is joint to the body passed as argument

Parameters:
other - the other body
Returns:
if true the body is connected to other

isTouchingBody

public boolean isTouchingBody(FBody b)
Return whether the body is currently touching the body passed as argument.

Parameters:
b - the body for which we want to know if there is contact
Returns:
if true the body is touching b


processing library fisica by Ricard Marxer. (c) 2009-2013