hAPI Fisica  0.1
The hAPI Fisica physics engine expands Richard Marxer's fisica for Processing. The engine wraps the jbox2d physics engine for use with the Haply Development kit and the Hapkit.
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
FBody Class Referenceabstract
Inheritance diagram for FBody:
FDrawable FBlob FBox FCircle FCompound FLine FPoly HTool

Public Member Functions

Body getBox2dBody ()
 
int getGroupIndex ()
 
void addToWorld (FWorld world)
 
void setState (FBody b)
 
void setStateFromWorld ()
 
void recreateInWorld ()
 
void removeFromWorld ()
 
void setGroupIndex (int index)
 
void setFilterBits (int mask)
 
void setCategoryBits (int mask)
 
int getCategoryBits ()
 
int getFilterBits ()
 
void setParent (FBody b)
 
FBody getParent ()
 
void setGrabbable (boolean value)
 
void setForce (float fx, float fy)
 
float getForceX ()
 
float getForceY ()
 
void addTorque (float torque)
 
void addForce (float fx, float fy)
 
void addImpulse (float fx, float fy)
 
void addForce (float fx, float fy, float px, float py)
 
void addImpulse (float fx, float fy, float px, float py)
 
void resetForces ()
 
float getVelocityX ()
 
float getVelocityY ()
 
void setVelocity (float vx, float vy)
 
void adjustVelocity (float dvx, float dvy)
 
float getX ()
 
float getY ()
 
void setPosition (float x, float y)
 
void adjustPosition (float dx, float dy)
 
float getRotation ()
 
float getHapticStiffness ()
 
float getHapticDamping ()
 
void setRotation (float w)
 
void adjustRotation (float dw)
 
boolean isResting ()
 
boolean isSleeping ()
 
void wakeUp ()
 
float getAngularVelocity ()
 
void setAngularVelocity (float w)
 
void adjustAngularVelocity (float dw)
 
void setAngularDamping (float damping)
 
void setDamping (float damping)
 
void setName (String name)
 
String getName ()
 
void setDensity (float density)
 
float getDensity ()
 
void setSensor (boolean value)
 
boolean isSensor ()
 
void setHaptic (boolean value)
 
void setHaptic (boolean value, float stiffness, float damping)
 
boolean isHaptic ()
 
void setHapticStiffness (float stiffness)
 
void setHapticDamping (float damping)
 
void setStaticBody (boolean value)
 
void setStatic (boolean value)
 
float getMass ()
 
boolean isStatic ()
 
void setBullet (boolean value)
 
void setRestitution (float restitution)
 
void setFriction (float friction)
 
void setRotatable (boolean rotatable)
 
void setAllowSleeping (boolean allowSleep)
 
ArrayList getTouching ()
 
ArrayList getContacts ()
 
ArrayList getJoints ()
 
boolean isConnected (FBody other)
 
boolean isTouchingBody (FBody b)
 
- Public Member Functions inherited from FDrawable
void draw (PGraphics graphics)
 
void draw (PApplet applet)
 
void drawDebug (PGraphics graphics)
 
void drawDebug (PApplet applet)
 
void attachImage (PImage img)
 
void dettachImage ()
 
float getImageAlpha ()
 
void setImageAlpha (float alpha)
 
void setDrawable (boolean drawable)
 
boolean isDrawable ()
 
int getFillColor ()
 
void setFillColor (int col)
 
void setNoFill ()
 
void setFill (float g)
 
void setFill (float g, float a)
 
void setFill (float r, float g, float b)
 
void setFill (float r, float g, float b, float a)
 
void setStrokeColor (int col)
 
void setNoStroke ()
 
void setStroke (float g)
 
void setStroke (float g, float a)
 
void setStroke (float r, float g, float b)
 
void setStroke (float r, float g, float b, float a)
 
void setStrokeWeight (float weight)
 

Protected Member Functions

void processBody (Body bd, ShapeDef sd)
 
ShapeDef getShapeDef ()
 
ShapeDef getTransformedShapeDef ()
 
ShapeDef getProcessedShapeDef ()
 
ArrayList getShapeDefs ()
 
ArrayList getBodies ()
 
ShapeDef processShapeDef (ShapeDef sd)
 
void preDraw (PGraphics applet)
 
