fisica
Class FBlob

java.lang.Object
  extended by fisica.FDrawable
      extended by fisica.FBody
          extended by fisica.FBlob

public class FBlob
extends FBody

Represents a blob body that can be added to a world. Blobs are soft bodies that are composed of vertices and tries to maintain constant the volume the vertices enclose. Blobs can be created by adding vertices using the vertex method in a similar way to FPoly:

 FBlob myBlob = new FBlob();
 myBlob.vertex(40, 10);
 myBlob.vertex(50, 20);
 myBlob.vertex(60, 30);
 myBlob.vertex(60, 40);
 myBlob.vertex(50, 50);
 myBlob.vertex(40, 60);
 myBlob.vertex(30, 70);
 myBlob.vertex(20, 60);
 myBlob.vertex(10, 50);
 myBlob.vertex(10, 40);
 myBlob.vertex(20, 30);
 myBlob.vertex(30, 20);
 myBlob.vertex(40, 10);
 world.add(myBlob);
 
 
or it may be initialized using the method setAsCircle to set the initial shape as a circle:
 FBlob myBlob = new FBlob();
 myBlob.setAsCircle(40);
 world.add(myBlob);
 
 

See Also:
FBox, FCircle, FPoly, FLine

Constructor Summary
FBlob()
          Constructs a blob body that can be added to a world.
 
Method Summary
 void addForce(float fx, float fy)
          Aply a force on the center of the body.
 void addTorque(float t)
          Add a rotation force (a torque) to the body.
 void addToWorld(FWorld world)
           
 void addVertexBody(FBody b)
          Adds a vertex body to the initial shape of the blob.
 void attachImage(processing.core.PImage img)
          Attach an image to the object.
 void dettachImage()
          Dettach any image that has been attached to the object.
 java.util.ArrayList getVertexBodies()
          Returns vertices of the blob.
 float getVertexSize()
          Returns the size of the circular vertices of the blob.
 float getVertexX(int i)
          Gets the x coordinate of the ith vertex of the initial shape of the blob.
 float getVertexY(int i)
          Gets the y coordinate of the ith vertex of the initial shape of the blob.
 void removeFromWorld()
           
 void setAsCircle(float size)
          Sets the initial shape of the blob to a circle.
 void setAsCircle(float x, float y, float size)
          Sets the initial shape of the blob to a circle.
 void setAsCircle(float x, float y, float size, int vertexCount)
          Sets the initial shape of the blob to a circle.
 void setAsCircle(float size, int vertexCount)
          Sets the initial shape of the blob to a circle.
 void setBullet(boolean d)
          Set whether the body is a bullet.
 void setDamping(float damping)
          Sets the damping of the springs used to maintain the volume defined by the vertices constant.
 void setDensity(float d)
          Set the density of the body.
 void setDrawable(boolean val)
          Set whether the object must be drawn or not.
 void setFillColor(int col)
          Set the fill color of the object.
 void setFrequency(float frequency)
          Sets the frequency of the springs used to maintain the volume defined by the vertices constant.
 void setFriction(float d)
          Set the friction of the body.
 void setNoFill()
          Set that the object must be drawn without fill.
 void setNoStroke()
          Set that the object must be drawn without stroke.
 void setRestitution(float d)
          Set the restitution of the body.
 void setStrokeColor(int col)
          Set the stroke color of the object.
 void setStrokeWeight(float col)
          Set the stroke weight of the object.
 void setVertexSize(float size)
          Sets the size of the circular vertices of the blob.
 void vertex(float x, float y)
          Adds a vertex to the initial shape of the blob.
 
Methods inherited from class fisica.FBody
addForce, addImpulse, addImpulse, adjustAngularVelocity, adjustPosition, adjustRotation, adjustVelocity, getAngularVelocity, getBox2dBody, getCategoryBits, getContacts, getDensity, getFilterBits, getForceX, getForceY, getGroupIndex, getJoints, getMass, getName, getParent, getRotation, getTouching, getVelocityX, getVelocityY, getX, getY, isConnected, isResting, isSensor, isSleeping, isStatic, isTouchingBody, recreateInWorld, resetForces, setAllowSleeping, setAngularDamping, setAngularVelocity, setCategoryBits, setFilterBits, setForce, setGrabbable, setGroupIndex, setName, setParent, setPosition, setRotatable, setRotation, setSensor, setState, setStateFromWorld, setStatic, setStaticBody, setVelocity, wakeUp
 
