|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jbox2d.dynamics.World
fisica.FWorld
public class FWorld
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();
}
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 |
---|
public FBox left
setEdges()
.
left
,
right
,
bottom
,
top
public FBox right
setEdges()
.
left
,
right
,
bottom
,
top
public FBox top
setEdges()
.
left
,
right
,
bottom
,
top
public FBox bottom
setEdges()
.
left
,
right
,
bottom
,
top
Constructor Detail |
---|
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 worldFBody
public FWorld()
Method Detail |
---|
public void addBody(FBody body)
public void removeBody(FBody body)
public void addJoint(FJoint joint)
public void removeJoint(FJoint joint)
public void grabBody(float x, float y)
public void dragBody(float x, float y)
public void releaseBody()
public void mouseEvent(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 mouseFBody
public void processActions()
public void draw(processing.core.PApplet applet)
applet
- applet to which to draw the world. Useful when trying to draw the world on other Processing backends, such as PDFFBody
public void draw(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 createGraphicsFBody
public void drawDebug(processing.core.PApplet applet)
applet
- applet to which to draw the world. Useful when trying to draw the world on other Processing backends, such as PDFFBody
public void drawDebug(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 createGraphicsFBody
public void draw()
FBody
public void drawDebug()
FBody
public 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(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()
left
, right
, bottom
and top
.
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 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.World
dt
- 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 position
public 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 position
public java.util.ArrayList getBodies()
public java.util.ArrayList getBodies(float x, float y)
x
- the horizontal component of the positiony
- the vertical component of the position
public java.util.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 position
public java.util.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 retrieved
public int raycast(float x1, float y1, float x2, float y2, FBody[] bodies, int maxCount, boolean solidShapes)
public FBody raycastOne(float x1, float y1, float x2, float y2, FRaycastResult result, boolean solidShapes)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |