Package org.jbox2d.testbed.framework
Class TestbedTest
- java.lang.Object
-
- org.jbox2d.testbed.framework.TestbedTest
-
- All Implemented Interfaces:
ContactListener,JbDeserializer.ObjectListener,JbSerializer.ObjectSigner,UnsupportedListener
- Direct Known Subclasses:
ApplyForce,BlobTest4,BodyTypes,Breakable,Cantilever,Car,Chain,CharacterCollision,CircleStress,CollisionFiltering,CollisionProcessing,CompoundShapes,ConfinedTest,ContinuousTest,ConvexHull,ConveyorBelt,DistanceTest,DominoTest,DominoTower,DynamicTreeTest,EdgeShapes,FixedPendulumTest,FreePendulumTest,Gears,LiquidTest,OneSidedTest,PistonTest,PolyShapes,PrismaticTest,Pulleys,PyramidTest,RayCastTest,RevoluteTest,RopeTest,SensorTest,ShapeEditing,SliderCrankTest,SphereStack,TheoJansen,Tumbler,VaryingFrictionTest,VaryingRestitution,VerticalStack,Web
public abstract class TestbedTest extends java.lang.Object implements ContactListener, JbDeserializer.ObjectListener, JbSerializer.ObjectSigner, UnsupportedListener
-
-
Field Summary
Fields Modifier and Type Field Description private AABBaabbprivate Bodybombprotected static longBOMB_TAGprivate booleanbombSpawningprivate Vec2bombSpawnPointprivate Vec2cachedCameraPosprivate floatcachedCameraScaleprivate TestQueryCallbackcallbackprivate Color3fcolor1private Color3fcolor2private Color3fcolor3private Color3fcolor4private Color3fcolor5private JbDeserializerdeserializerprotected DestructionListenerdestructionListenerprivate booleandialogOnSaveLoadErrorsprotected static longGROUND_BODY_TAGprotected BodygroundBodyprivate booleanhasCachedCameraprivate java.util.LinkedList<QueueItem>inputQueueprivate booleanloadPendingprivate static org.slf4j.Loggerlogprotected intm_textLineprotected Worldm_worldOnly visible for compatibility.static intMAX_CONTACT_POINTSprivate TestbedModelmodelprotected static longMOUSE_JOINT_TAGprivate Color3fmouseColorprivate MouseJointmouseJointprivate Vec2mouseWorldprivate Vec2pprivate Vec2p1private Vec2p2private intpointCountstatic ContactPoint[]pointsprivate AABBqueryAABBprivate booleanresetPendingprivate booleansavePendingprivate JbSerializerserializerprivate Collision.PointState[]state1private Collision.PointState[]state2private java.util.List<java.lang.String>statsListprivate intstepCountprivate Vec2tangentprivate java.util.LinkedList<java.lang.String>textListprivate java.lang.Stringtitleprivate Vec2vprivate Vec2velprivate WorldManifoldworldManifold
-
Constructor Summary
Constructors Constructor Description TestbedTest()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void_load()protected void_reset()protected void_save()voidaddTextLine(java.lang.String argTextLine)Adds a text line to the reporting areavoidbeginContact(Contact contact)Called when two fixtures begin to touch.voidcompleteBombSpawn(Vec2 p)voidendContact(Contact contact)Called when two fixtures cease to touch.voidexit()called when the tests exitsBodygetBomb()Gets the 'bomb' body if it's presentVec2getCachedCameraPos()floatgetCachedCameraScale()static ContactPoint[]getContactPoints()Gets the contact points for the current testDebugDrawgetDebugDraw()Gets the debug draw for the testbedVec2getDefaultCameraPos()Override for a different default camera posfloatgetDefaultCameraScale()Override for a different default camera scalejava.lang.StringgetFilename()Gets the filename of the current test.BodygetGroundBody()Gets the ground body of the world, used for some jointsTestbedModelgetModel()Gets the testbed modelintgetPointCount()The number of contact points we're storingintgetStepCount()java.lang.LonggetTag(Shape shape)java.lang.LonggetTag(Body body)java.lang.LonggetTag(Fixture fixture)java.lang.LonggetTag(Joint joint)java.lang.LonggetTag(World world)abstract java.lang.StringgetTestName()The name of the testWorldgetWorld()Gets the current worldVec2getWorldMouse()Gets the world position of the mousevoidinit(World argWorld, boolean argDeserialized)voidinit(TestbedModel argModel)abstract voidinitTest(boolean deserialized)Initializes the current testbooleanisDialogOnSaveLoadErrors()booleanisHasCachedCamera()booleanisSaveLoadEnabled()Override to enable saving and loading.booleanisUnsupported(UnsupportedObjectException exception)Called when an object is unsupported by the de/serializer.voidjointDestroyed(Joint joint)voidkeyPressed(char keyCar, int keyCode)voidkeyReleased(char keyChar, int keyCode)voidlanchBomb()voidlaunchBomb(Vec2 position, Vec2 velocity)voidload()Loads the test from filevoidmouseDown(Vec2 p)Called for mouse-downvoidmouseMove(Vec2 p)Called when mouse is movedvoidmouseUp(Vec2 p)Called for mouse-upvoidpostSolve(Contact contact, ContactImpulse impulse)This lets you inspect a contact after the solver is finished.voidpreSolve(Contact contact, Manifold oldManifold)This is called after a contact is updated.voidprocessBody(Body body, java.lang.Long tag)voidprocessFixture(Fixture fixture, java.lang.Long tag)voidprocessJoint(Joint joint, java.lang.Long tag)voidprocessShape(Shape shape, java.lang.Long tag)voidprocessWorld(World world, java.lang.Long tag)voidqueueKeyPressed(char c, int code)voidqueueKeyReleased(char c, int code)voidqueueMouseDown(Vec2 p)voidqueueMouseMove(Vec2 p)voidqueueMouseUp(Vec2 p)voidqueueShiftMouseDown(Vec2 p)voidreset()Resets the testvoidsave()Saves the testvoidsetCachedCameraPos(Vec2 argPos)voidsetCachedCameraScale(float cachedCameraScale)voidsetCamera(Vec2 argPos)voidsetCamera(Vec2 argPos, float scale)Sets the current testbed cameravoidsetDialogOnSaveLoadErrors(boolean dialogOnSaveLoadErrors)voidsetHasCachedCamera(boolean hasCachedCamera)voidsetTitle(java.lang.String argTitle)Sets the title of the testvoidshiftMouseDown(Vec2 p)Called when shift-mouse down occursvoidspawnBomb(Vec2 worldPt)voidstep(TestbedSettings settings)voidupdate()
-
-
-
Field Detail
-
MAX_CONTACT_POINTS
public static final int MAX_CONTACT_POINTS
- See Also:
- Constant Field Values
-
GROUND_BODY_TAG
protected static final long GROUND_BODY_TAG
- See Also:
- Constant Field Values
-
BOMB_TAG
protected static final long BOMB_TAG
- See Also:
- Constant Field Values
-
MOUSE_JOINT_TAG
protected static final long MOUSE_JOINT_TAG
- See Also:
- Constant Field Values
-
log
private static final org.slf4j.Logger log
-
points
public static final ContactPoint[] points
-
m_world
protected World m_world
Only visible for compatibility. Should usegetWorld()instead.
-
groundBody
protected Body groundBody
-
mouseJoint
private MouseJoint mouseJoint
-
bomb
private Body bomb
-
bombSpawnPoint
private final Vec2 bombSpawnPoint
-
bombSpawning
private boolean bombSpawning
-
mouseWorld
private final Vec2 mouseWorld
-
pointCount
private int pointCount
-
stepCount
private int stepCount
-
model
private TestbedModel model
-
destructionListener
protected DestructionListener destructionListener
-
inputQueue
private final java.util.LinkedList<QueueItem> inputQueue
-
title
private java.lang.String title
-
m_textLine
protected int m_textLine
-
textList
private final java.util.LinkedList<java.lang.String> textList
-
cachedCameraScale
private float cachedCameraScale
-
cachedCameraPos
private final Vec2 cachedCameraPos
-
hasCachedCamera
private boolean hasCachedCamera
-
serializer
private JbSerializer serializer
-
deserializer
private JbDeserializer deserializer
-
dialogOnSaveLoadErrors
private boolean dialogOnSaveLoadErrors
-
savePending
private boolean savePending
-
loadPending
private boolean loadPending
-
resetPending
private boolean resetPending
-
color1
private final Color3f color1
-
color2
private final Color3f color2
-
color3
private final Color3f color3
-
color4
private final Color3f color4
-
color5
private final Color3f color5
-
mouseColor
private final Color3f mouseColor
-
p1
private final Vec2 p1
-
p2
private final Vec2 p2
-
tangent
private final Vec2 tangent
-
statsList
private final java.util.List<java.lang.String> statsList
-
queryAABB
private final AABB queryAABB
-
callback
private final TestQueryCallback callback
-
p
private final Vec2 p
-
v
private final Vec2 v
-
aabb
private final AABB aabb
-
vel
private final Vec2 vel
-
state1
private final Collision.PointState[] state1
-
state2
private final Collision.PointState[] state2
-
worldManifold
private final WorldManifold worldManifold
-
-
Method Detail
-
init
public void init(TestbedModel argModel)
-
init
public void init(World argWorld, boolean argDeserialized)
-
getWorld
public World getWorld()
Gets the current world- Returns:
-
getModel
public TestbedModel getModel()
Gets the testbed model- Returns:
-
getContactPoints
public static ContactPoint[] getContactPoints()
Gets the contact points for the current test- Returns:
-
getGroundBody
public Body getGroundBody()
Gets the ground body of the world, used for some joints- Returns:
-
getDebugDraw
public DebugDraw getDebugDraw()
Gets the debug draw for the testbed- Returns:
-
getWorldMouse
public Vec2 getWorldMouse()
Gets the world position of the mouse- Returns:
-
getStepCount
public int getStepCount()
-
getPointCount
public int getPointCount()
The number of contact points we're storing- Returns:
-
getBomb
public Body getBomb()
Gets the 'bomb' body if it's present- Returns:
-
getCachedCameraScale
public float getCachedCameraScale()
-
setCachedCameraScale
public void setCachedCameraScale(float cachedCameraScale)
-
getCachedCameraPos
public Vec2 getCachedCameraPos()
-
setCachedCameraPos
public void setCachedCameraPos(Vec2 argPos)
-
isHasCachedCamera
public boolean isHasCachedCamera()
-
setHasCachedCamera
public void setHasCachedCamera(boolean hasCachedCamera)
-
isDialogOnSaveLoadErrors
public boolean isDialogOnSaveLoadErrors()
-
setDialogOnSaveLoadErrors
public void setDialogOnSaveLoadErrors(boolean dialogOnSaveLoadErrors)
-
getDefaultCameraPos
public Vec2 getDefaultCameraPos()
Override for a different default camera pos- Returns:
-
getDefaultCameraScale
public float getDefaultCameraScale()
Override for a different default camera scale- Returns:
-
getFilename
public java.lang.String getFilename()
Gets the filename of the current test. Default implementation uses the test name with no spaces".- Returns:
-
reset
public void reset()
Resets the test
-
save
public void save()
Saves the test
-
load
public void load()
Loads the test from file
-
_reset
protected void _reset()
-
_save
protected void _save()
-
_load
protected void _load()
-
setCamera
public void setCamera(Vec2 argPos)
-
setCamera
public void setCamera(Vec2 argPos, float scale)
Sets the current testbed camera- Parameters:
argPos-scale-
-
initTest
public abstract void initTest(boolean deserialized)
Initializes the current test- Parameters:
argDeserialized- if the test was deserialized from a file. If so, all physics objects were already added.
-
getTestName
public abstract java.lang.String getTestName()
The name of the test- Returns:
-
exit
public void exit()
called when the tests exits
-
update
public void update()
-
step
public void step(TestbedSettings settings)
-
queueShiftMouseDown
public void queueShiftMouseDown(Vec2 p)
-
queueMouseUp
public void queueMouseUp(Vec2 p)
-
queueMouseDown
public void queueMouseDown(Vec2 p)
-
queueMouseMove
public void queueMouseMove(Vec2 p)
-
queueKeyPressed
public void queueKeyPressed(char c, int code)
-
queueKeyReleased
public void queueKeyReleased(char c, int code)
-
shiftMouseDown
public void shiftMouseDown(Vec2 p)
Called when shift-mouse down occurs- Parameters:
p-
-
mouseUp
public void mouseUp(Vec2 p)
Called for mouse-up- Parameters:
p-
-
mouseDown
public void mouseDown(Vec2 p)
Called for mouse-down- Parameters:
p-
-
mouseMove
public void mouseMove(Vec2 p)
Called when mouse is moved- Parameters:
p-
-
setTitle
public void setTitle(java.lang.String argTitle)
Sets the title of the test- Parameters:
argTitle-
-
addTextLine
public void addTextLine(java.lang.String argTextLine)
Adds a text line to the reporting area- Parameters:
argTextLine-
-
lanchBomb
public void lanchBomb()
-
spawnBomb
public void spawnBomb(Vec2 worldPt)
-
completeBombSpawn
public void completeBombSpawn(Vec2 p)
-
isSaveLoadEnabled
public boolean isSaveLoadEnabled()
Override to enable saving and loading. Remember to also override theJbDeserializer.ObjectListenerandJbSerializer.ObjectSignermethods if you need to- Returns:
-
getTag
public java.lang.Long getTag(Body body)
- Specified by:
getTagin interfaceJbSerializer.ObjectSigner- Returns:
- the tag for the body. can be null.
-
getTag
public java.lang.Long getTag(Fixture fixture)
- Specified by:
getTagin interfaceJbSerializer.ObjectSigner- Returns:
- the tag for the fixture. can be null.
-
getTag
public java.lang.Long getTag(Joint joint)
- Specified by:
getTagin interfaceJbSerializer.ObjectSigner- Returns:
- the tag for the joint. can be null.
-
getTag
public java.lang.Long getTag(Shape shape)
- Specified by:
getTagin interfaceJbSerializer.ObjectSigner- Returns:
- the tag for the shape. can be null.
-
getTag
public java.lang.Long getTag(World world)
- Specified by:
getTagin interfaceJbSerializer.ObjectSigner- Returns:
- the tag for the world. can be null.
-
processBody
public void processBody(Body body, java.lang.Long tag)
- Specified by:
processBodyin interfaceJbDeserializer.ObjectListener
-
processFixture
public void processFixture(Fixture fixture, java.lang.Long tag)
- Specified by:
processFixturein interfaceJbDeserializer.ObjectListener
-
processJoint
public void processJoint(Joint joint, java.lang.Long tag)
- Specified by:
processJointin interfaceJbDeserializer.ObjectListener
-
processShape
public void processShape(Shape shape, java.lang.Long tag)
- Specified by:
processShapein interfaceJbDeserializer.ObjectListener
-
processWorld
public void processWorld(World world, java.lang.Long tag)
- Specified by:
processWorldin interfaceJbDeserializer.ObjectListener
-
isUnsupported
public boolean isUnsupported(UnsupportedObjectException exception)
Description copied from interface:UnsupportedListenerCalled when an object is unsupported by the de/serializer.- Specified by:
isUnsupportedin interfaceUnsupportedListener- Parameters:
exception- the exception describing the error- Returns:
- if the process should stop and the exception be thrown
-
jointDestroyed
public void jointDestroyed(Joint joint)
-
beginContact
public void beginContact(Contact contact)
Description copied from interface:ContactListenerCalled when two fixtures begin to touch.- Specified by:
beginContactin interfaceContactListener
-
endContact
public void endContact(Contact contact)
Description copied from interface:ContactListenerCalled when two fixtures cease to touch.- Specified by:
endContactin interfaceContactListener
-
postSolve
public void postSolve(Contact contact, ContactImpulse impulse)
Description copied from interface:ContactListenerThis lets you inspect a contact after the solver is finished. This is useful for inspecting impulses. Note: the contact manifold does not include time of impact impulses, which can be arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly in a separate data structure. Note: this is only called for contacts that are touching, solid, and awake.- Specified by:
postSolvein interfaceContactListenerimpulse- this is usually a pooled variable, so it will be modified after this call
-
preSolve
public void preSolve(Contact contact, Manifold oldManifold)
Description copied from interface:ContactListenerThis is called after a contact is updated. This allows you to inspect a contact before it goes to the solver. If you are careful, you can modify the contact manifold (e.g. disable contact). A copy of the old manifold is provided so that you can detect changes. Note: this is called only for awake bodies. Note: this is called even when the number of contact points is zero. Note: this is not called for sensors. Note: if you set the number of contact points to zero, you will not get an EndContact callback. However, you may get a BeginContact callback the next step. Note: the oldManifold parameter is pooled, so it will be the same object for every callback for each thread.- Specified by:
preSolvein interfaceContactListener
-
keyPressed
public void keyPressed(char keyCar, int keyCode)
-
keyReleased
public void keyReleased(char keyChar, int keyCode)
-
-