fisica
Class FWorld

java.lang.Object
  extended by org.jbox2d.dynamics.World
      extended by fisica.FWorld

public class FWorld
extends org.jbox2d.dynamics.World

Represents the world where all the bodies live in. When we create a world it will have the size of the applet that it is created in. Once the world is created we can add bodies to it or remove bodies we have added. Once the world is created we may add or remove bodies to it using add and remove. We may also call step to advance one step the simulation. Finally we can draw the world and all the bodies living in it by using draw.

 FWorld world;

 void setup() {
   Fisica.init(this);

   world = new FWorld();
   world.setEdges();

   // Create and add bodies to the world here
   // ...
 }

 void draw() {
   world.step();
   world.draw();
 }

 

See Also:
FBody

Field Summary
 FBox bottom
          The bottom edge of the world.
 FBox left
          The left edge of the world.
 FBox right
          The right edge of the world.
 FBox top
          The top edge of the world.
 
Constructor Summary
FWorld()
           
FWorld(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY)
          Constructs the world where all the bodies live in.
 
Method Summary
 void add(FBody body)
          Add a body to the world.
 void add(FJoint joint)
          Add a joint to the world.
 void addBody(FBody body)
           
 void addJoint(FJoint joint)
           
 void clear()
          Clear all bodies and joints from the world.
 void dragBody(float x, float y)
           
 void draw()
          Draws all the bodies in the world on the applet canvas.
 void draw(processing.core.PApplet applet)
          Draws all the bodies in the world.
 void draw(processing.core.PGraphics graphics)
          Draws all the bodies in the world.
 void drawDebug()
          Draws the debug version of all the bodies in the world on the applet canvas.
 void drawDebug(processing.core.PApplet applet)
          Draws the debug version of all the bodies in the world.
 void drawDebug(processing.core.PGraphics graphics)
          Draws the debug version of all the bodies in the world.
 java.util.ArrayList getBodies()
          Returns a list with all the bodies in the world
 java.util.ArrayList getBodies(float x, float y)
          Returns a list with the 10 first bodies found at the given position.
 java.util.ArrayList getBodies(float x, float y, boolean getStatic)
          Returns a list with the 10 first bodies found at the given position.
 java.util.ArrayList getBodies(float x, float y, boolean getStatic, int count)
          Returns a list with all the bodies found at the given position.
 FBody getBody(float x, float y)
          Returns the first object found at the given position.
 FBody getBody(float x, float y, boolean getStatic)
          Returns the first object found at the given position.
 FMouseJoint getMouseJoint()
          Returns the mouse joint that is used for interaction with the bodies in the world.
 void grabBody(float x, float y)
           
 void mouseEvent(processing.event.MouseEvent event)
          This is an internal method to handle mouse interaction and should not be used.
 void processActions()
           
 int raycast(float x1, float y1, float x2, float y2, FBody[] bodies, int maxCount, boolean solidShapes)
           
 FBody raycastOne(float x1, float y1, float x2, float y2, FRaycastResult result, boolean solidShapes)
           
 void releaseBody()
           
 void remove(FBody body)
          Remove a body from the world.
 void remove(FJoint joint)
          Remove a joint from the world.
 void removeBody(FBody body)
           
 void removeJoint(FJoint joint)
           
 void setEdges()
          Add black edges of Processing's canvas dimensions to the world.
 void setEdges(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY)
          Add black edges of given dimensions to the world.
 void setEdges(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY, int color)
          Add edges of given dimensions to the world.
 void setEdges(int color)
          Add edges of Processing's canvas dimensions to the world.
 void setEdges(processing.core.PApplet applet, int color)
          Add edges of given applet's dimensions to the world.
 void setEdgesFriction(float friction)
          Set the friction of all the edges.
 void setEdgesRestitution(float restitution)
          Set the restitution of all the edges.
 void setGrabbable(boolean value)
          Controls whether the bodies in the world can be grabbed by the mouse or not.
 void setGravity(float gx, float gy)
          Set the gravity of the world.
 void step()
          Advance the world simulation of 1/60th of a second.
 void step(float dt)
          Advance the world simulation of given time.
 void step(float dt, int iterationCount)
          Advance the world simulation of given time, with a given number of iterations.
 
Methods inherited from class org.jbox2d.dynamics.World
createBody, createController, createJoint, destroyBody, destroyController, destroyJoint, drawDebugData, drawJoint, drawShape, getBodyCount, getBodyList, getContactCount, getDebugDraw, getGravity, getGroundBody, getJointCount, getJointList, getPairCount, getProxyCount, getWorldAABB, inRange, isAutoDebugDraw, isDrawingDebugData, query, raycast, raycastOne, refilter, registerPostStep, setAutoDebugDraw, setBoundaryListener, setContactFilter, setContactListener, setContinuousPhysics, setDebugDraw, setDestructionListener, setDrawDebugData, setGravity, setPositionCorrection, setWarmStarting, solve, solveTOI, unregisterPostStep, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