void postDraw (PGraphics applet)
 
void preDrawDebug (PGraphics applet)
 
void postDrawDebug (PGraphics applet)
 
AABB getAABB ()
 
AABB getBB ()
 
void applyMatrix (PGraphics applet)
 
void setPosition (Vec2 position)
 
void updateMass ()
 
Vec2 getLocalWorldPoint (Vec2 p)
 
- Protected Member Functions inherited from FDrawable
void updateStyle (FDrawable other)
 
void appletStroke (PGraphics applet, int argb)
 
void appletFill (PGraphics applet, int argb)
 
void appletFillStroke (PGraphics applet)
 
void drawImage (PGraphics applet)
 

Protected Attributes

float m_density = 1.0f
 
float m_restitution = 0.1f
 
float m_friction = 0.1f
 
boolean m_bullet = false
 
boolean m_sensor = false
 
boolean m_static = false
 
float m_linearDamping = 0.5f
 
float m_gravityScale = 1.0f
 
float m_angularDamping = 0.5f
 
boolean m_rotatable = true
 
boolean m_allowSleep = true
 
boolean m_isSleeping = false
 
int m_groupIndex = 0
 
int m_filterBits = 0xffff
 
int m_categoryBits = 0x0001
 
Vec2 m_linearVelocity = new Vec2(0.0f, 0.0f)
 
float m_angularVelocity = 0.0f
 
Vec2 m_force = new Vec2(0.0f, 0.0f)
 
float m_torque = 0.0f
 
Vec2 m_position = new Vec2(0.0f, 0.0f)
 
float m_angle = 0.0f
 
String m_name
 
Body m_body
 
FWorld m_world
 
FBody m_parent
 
boolean m_grabbable = true
 
boolean h_isHaptic = true
 
float h_damping = 0.0f
 
float h_stiffness =0.0f
 
- Protected Attributes inherited from FDrawable
boolean m_drawable = true
 
boolean m_fill = true
 
int m_fillColor = 0xFFFFFFFF
 
boolean m_stroke = true
 
int m_strokeColor = 0xFF000000
 
float m_strokeWeight = 1.0f
 
PImage m_image = null
 
float m_imageAlpha = 255.0f
 
PImage m_mask = null
 

Detailed Description

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.

Member Function Documentation

◆ addForce() [1/2]

void FBody.addForce ( float  fx,
float  fy 
)

Aply a force on the center of the body.

See also
addTorque(float)
addForce(float,float,float,float)
Parameters
fxthe x coordinate of the force
fythe y coordinate of the force

◆ addForce() [2/2]

void FBody.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.

See also
addTorque(float)
addImpulse(float,float,float,float)
Parameters
fxthe x coordinate of the force
fythe y coordinate of the force
pxthe x position relative to the body's center, where to apply the force
pythe y position relative to the body's center, where to apply the force

◆ addImpulse() [1/2]

void FBody.addImpulse ( float  fx,
float  fy 
)

Apply an impulse on the center of the body.

See also
addTorque(float)
addForce(float,float,float,float)
Parameters
fxthe x coordinate of the force
fythe y coordinate of the force

◆ addImpulse() [2/2]

void FBody.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.

See also
addTorque(float)
addForce(float,float,float,float)
Parameters
fxthe x coordinate of the force
fythe y coordinate of the force
pxthe x position relative to the body's center, where to apply the force
pythe y position relative to the body's center, where to apply the force

◆ addTorque()

void FBody.addTorque ( float  torque)

Add a rotation force (a torque) to the body.

See also
addForce(float,float)
addForce(float,float,float,float)
Parameters
torquethe value of the torque

◆ adjustAngularVelocity()

void FBody.adjustAngularVelocity ( float  dw)

Adjust the rotation velocity of the body.

Parameters
dwthe rotation velocity to be added to the body in radians per second
See also
getAngularVelocity()
setAngularVelocity(float)

◆ adjustPosition()

void FBody.adjustPosition ( float  dx,
float  dy 
)

Adjust the position of the body.

Parameters
dxthe horizontal position to be added to the body in simulation world units
dythe vertical position to be added to the body in simulation world units

◆ adjustRotation()

void FBody.adjustRotation ( float  dw)

Adjust the rotation of the body.

