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.
Classes | Public Member Functions | Public Attributes | Protected Attributes | List of all members
FWorld Class Reference
Inheritance diagram for FWorld:

Classes

class  ConcreteContactListener
 

Public Member Functions

void addBody (FBody body)
 
void removeBody (FBody body)
 
void addJoint (FJoint joint)
 
void removeJoint (FJoint joint)
 
void setContactListener (final FContactListener listener)
 
void grabBody (float x, float y)
 
void dragBody (float x, float y)
 
void releaseBody ()
 
void mouseEvent (MouseEvent event)
 
 FWorld (float topLeftX, float topLeftY, float bottomRightX, float bottomRightY)
 
FMouseJoint getMouseJoint ()
 
void setGrabbable (boolean value)
 
void processActions ()
 
void draw (PApplet applet)
 
void draw (PGraphics graphics)
 
void drawDebug (PApplet applet)
 
void drawDebug (PGraphics graphics)
 
void draw ()
 
void drawDebug ()
 
void add (FBody body)
 
void remove (FBody body)
 
void add (FJoint joint)
 
void remove (FJoint joint)
 
void clear ()
 
void setEdges (float topLeftX, float topLeftY, float bottomRightX, float bottomRightY, int color)
 
void setEdges (float topLeftX, float topLeftY, float bottomRightX, float bottomRightY)
 
void setEdges (PApplet applet, int color)
 
void setEdges (int color)
 
void setEdges ()
 
void setEdgesFriction (float friction)
 
void setEdgesRestitution (float restitution)
 
void setGravity (float gx, float gy)
 
void step ()
 
void step (float dt)
 
void step (float dt, int iterationCount)
 
FBody getBody (float x, float y)
 
FBody getBody (float x, float y, boolean getStatic)
 
ArrayList getBodies ()
 
ArrayList getBodies (float x, float y)
 
ArrayList getBodies (float x, float y, boolean getStatic)
 
ArrayList getBodies (float x, float y, boolean getStatic, int count)
 
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)
 

Public Attributes

FBox left
 
FBox right
 
FBox top
 
FBox bottom
 

Protected Attributes

float m_topLeftX
 
float m_topLeftY
 
float m_bottomRightX
 
float m_bottomRightY
 
float m_edgesFriction = 0.1f
 
float m_edgesRestitution = 0.1f
 
boolean m_grabbable = true
 
float m_grabPositionX = 0.0f
 
float m_grabPositionY = 0.0f
 
int m_mouseButton = PConstants.LEFT
 
HashMap m_contacts
 
ArrayList m_contactResults
 
LinkedList m_actions
 
ArrayList m_fbodies = new ArrayList()
 
FMouseJoint m_mouseJoint = new FMouseJoint((FBody)null, 0.0f, 0.0f)
 

Detailed Description

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() {
world = new FWorld();
world.setEdges();
// Create and add bodies to the world here
// ...
}
void draw() {
world.step();
world.draw();
}

World

See also
FBody

Constructor & Destructor Documentation

◆ FWorld()

FWorld.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);
world = new FWorld(-width, -height, 2*width, 2*height);
}

World

Parameters
topLeftXthe horizontal coordinate of the top left corner of the world
topLeftYthe vertical coordinate of the top left corner of the world
bottomRightXthe horizontal coordinate of the bottom right corner of the world
bottomRightYthe vertical coordinate of the bottom right corner of the world
See also
FBody

Member Function Documentation

◆ add() [1/2]

void FWorld.add ( FBody  body)

Add a body to the world.

Parameters
bodybody to be added to the world
See also
remove(FBody)

◆ add() [2/2]

void FWorld.add ( FJoint  joint)

Add a joint to the world.

Parameters
jointjoint to be added to the world
See also
remove(FJoint)

◆ clear()

void FWorld.clear ( )

Clear all bodies and joints from the world. NOT IMPLEMENTED YET.

◆ draw() [1/3]

void FWorld.draw ( PApplet  applet)

Draws all the bodies in the world. This method is often called in the draw method of the applet.

Parameters
appletapplet to which to draw the world. Useful when trying to draw the world on other Processing backends, such as PDF
See also
FBody

◆ draw() [2/3]

void FWorld.draw ( PGraphics  graphics)

Draws all the bodies in the world. This method is often called in the draw method of the applet.

Parameters
graphicsgraphics 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() [3/3]

void FWorld.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() [1/3]

void FWorld.drawDebug ( 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
appletapplet to which to draw the world. Useful when trying to draw the world on other Processing backends, such as PDF
See also
FBody

◆ drawDebug() [2/3]

void FWorld.drawDebug ( 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
graphicsgraphics 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() [3/3]

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

◆ getBodies() [1/4]

ArrayList FWorld.getBodies ( )

Returns a list with all the bodies in the world

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

◆ getBodies() [2/4]

ArrayList FWorld.getBodies ( float  x,
float  y 
)

Returns a list with the 10 first bodies found at the given position.

Parameters
xthe horizontal component of the position
ythe vertical component of the position
Returns
an ArrayList (of FBody) of the 10 first bodies found at the given position

◆ getBodies() [3/4]

ArrayList FWorld.getBodies ( float  x,
float  y,
boolean  getStatic 
)

Returns a list with the 10 first bodies found at the given position.

Parameters
xthe horizontal component of the position
ythe vertical component of the position
getStaticif
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() [4/4]

ArrayList FWorld.getBodies ( float  x,
float  y,
boolean  getStatic,
int  count 
)

Returns a list with all the bodies found at the given position.

Parameters
xthe horizontal component of the position
ythe vertical component of the position
getStaticif
true
it will also get static objects that can be found at that position
countthe maximum number of bodies to be retrieved
Returns
an ArrayList (of FBody) of all bodies found at the given position

◆ getBody() [1/2]

FBody FWorld.getBody ( float  x,
float  y 
)

Returns the first object found at the given position.

Parameters
xthe horizontal component of the position
ythe vertical component of the position
Returns
the body found at the given position

◆ getBody() [2/2]

FBody FWorld.getBody ( float  x,
float  y,
boolean  getStatic 
)

Returns the first object found at the given position.

Parameters
xthe horizontal component of the position
ythe vertical component of the position
getStaticif
true
it will also get static objects that can be found at that position
Returns
the body found at the given position

◆ getMouseJoint()

FMouseJoint FWorld.getMouseJoint ( )

Returns the mouse joint that is used for interaction with the bodies in the world.

Returns
the mouse joint used for grabbing bodies

◆ mouseEvent()

void FWorld.mouseEvent ( MouseEvent  event)

This is an internal method to handle mouse interaction and should not be used.

◆ remove() [1/2]

void FWorld.remove ( FBody  body)

Remove a body from the world.

Parameters
bodybody to be removed from the world
See also
add(FBody)

◆ remove() [2/2]

void FWorld.remove ( FJoint  joint)

Remove a joint from the world.

Parameters
jointjoint to be removed from the world
See also
add(FJoint)

◆ setEdges() [1/5]

void FWorld.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
topLeftXthe horizontal coordinate of the top left corner of the edges
topLeftYthe vertical coordinate of the top left corner of the edges
bottomRightXthe horizontal coordinate of the bottom right corner of the edges
bottomRightYthe vertical coordinate of the bottom right corner of the edges
colorthe color of the edges. This color must be passed using Processing's color() function

◆ setEdges() [2/5]

void FWorld.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
topLeftXthe horizontal coordinate of the top left corner of the edges
topLeftYthe vertical coordinate of the top left corner of the edges
bottomRightXthe horizontal coordinate of the bottom right corner of the edges
bottomRightYthe vertical coordinate of the bottom right corner of the edges
colorthe color of the edges. This color must be passed using Processing's color() function

◆ setEdges() [3/5]

void FWorld.setEdges ( 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
appletapplet from where to get the dimensions for the edges
colorthe color of the edges. This color must be passed using Processing's color() function

◆ setEdges() [4/5]

void FWorld.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
colorthe color of the edges. This color must be passed using Processing's color() function

◆ setEdges() [5/5]

void FWorld.setEdges ( )

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

◆ setEdgesFriction()

void FWorld.setEdgesFriction ( float  friction)

Set the friction of all the edges.

Parameters
frictionthe friction of the edges

◆ setEdgesRestitution()

void FWorld.setEdgesRestitution ( float  restitution)

Set the restitution of all the edges.

Parameters
restitutionthe restitution of the edges

◆ setGrabbable()

void FWorld.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);

World

Parameters
valueif true the bodies that live in this world can be grabbed and dragged using the mouse
See also
FBody

◆ setGravity()

void FWorld.setGravity ( float  gx,
float  gy 
)

Set the gravity of the world. Use

world.setGravity(0,0);

to have a world without gravity.

Parameters
gxthe horizontal component of the gravity
gythe vertical component of the gravity

◆ step() [1/3]

void FWorld.step ( )

Advance the world simulation of 1/60th of a second.

◆ step() [2/3]

void FWorld.step ( float  dt)

Advance the world simulation of given time.

Parameters
dtthe time to advance the world simulation

◆ step() [3/3]

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

Parameters
dtthe time to advance the world simulation
iterationCountthe number of iterations for the world simulation step

Member Data Documentation

◆ bottom

FBox FWorld.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

◆ left

FBox FWorld.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

FBox FWorld.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

FBox FWorld.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

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