left

public FBox left
The left edge of the world. For this edge to exist, the edges must have been created by calling setEdges().

See Also:
left, right, bottom, top

right

public FBox right
The right edge of the world. For this edge to exist, the edges must have been created by calling setEdges().

See Also:
left, right, bottom, top

top

public FBox top
The top edge of the world. For this edge to exist, the edges must have been created by calling setEdges().

See Also:
left, right, bottom, top

bottom

public FBox bottom
The bottom edge of the world. For this edge to exist, the edges must have been created by calling setEdges().

See Also:
left, right, bottom, top
Constructor Detail

FWorld

public FWorld(float topLeftX,
              float topLeftY,
              float bottomRightX,
              float bottomRightY)
Constructs the world where all the bodies live in. We usually want to build the world larger than the actual screen, because when bodies exit the world they will appear stuck since they do not get update anymore. By default the world's width and height are three times larger than those of the Processing canvas. FWorld world; void setup() { size(200, 200); Fisica.init(this); world = new FWorld(-width, -height, 2*width, 2*height); }

Parameters:
topLeftX - the horizontal coordinate of the top left corner of the world
topLeftY - the vertical coordinate of the top left corner of the world
bottomRightX - the horizontal coordinate of the bottom right corner of the world
bottomRightY - the vertical coordinate of the bottom right corner of the world
See Also:
FBody

FWorld

public FWorld()
Method Detail

addBody

public void addBody(FBody body)

removeBody

public void removeBody(FBody body)

addJoint

public void addJoint(FJoint joint)

removeJoint

public void removeJoint(FJoint joint)

grabBody

public void grabBody(float x,
                     float y)

dragBody

public void dragBody(float x,
                     float y)

releaseBody

public void releaseBody()

mouseEvent

public void mouseEvent(processing.event.MouseEvent event)
This is an internal method to handle mouse interaction and should not be used.


getMouseJoint

public FMouseJoint getMouseJoint()
Returns the mouse joint that is used for interaction with the bodies in the world.

Returns:
the mouse joint used for grabbing bodies

setGrabbable

public void setGrabbable(boolean value)
Controls whether the bodies in the world can be grabbed by the mouse or not. By default the world bodies' are grabbable and draggable. world.setGrabbable(false);

Parameters:
value - if true the bodies that live in this world can be grabbed and dragged using the mouse
See Also:
FBody

processActions

public void processActions()

draw

public void draw(processing.core.PApplet applet)
Draws all the bodies in the world. This method is often called in the draw method of the applet.

Parameters:
applet - applet to which to draw the world. Useful when trying to draw the world on other Processing backends, such as PDF
See Also:
FBody

draw

public void draw(processing.core.PGraphics graphics)
Draws all the bodies in the world. This method is often called in the draw method of the applet.

Parameters:
graphics - graphics to which to draw the world. Useful when trying to draw the world on other buffers, such as when using createGraphics
See Also:
FBody

drawDebug

public void drawDebug(processing.core.PApplet applet)
Draws the debug version of all the bodies in the world. This method is often called in the draw method of the applet.

Parameters:
applet - applet to which to draw the world. Useful when trying to draw the world on other Processing backends, such as PDF
See Also:
FBody

drawDebug

public void drawDebug(processing.core.PGraphics graphics)
Draws the debug version of all the bodies in the world. This method is often called in the draw method of the applet.

Parameters:
graphics - graphics to which to draw the world. Useful when trying to draw the world on other buffers, such as when using createGraphics
See Also:
FBody

draw

public void draw()
Draws all the bodies in the world on the applet canvas. This method is often called in the draw method of the applet.

See Also:
FBody

drawDebug

public void drawDebug()
Draws the debug version of all the bodies in the world on the applet canvas. This method is often called in the draw method of the applet.

See Also:
FBody

add

public void add(FBody body)
Add a body to the world.

Parameters:
body - body to be added to the world
See Also:
remove(FBody)

remove

public void remove(FBody body)
Remove a body from the world.

Parameters:
body - body to be removed from the world
See Also:
add(FBody)

add

public void add(FJoint joint)
Add a joint to the world.

Parameters:
joint - joint to be added to the world
See Also:
remove(FJoint)

remove

public void remove(FJoint joint)
Remove a joint from the world.

Parameters:
joint - joint to be removed from the world
See Also:
add(FJoint)

clear

public void clear()
Clear all bodies and joints from the world. NOT IMPLEMENTED YET.


setEdges

public void setEdges(float topLeftX,
                     float topLeftY,
                     float bottomRightX,
                     float bottomRightY,
                     int color)
