org.jbox2d.testbed.tests
Class ShapeDrawing

java.lang.Object
  extended by org.jbox2d.testbed.AbstractExample
      extended by org.jbox2d.testbed.tests.ShapeDrawing

public class ShapeDrawing
extends AbstractExample

An example of Crayon Physics-style shape creation. This is a simple method of allowing user input to guide shape creation. Rather than trying to decompose the user-created polygon into a shape usable by JBox2d, we create each segment of the stroke as an individual shape, and finalize the shape when the "crayon" is lifted.

This method is inefficient, and each segment of stroke must be fairly large to avoid angering the engine, but it is very robust against weird user input, which makes it much easier to implement.


Field Summary
 
Fields inherited from class org.jbox2d.testbed.AbstractExample
black, blue, bombSpawning, bombSpawnPoint, boundImages, cachedCamScale, cachedCamX, cachedCamY, gray, green, hasCachedCamera, instructionString, keyDown, m_bomb, m_boundaryListener, m_contactListener, m_debugDraw, m_destructionListener, m_mouseJoint, m_pointCount, m_points, m_textLine, m_world, m_worldAABB, memFree, mouseScreen, mouseWorld, needsReset, newKeyDown, parent, pmousePressed, pmouseScreen, red, settings, textLineHeight, white
 
Constructor Summary
ShapeDrawing(TestbedMain _parent)
           
 
Method Summary
 void addStrokeSegment()
           
 void beginMouseStroke()
           
 void create()
          Create the world geometry for each test.
 void createStrokeRect(Vec2 start, Vec2 end, float radius, Body body, PolygonDef sd)
           
 void finalizeStroke()
           
 java.lang.String getExampleInstructions()
          Returns a string containing example instructions.
 java.lang.String getName()
           
 void mouseDown(Vec2 p)
          Handle mouseDown events.
 void mouseMove(Vec2 p)
          Handle mouseMove events (TestbedMain also sends mouseDragged events here)
 void mouseUp()
          Handle mouseUp events.
 void preStep()
          Stub for overloading in examples - called before physics step.
 
Methods inherited from class org.jbox2d.testbed.AbstractExample
bindImage, boundaryViolated, completeBombSpawn, createWorld, initialize, jointDestroyed, keyPressed, keyReleased, launchBomb, launchBomb, postStep, printInstructions, setCamera, spawnBomb, step
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeDrawing

public ShapeDrawing(TestbedMain _parent)
Method Detail

create

public void create()
Description copied from class: AbstractExample
Create the world geometry for each test. Any custom initialization for a test should go here. Called immediately after initialize(), which handles generic test initialization and should usually not be overloaded.

Specified by:
create in class AbstractExample

preStep

public void preStep()
Description copied from class: AbstractExample
Stub for overloading in examples - called before physics step.

Overrides:
preStep in class AbstractExample

beginMouseStroke

public void beginMouseStroke()

addStrokeSegment

public void addStrokeSegment()

finalizeStroke

public void finalizeStroke()

createStrokeRect

public void createStrokeRect(Vec2 start,
                             Vec2 end,
                             float radius,
                             Body body,
                             PolygonDef sd)

mouseDown

public void mouseDown(Vec2 p)
Description copied from class: AbstractExample
Handle mouseDown events.

Overrides:
mouseDown in class AbstractExample
Parameters:
p - The screen location that the mouse is down at.

mouseUp

public void mouseUp()
Description copied from class: AbstractExample
Handle mouseUp events.

Overrides:
mouseUp in class AbstractExample

mouseMove

public void mouseMove(Vec2 p)
Description copied from class: AbstractExample
Handle mouseMove events (TestbedMain also sends mouseDragged events here)

Overrides:
mouseMove in class AbstractExample
Parameters:
p - The new mouse location (screen coordinates)

getName

public java.lang.String getName()
Specified by:
getName in class AbstractExample
Returns:
Title of example.

getExampleInstructions

public java.lang.String getExampleInstructions()
Description copied from class: AbstractExample
Returns a string containing example instructions. Overload within an example to provide special instructions or information.

Overrides:
getExampleInstructions in class AbstractExample
Returns:
A string containing example instructions