Methods inherited from class fisica.FDrawable
draw, draw, drawDebug, drawDebug, getFillColor, getImageAlpha, isDrawable, setFill, setFill, setFill, setFill, setImageAlpha, setStroke, setStroke, setStroke, setStroke
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FBlob

public FBlob()
Constructs a blob body that can be added to a world. It creates an empty blob, before adding the blob to the world use vertex or setAsCircle to define the initial shape of the blob.

Method Detail

addToWorld

public void addToWorld(FWorld world)
Overrides:
addToWorld in class FBody

removeFromWorld

public void removeFromWorld()
Overrides:
removeFromWorld in class FBody

addVertexBody

public void addVertexBody(FBody b)
Adds a vertex body to the initial shape of the blob. This method must be called before adding the body to the world.

Parameters:
b - b the body to be added

vertex

public void vertex(float x,
                   float y)
Adds a vertex to the initial shape of the blob. This method must be called before adding the body to the world.

Parameters:
x - x coordinate of the vertex to be added
y - y coordinate of the vertex to be added

getVertexX

public float getVertexX(int i)
Gets the x coordinate of the ith vertex of the initial shape of the blob.

Parameters:
i - index of the vertex to retrieve
Returns:
the x coordinate of the vertex to retrieve

getVertexY

public float getVertexY(int i)
Gets the y coordinate of the ith vertex of the initial shape of the blob.

Parameters:
i - index of the vertex to retrieve
Returns:
the y coordinate of the vertex to retrieve

setAsCircle

public void setAsCircle(float x,
                        float y,
                        float size,
                        int vertexCount)
Sets the initial shape of the blob to a circle. This method removes all the previous vertices tha may have been added by the use of the vertex. This method must be called before adding the body to the world.

Parameters:
x - x coordinate of the position of the circle
y - y coordinate of the position of the circle
size - size of the circle
vertexCount - number of vertices of the circle

setAsCircle

public void setAsCircle(float x,
                        float y,
                        float size)
Sets the initial shape of the blob to a circle. This method removes all the previous vertices tha may have been added by the use of the vertex. This method must be called before adding the body to the world.

Parameters:
x - x coordinate of the position of the circle
y - y coordinate of the position of the circle
size - size of the circle

setAsCircle

public void setAsCircle(float size)
Sets the initial shape of the blob to a circle. This method removes all the previous vertices tha may have been added by the use of the vertex. This method must be called before adding the body to the world.

Parameters:
size - size of the circle

setAsCircle

public void setAsCircle(float size,
                        int vertexCount)
Sets the initial shape of the blob to a circle. This method removes all the previous vertices tha may have been added by the use of the vertex. This method must be called before adding the body to the world.

Parameters:
size - size of the circle
vertexCount - number of vertices of the circle

getVertexSize

public float getVertexSize()
Returns the size of the circular vertices of the blob. This method must be called before the body is added to the world.

Returns:
size of the circular vertices of the blob

setVertexSize

public void setVertexSize(float size)
Sets the size of the circular vertices of the blob. This method must be called before the body is added to the world.

Parameters:
size - size of the circular vertices of the blob

getVertexBodies

public java.util.ArrayList getVertexBodies()
Returns vertices of the blob.

Returns:
list of vertex bodies

setFrequency

public void setFrequency(float frequency)
Sets the frequency of the springs used to maintain the volume defined by the vertices constant.

Parameters:
frequency - the frequency of the springs of the constant volume joint

setDamping

public void setDamping(float damping)
Sets the damping of the springs used to maintain the volume defined by the vertices constant.

Overrides:
setDamping in class FBody
Parameters:
damping - the damping of the springs of the constant volume joint
See Also:
FBody.setAngularDamping(float)

addForce

public void addForce(float fx,
                     float fy)
Description copied from class: FBody
Aply a force on the center of the body.

Overrides:
addForce in class FBody
Parameters:
fx - the x coordinate of the force
fy - the y coordinate of the force
See Also:
FBody.addTorque(float), FBody.addForce(float,float,float,float)