Add edges of given dimensions to the world. This will create the bodies for left, right, bottom and top.

Parameters:
topLeftX - the horizontal coordinate of the top left corner of the edges
topLeftY - the vertical coordinate of the top left corner of the edges
bottomRightX - the horizontal coordinate of the bottom right corner of the edges
bottomRightY - the vertical coordinate of the bottom right corner of the edges
color - the color of the edges. This color must be passed using Processing's color() function

setEdges

public void setEdges(float topLeftX,
                     float topLeftY,
                     float bottomRightX,
                     float bottomRightY)
Add black edges of given dimensions to the world. This will create the bodies for left, right, bottom and top.

Parameters:
topLeftX - the horizontal coordinate of the top left corner of the edges
topLeftY - the vertical coordinate of the top left corner of the edges
bottomRightX - the horizontal coordinate of the bottom right corner of the edges
bottomRightY - the vertical coordinate of the bottom right corner of the edges
color - the color of the edges. This color must be passed using Processing's color() function

setEdges

public void setEdges(processing.core.PApplet applet,
                     int color)
Add edges of given applet's dimensions to the world. This will create the bodies for left, right, bottom and top.

Parameters:
applet - applet from where to get the dimensions for the edges
color - the color of the edges. This color must be passed using Processing's color() function

setEdges

public void setEdges(int color)
Add edges of Processing's canvas dimensions to the world. This will create the bodies for left, right, bottom and top.

Parameters:
color - the color of the edges. This color must be passed using Processing's color() function

setEdges

public void setEdges()
Add black edges of Processing's canvas dimensions to the world. This will create the bodies for left, right, bottom and top.


setEdgesFriction

public void setEdgesFriction(float friction)
Set the friction of all the edges.

Parameters:
friction - the friction of the edges

setEdgesRestitution

public void setEdgesRestitution(float restitution)
Set the restitution of all the edges.

Parameters:
restitution - the restitution of the edges

setGravity

public void setGravity(float gx,
                       float gy)
Set the gravity of the world. Use world.setGravity(0,0); to have a world without gravity.

Parameters:
gx - the horizontal component of the gravity
gy - the vertical component of the gravity

step

public void step()
Advance the world simulation of 1/60th of a second.


step

public void step(float dt)
Advance the world simulation of given time.

Parameters:
dt - the time to advance the world simulation

step

public void step(float dt,
                 int iterationCount)
Advance the world simulation of given time, with a given number of iterations. The larger the number of iterations, the more computationally expensive and precise it will be. The default is 10 iterations.

Overrides:
step in class org.jbox2d.dynamics.World
Parameters:
dt - the time to advance the world simulation
iterationCount - the number of iterations for the world simulation step

getBody

public FBody getBody(float x,
                     float y)
Returns the first object found at the given position.

Parameters:
x - the horizontal component of the position
y - the vertical component of the position
Returns:
the body found at the given position

getBody

public FBody getBody(float x,
                     float y,
                     boolean getStatic)
Returns the first object found at the given position.

Parameters:
x - the horizontal component of the position
y - the vertical component of the position
getStatic - if true it will also get static objects that can be found at that position
Returns:
the body found at the given position

getBodies

public java.util.ArrayList getBodies()
Returns a list with all the bodies in the world

Returns:
an ArrayList (of FBody) of the bodies in the world

getBodies

public java.util.ArrayList getBodies(float x,
                                     float y)
Returns a list with the 10 first bodies found at the given position.

Parameters:
x - the horizontal component of the position
y - the vertical component of the position
Returns:
an ArrayList (of FBody) of the 10 first bodies found at the given position

getBodies

public java.util.ArrayList getBodies(float x,
                                     float y,
                                     boolean getStatic)
Returns a list with the 10 first bodies found at the given position.

Parameters:
x - the horizontal component of the position
y - the vertical component of the position
getStatic - if true it will also get static objects that can be found at that position
Returns:
an ArrayList (of FBody) of the 10 first bodies found at the given position

getBodies

public java.util.ArrayList getBodies(float x,
                                     float y,
                                     boolean getStatic,
                                     int count)
Returns a list with all the bodies found at the given position.

Parameters:
x - the horizontal component of the position
y - the vertical component of the position
getStatic - if true it will also get static objects that can be found at that position
count - the maximum number of bodies to be retrieved
Returns:
an ArrayList (of FBody) of all bodies found at the given position

raycast

public int raycast(float x1,
                   float y1,
                   float x2,
                   float y2,
                   FBody[] bodies,
                   int maxCount,
                   boolean solidShapes)

raycastOne

public FBody raycastOne(float x1,
                        float y1,
                        float x2,
                        float y2,
                        FRaycastResult result,
                        boolean solidShapes)


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