Parameters
dwthe rotation to be added to the body in radians
See also
getRotation()
setRotation(float)

◆ adjustVelocity()

void FBody.adjustVelocity ( float  dvx,
float  dvy 
)

Adjust the velocity of the body.

Parameters
dvxthe horizontal velocity to be added to the body in simulation world units per second
dvythe vertical velocity to be added to the body in simulation world units per second

◆ getAngularVelocity()

float FBody.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)

◆ getBox2dBody()

Body FBody.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

◆ getContacts()

ArrayList FBody.getContacts ( )

Return a list of contacts currently involving the body.

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

◆ getDensity()

float FBody.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

◆ getForceX()

float FBody.getForceX ( )

Get the x coordinate of the force applied to the center of the body.

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

◆ getForceY()

float FBody.getForceY ( )

Get the y coordinate of the force applied to the center of the body.

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

◆ getGroupIndex()

int FBody.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

◆ getHapticDamping()

float FBody.getHapticDamping ( )

Returns the haptic damping of the body.

Returns
the haptic damping coefficient of the body in dyne seconds per
See also
setHapticDamping(float)
#setHapticDamping(hDamping)

◆ getHapticStiffness()

float FBody.getHapticStiffness ( )

Returns the haptic stiffness of the body.

Returns
the haptic stiffness coefficient of the body in dyne per meter (CGS units)
See also
setHapticStiffness(float)
#setHapticStiffness(hStiffness)

◆ getJoints()

ArrayList FBody.getJoints ( )

Returns a list with all the joints with a connection to the body

Returns
an ArrayList (of FJoint) connected to the body

◆ getMass()

float FBody.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

◆ getName()

String FBody.getName ( )

Get the name of the body.

Returns
name the name of the body

◆ getRotation()

float FBody.getRotation ( )

Returns the rotation of the body.

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

◆ getTouching()

ArrayList FBody.getTouching ( )

Return a list of bodies currently touching the body.

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

◆ getVelocityX()

float FBody.getVelocityX ( )

Returns the horizontal velocity of the body.

Returns
the horizontal velocity of the body in simulation world units per second

◆ getVelocityY()

float FBody.getVelocityY ( )

Returns the vertical velocity of the body.

Returns
the vertical velocity of the body in simulation world units per second

◆ getX()

float FBody.getX ( )

Returns the horizontal position of the body.

Returns
the horizontal position of the body in simulation world units
See also
getY
setPosition(float,float)

◆ getY()

float FBody.getY ( )

Returns the vertical position of the body.

Returns
the vertical position of the body in simulation world units
See also
getX
setPosition(float,float)

◆ isConnected()

boolean FBody.isConnected ( FBody  other)

Returns true if the body is joint to the body passed as argument

Parameters
otherthe other body
Returns
if
true
the body is connected to other

◆ isHaptic()

boolean FBody.isHaptic ( )

Returns whether the body is a haptic body. Haptic bodies act as normal bodies in the sense that they notify about contacts, however they allow for penalty based force calculation that resut from colliding with other bodies. This can be used for direct contact rendering using penalty forumations.

Returns
if
true
the body is a haptic body. Resultant forces will be calculated between this body and other bodies based on penalty based formulations.

◆ isResting()

boolean FBody.isResting ( )

Deprecated. Please use isSleeping().

Returns
true if the body is resting

◆ isSensor()

boolean FBody.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

◆ isSleeping()

boolean FBody.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)

◆ isStatic()

boolean FBody.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

◆ isTouchingBody()

boolean FBody.isTouchingBody ( FBody  b)

Return whether the body is currently touching the body passed as argument.

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

◆ resetForces()

void FBody.resetForces ( )

Remove all the forces that are applied to the body.

◆ setAllowSleeping()

void FBody.setAllowSleeping ( boolean  allowSleep)

Set whether the body can sleep.

Parameters
allowSleepif
true
the body will be able to sleep

◆ setAngularDamping()

void FBody.setAngularDamping ( float  damping)

Set the damping of the rotation movement of the body. The damping constantly reduces the rotation velocity of the body.

Parameters
dampingthe damping of the rotation movement of the body
See also
setDamping(float)

◆ setAngularVelocity()

void FBody.setAngularVelocity ( float  w)