addTorque

public void addTorque(float t)
Description copied from class: FBody
Add a rotation force (a torque) to the body.

Overrides:
addTorque in class FBody
Parameters:
t - the value of the torque
See Also:
FBody.addForce(float,float), FBody.addForce(float,float,float,float)

setDensity

public void setDensity(float d)
Description copied from class: FBody
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.

Overrides:
setDensity in class FBody
Parameters:
d - the density of the body

setFriction

public void setFriction(float d)
Description copied from class: FBody
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.

Overrides:
setFriction in class FBody
Parameters:
d - 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

setRestitution

public void setRestitution(float d)
Description copied from class: FBody
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.

Overrides:
setRestitution in class FBody
Parameters:
d - 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

setBullet

public void setBullet(boolean d)
Description copied from class: FBody
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.

Overrides:
setBullet in class FBody
Parameters:
d - if true the body will be a bullet

setNoStroke

public void setNoStroke()
Description copied from class: FDrawable
Set that the object must be drawn without stroke.

Overrides:
setNoStroke in class FDrawable
See Also:
FDrawable.setStroke(float), FDrawable.setStroke(float,float), FDrawable.setStroke(float,float,float), FDrawable.setStroke(float,float,float,float)

setNoFill

public void setNoFill()
Description copied from class: FDrawable
Set that the object must be drawn without fill.

Overrides:
setNoFill in class FDrawable
See Also:
FDrawable.setFill(float), FDrawable.setFill(float,float), FDrawable.setFill(float,float,float), FDrawable.setFill(float,float,float,float)

setFillColor

public void setFillColor(int col)
Description copied from class: FDrawable
Set the fill color of the object. This method must be used in conjunction with Processing's color(). In most cases users will find it more convenient to use the versions of FDrawable.setFill(float), FDrawable.setFill(float,float), FDrawable.setFill(float,float,float) or FDrawable.setFill(float,float,float,float)

Overrides:
setFillColor in class FDrawable
Parameters:
col - a Processing color type. e.g. myBody.setFillColor(color(20,100,30,90));
See Also:
FDrawable.setNoFill(), FDrawable.setFill(float), FDrawable.setFill(float,float), FDrawable.setFill(float,float,float), FDrawable.setFill(float,float,float,float)

setStrokeColor

public void setStrokeColor(int col)
Description copied from class: FDrawable
Set the stroke color of the object. This method must be used in conjunction with Processing's color(). In most cases users will find it more convenient to use the versions of FDrawable.setStroke(float), FDrawable.setStroke(float,float), FDrawable.setStroke(float,float,float) or FDrawable.setStroke(float,float,float,float)

Overrides:
setStrokeColor in class FDrawable
Parameters:
col - a Processing color type. e.g. myBody.setStrokeColor(color(20,100,30,90));
See Also:
FDrawable.setNoStroke(), FDrawable.setStroke(float), FDrawable.setStroke(float,float), FDrawable.setStroke(float,float,float), FDrawable.setStroke(float,float,float,float)

setStrokeWeight

public void setStrokeWeight(float col)
Description copied from class: FDrawable
Set the stroke weight of the object.

Overrides:
setStrokeWeight in class FDrawable
Parameters:
col - weight value in pixels
See Also:
FDrawable.setStroke(float), FDrawable.setStroke(float,float), FDrawable.setStroke(float,float,float), FDrawable.setStroke(float,float,float,float)

setDrawable

public void setDrawable(boolean val)
Description copied from class: FDrawable
Set whether the object must be drawn or not.

Overrides:
setDrawable in class FDrawable
Parameters:
val - if true the object will be drawn, else it will not
See Also:
FDrawable.isDrawable()

attachImage

public void attachImage(processing.core.PImage img)
Description copied from class: FDrawable
Attach an image to the object. This method allows to draw an image onto the screen instead of calling the FDrawable.draw(PApplet) method.

Overrides:
attachImage in class FDrawable
Parameters:
img - the PImage to attach to the object.

dettachImage

public void dettachImage()
Description copied from class: FDrawable
Dettach any image that has been attached to the object.

Overrides:
dettachImage in class FDrawable
See Also:
FDrawable.attachImage(PImage)


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