public class FWorld
extends org.jbox2d.dynamics.World
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();
}
FBody| Modifier and Type | Field and Description |
|---|---|
FBox |
bottom
The bottom edge of the world.
|
FBox |
left
The left edge of the world.
|
protected LinkedList |
m_actions |
protected float |
m_bottomRightX |
protected float |
m_bottomRightY |
protected ArrayList |
m_contactResults |
protected HashMap |
m_contacts |
protected float |
m_edgesFriction |
protected float |
m_edgesRestitution |
protected ArrayList |
m_fbodies |
protected boolean |
m_grabbable |
protected float |
m_grabPositionX |
protected float |
m_grabPositionY |
protected int |
m_mouseButton |
protected FMouseJoint |
m_mouseJoint |
protected float |
m_topLeftX |
protected float |
m_topLeftY |
FBox |
right
The right edge of the world.
|
FBox |
top
The top edge of the world.
|
| Constructor and Description |
|---|
FWorld() |
FWorld(float topLeftX,
float topLeftY,
float bottomRightX,
float bottomRightY)
Constructs the world where all the bodies live in.
|
| Modifier and Type | Method and Description |
|---|---|
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(def.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(def.processing.core.PGraphics graphics)
Draws the debug version of all the bodies in the world.
|
ArrayList |
getBodies()
Returns a list with all the bodies in the world
|
ArrayList |
getBodies(float x,
float y)
Returns a list with the 10 first bodies found at the given position.
|
ArrayList |
getBodies(float x,
float y,
boolean getStatic)
Returns a list with the 10 first bodies found at the given position.
|
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(def.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) |
int |
raycast(org.jbox2d.collision.Segment segment,
org.jbox2d.collision.shapes.Shape[] shapes,
int maxCount,
boolean solidShapes,
Object userData) |
FBody |
raycastOne(float x1,
float y1,
float x2,
float y2,
FRaycastResult result,
boolean solidShapes) |
org.jbox2d.collision.shapes.Shape |
raycastOne(org.jbox2d.collision.Segment segment,
org.jbox2d.common.RaycastResult result,
boolean solidShapes,
Object userData) |
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 |
setContactListener(org.jbox2d.dynamics.ContactListener listener) |
void |
setContactListener(FContactListener listener) |
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(def.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 |
setGravity(org.jbox2d.common.Vec2 vector) |
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.
|
createBody, createController, createJoint, destroyBody, destroyController, destroyJoint, drawDebugData, drawJoint, drawShape, getBodyCount, getBodyList, getContactCount, getDebugDraw, getGravity, getGroundBody, getJointCount, getJointList, getPairCount, getProxyCount, getWorldAABB, inRange, isAutoDebugDraw, isDrawingDebugData, query, refilter, registerPostStep, setAutoDebugDraw, setBoundaryListener, setContactFilter, setContinuousPhysics, setDebugDraw, setDestructionListener, setDrawDebugData, setPositionCorrection, setWarmStarting, solve, solveTOI, unregisterPostStep, validatepublic FBox left
setEdges().public FBox right
setEdges().public FBox top
setEdges().public FBox bottom
setEdges().protected float m_topLeftX
protected float m_topLeftY
protected float m_bottomRightX
protected float m_bottomRightY
protected float m_edgesFriction
protected float m_edgesRestitution
protected boolean m_grabbable
protected float m_grabPositionX
protected float m_grabPositionY
protected int m_mouseButton
protected HashMap m_contacts
protected ArrayList m_contactResults
protected LinkedList m_actions
protected ArrayList m_fbodies
protected FMouseJoint m_mouseJoint
public FWorld(float topLeftX,
float topLeftY,
float bottomRightX,
float bottomRightY)
FWorld world;
void setup() {
size(200, 200);
Fisica.init(this); world = new FWorld(-width, -height, 2*width, 2*height); }
topLeftX - the horizontal coordinate of the top left corner of the worldtopLeftY - the vertical coordinate of the top left corner of the worldbottomRightX - the horizontal coordinate of the bottom right corner of the worldbottomRightY - the vertical coordinate of the bottom right corner of the worldFBodypublic FWorld()
public void addBody(FBody body)
public void removeBody(FBody body)
public void addJoint(FJoint joint)
public void removeJoint(FJoint joint)
public void setContactListener(FContactListener listener)
public void setContactListener(org.jbox2d.dynamics.ContactListener listener)
setContactListener in class org.jbox2d.dynamics.Worldpublic void grabBody(float x,
float y)
public void dragBody(float x,
float y)
public void releaseBody()
public void mouseEvent(def.processing.event.MouseEvent event)
public FMouseJoint getMouseJoint()
public void setGrabbable(boolean value)
world.setGrabbable(false);
value - if true the bodies that live in this world can be grabbed and
dragged using the mouseFBodypublic void processActions()
public void draw(def.processing.core.PGraphics graphics)
graphics - graphics to which to draw the world. Useful when trying to draw
the world on other buffers, such as when using createGraphicsFBodypublic void drawDebug(def.processing.core.PGraphics graphics)
graphics - graphics to which to draw the world. Useful when trying to draw
the world on other buffers, such as when using createGraphicsFBodypublic void draw()
FBodypublic void drawDebug()
FBodypublic void add(FBody body)
body - body to be added to the worldremove(FBody)public void remove(FBody body)
body - body to be removed from the worldadd(FBody)public void add(FJoint joint)
joint - joint to be added to the worldremove(FJoint)public void remove(FJoint joint)
joint - joint to be removed from the worldadd(FJoint)public void clear()
public void setEdges(float topLeftX,
float topLeftY,
float bottomRightX,
float bottomRightY,
int color)
left, right, bottom and top.topLeftX - the horizontal coordinate of the top left corner of the edgestopLeftY - the vertical coordinate of the top left corner of the edgesbottomRightX - the horizontal coordinate of the bottom right corner of the edgesbottomRightY - the vertical coordinate of the bottom right corner of the edgescolor - the color of the edges. This color must be passed using
Processing's color() functionpublic void setEdges(float topLeftX,
float topLeftY,
float bottomRightX,
float bottomRightY)
left, right, bottom and top.topLeftX - the horizontal coordinate of the top left corner of the edgestopLeftY - the vertical coordinate of the top left corner of the edgesbottomRightX - the horizontal coordinate of the bottom right corner of the edgesbottomRightY - the vertical coordinate of the bottom right corner of the edgescolor - the color of the edges. This color must be passed using
Processing's color() functionpublic void setEdges(def.processing.core.PApplet applet,
int color)
left, right, bottom and top.applet - applet from where to get the dimensions for the edgescolor - the color of the edges. This color must be passed using
Processing's color() functionpublic void setEdges(int color)
left, right, bottom and
top.color - the color of the edges. This color must be passed using
Processing's color() functionpublic void setEdges()
public void setEdgesFriction(float friction)
friction - the friction of the edgespublic void setEdgesRestitution(float restitution)
restitution - the restitution of the edgespublic void setGravity(float gx,
float gy)
world.setGravity(0,0); to have a
world without gravity.gx - the horizontal component of the gravitygy - the vertical component of the gravitypublic void setGravity(org.jbox2d.common.Vec2 vector)
setGravity in class org.jbox2d.dynamics.Worldpublic void step()
public void step(float dt)
dt - the time to advance the world simulationpublic void step(float dt,
int iterationCount)
step in class org.jbox2d.dynamics.Worlddt - the time to advance the world simulationiterationCount - the number of iterations for the world simulation steppublic FBody getBody(float x, float y)
x - the horizontal component of the positiony - the vertical component of the positionpublic FBody getBody(float x, float y, boolean getStatic)
x - the horizontal component of the positiony - the vertical component of the positiongetStatic - if true it will also get static objects that can be found
at that positionpublic ArrayList getBodies()
public ArrayList getBodies(float x, float y)
x - the horizontal component of the positiony - the vertical component of the positionpublic ArrayList getBodies(float x, float y, boolean getStatic)
x - the horizontal component of the positiony - the vertical component of the positiongetStatic - if true it will also get static objects that can be found
at that positionpublic ArrayList getBodies(float x, float y, boolean getStatic, int count)
x - the horizontal component of the positiony - the vertical component of the positiongetStatic - if true it will also get static objects that can be found
at that positioncount - the maximum number of bodies to be retrievedpublic int raycast(float x1,
float y1,
float x2,
float y2,
FBody[] bodies,
int maxCount,
boolean solidShapes)
public int raycast(org.jbox2d.collision.Segment segment,
org.jbox2d.collision.shapes.Shape[] shapes,
int maxCount,
boolean solidShapes,
Object userData)
raycast in class org.jbox2d.dynamics.Worldpublic org.jbox2d.collision.shapes.Shape raycastOne(org.jbox2d.collision.Segment segment,
org.jbox2d.common.RaycastResult result,
boolean solidShapes,
Object userData)
raycastOne in class org.jbox2d.dynamics.Worldpublic FBody raycastOne(float x1, float y1, float x2, float y2, FRaycastResult result, boolean solidShapes)