Set the rotation velocity of the body.

Parameters
wthe rotation velocity of the body in radians per second

◆ setBullet()

void FBody.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
valueif
true
the body will be a bullet

◆ setDamping()

void FBody.setDamping ( float  damping)

Set the damping of the translation movement of the body. The damping constantly reduces the translation velocity of the body.

Parameters
dampingthe damping of the translation movement of the body
See also
setAngularDamping(float)

◆ setDensity()

void FBody.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
densitythe density of the body

◆ setForce()

void FBody.setForce ( float  fx,
float  fy 
)

Set the force applied to the center of the body.

See also
addForce(float,float)
Parameters
fxthe x coordinate of the force
fythe y coordinate of the force

◆ setFriction()

void FBody.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
frictiona positive value. A value of 0 means no friction and thus the body will not be slown down if no other forces are applied

◆ setGrabbable()

void FBody.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.

See also
FWorld::setGrabbable(boolean)
Parameters
valueif
true
and the world it belongs to is grabbable, then the body is grabbable by the mouse

◆ setGroupIndex()

void FBody.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
indexthe index of the group

◆ setHaptic() [1/2]

void FBody.setHaptic ( boolean  value)

Set whether the body is a haptic body. Haptic bodies act as normal bodies in the sense that they notify about contacts, however they allow for collision with other bodies using a penalty based method. This allows us to render haptic contacts to a device.

Parameters
valueif
true
the body will be a haptic body. If if
false
the body will not generate a force when colliding with other bodies

◆ setHaptic() [2/2]

void FBody.setHaptic ( boolean  value,
float  stiffness,
float  damping 
)

Set whether the body is a haptic body. Haptic bodies act as normal bodies in the sense that they notify about contacts, however they allow for collision with other bodies using a penalty based method. This allows us to render haptic contacts to a device.

Parameters
valueif
true
the body will be a haptic body. If if
false
the body will not generate a force when colliding with other bodies
stiffnesssets the stiffness of the haptic body for direct collision rendering
dampingsets the damping coefficent of the haptic body for direct collision rendering

◆ setHapticDamping()

void FBody.setHapticDamping ( float  damping)

Sets the damping of a haptic body for penalty based contact rendering.

Parameters
dampingThe damping of the haptic body. Resultant forces are proportional to the amount of penetration between bodies

◆ setHapticStiffness()

void FBody.setHapticStiffness ( float  stiffness)

Sets the stiffness of a haptic body for penalty based contact rendering.

Parameters
stiffnessThe stiffness of the haptic body. Resultant forces are proportional to the amount of penetration between bodies

◆ setName()

void FBody.setName ( String  name)

Set the name of the body.

Parameters
namethe name of the body

◆ setPosition()

void FBody.setPosition ( float  x,
float  y 
)

Set the position of the body.

Parameters
xthe horizontal position of the body in simulation world units
ythe vertical position of the body in simulation world units

◆ setRestitution()

void FBody.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
restitutiona 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

◆ setRotatable()

void FBody.setRotatable ( boolean  rotatable)

Set whether the body can rotate.

Parameters
rotatableif
true
the body will not rotate

◆ setRotation()

void FBody.setRotation ( float  w)

Set the rotation of the body.

Parameters
wthe rotation of the body in radians
See also
getRotation()

◆ setSensor()

void FBody.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
valueif
true
the body will be a sensor. It will not collide when enters contact with other bodies

◆ setStatic()

void FBody.setStatic ( boolean  value)

Set whether the body is static. Static bodies do not move or rotate, unless done manually using setPosition or setRotation.

Parameters
valueif
true
the body will be static

◆ setStaticBody()

void FBody.setStaticBody ( boolean  value)

Set whether the body is static. Static bodies do not move or rotate, unless done manually using setPosition or setRotation.

Parameters
valueif
true
the body will be static

◆ setVelocity()

void FBody.setVelocity ( float  vx,
float  vy 
)

Set the velocity of the body.

Parameters
vxthe horizontal velocity of the body in simulation world units per second
vythe vertical velocity of the body in simulation world units per second

◆ wakeUp()

void FBody.wakeUp ( )

Wake up the body from a sleeping state.

See also
isSleeping()
setAllowSleeping(boolean)

The documentation for this class was generated from the following file: