org.xith3d.physics.simulation
Class SimulationWorld

java.lang.Object
  extended by org.xith3d.physics.simulation.SimulationWorld
All Implemented Interfaces:
org.jagatoo.datatypes.Enableable, Updatable

public abstract class SimulationWorld
extends java.lang.Object
implements Updatable, org.jagatoo.datatypes.Enableable

A simulation world


Field Summary
protected  SimulationEngine engine
           
 
Constructor Summary
SimulationWorld(SimulationEngine engine)
          Creates a new simulation world.
 
Method Summary
 void addBody(Body body)
          Adds a body to the world.
protected abstract  void addBodyImpl(Body body)
          Put impl-specific stuff here.
 void addJoint(Joint joint)
          Adds a joint to the world.
protected abstract  void addJointImpl(Joint joint)
          Put impl-specific stuff here.
protected abstract  void afterStep()
          This method is called after the stepImpl(long) method is called.
protected abstract  void beforeStep()
          This method is called before the stepImpl(long) method is called.
 Body getBody(int i)
          Gets a body from its index.
 SimulationEngine getEngine()
           
 org.openmali.vecmath2.Vector3f getGravity()
           
 Joint getJoint(int i)
          Gets a joint from its index.
 long getMaxStepSize()
           
abstract  java.lang.String getStepperFunction()
           
abstract  java.util.Set<java.lang.String> getStepperFunctions()
           
 long getStepSize()
           
 boolean isEnabled()
           
 boolean isGravityEnabled()
           
 BallJoint newBallJoint(Body body1, Body body2)
          Creates a new BallJoint.
protected abstract  BallJoint newBallJointImpl(Body body1, Body body2)
          Creates a new BallJoint.
 Body newBody()
          Creates a new Body.
protected abstract  Body newBodyImpl()
          Creates a new Body.
 FixedJoint newFixedJoint(Body body1, Body body2)
          Creates a new FixedJoint.
protected abstract  FixedJoint newFixedJointImpl(Body body1, Body body2)
          Creates a new FixedJoint.
 Hinge2Joint newHinge2Joint(Body body1, Body body2)
          Creates a new Hinge2Joint.
protected abstract  Hinge2Joint newHinge2JointImpl(Body body1, Body body2)
          Creates a new Hinge2Joint.
 HingeJoint newHingeJoint(Body body1, Body body2)
          Creates a new HingeJoint.
protected abstract  HingeJoint newHingeJointImpl(Body body1, Body body2)
          Creates a new HingeJoint.
 JointLimitMotor newJointLimitMotor()
           
protected  JointLimitMotor newJointLimitMotor(float defaultCFM, float defaultERP)
           
 SliderJoint newSliderJoint(Body body1, Body body2)
          Creates a new SliderJoint.
protected abstract  SliderJoint newSliderJointImpl(Body body1, Body body2)
          Creates a new SliderJoint.
 int numBodies()
           
 int numJoints()
           
 void removeBody(Body body)
          Removes a body from the world.
protected abstract  void removeBodyImpl(Body body)
          Put impl-specific stuff here.
 void removeJoint(Joint joint)
          Removes a joint from the world.
protected abstract  void removeJointImpl(Joint joint)
          Put impl-specific stuff here
abstract  void resolveCollision(Collision collision, Body body1, Body body2, SurfaceParameters surfParams)
          This method should be called by yourself (yeah, SimulationWorld is listening to you !!)
 void resolveCollision(Collision collision, SurfaceParameters surfParams)
          This method should be called by yourself (yeah, SimulationWorld is listening to you !!)
 void setEnabled(boolean enabled)
          Sets this SimulationWorld enabled/disabled.
 void setGravity(float x, float y, float z)
           
 void setGravity(org.openmali.vecmath2.Vector3f gravity)
           
 void setGravityEnabled(boolean enabled)
          Sets whether gravity is (world-)globally enabled or not.
protected abstract  void setGravityImpl(float x, float y, float z)
          Put impl-specific stuff here.
 void setMaxStepSize(long micros)
          Sets the maximum internal step time in microseconds.
abstract  void setStepperFunction(java.lang.String stepperFunction)
          Sets the stepping function to be used.
 void setStepSize(long micros)
          Sets the constant internal step time in microseconds.
 void step(long stepMicros, CollisionResolversManager collisionResolversManager)
          Step the simulation = advance the time
protected abstract  void stepImpl(long stepMicros)
          Step the simulation = advance the time
 void update(long gameTime, long frameTime, UpdatingThread.TimingMode timingMode)
          Updates this Updatable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

engine

protected SimulationEngine engine
Constructor Detail

SimulationWorld

public SimulationWorld(SimulationEngine engine)
Creates a new simulation world.

Parameters:
engine - the simulation engine we belong to
Method Detail

getEngine

public SimulationEngine getEngine()
Returns:
the SimulationEngine.

setGravityImpl

protected abstract void setGravityImpl(float x,
                                       float y,
                                       float z)
Put impl-specific stuff here.


setGravity

public final void setGravity(float x,
                             float y,
                             float z)
Parameters:
x - the gravity to set
y - the gravity to set
z - the gravity to set

setGravity

public final void setGravity(org.openmali.vecmath2.Vector3f gravity)
Parameters:
gravity - the gravity to set

setGravityEnabled

public void setGravityEnabled(boolean enabled)
Sets whether gravity is (world-)globally enabled or not.

Parameters:
enabled -

isGravityEnabled

public final boolean isGravityEnabled()
Returns:
whether gravity is (world-)globally enabled or not.

getGravity

public final org.openmali.vecmath2.Vector3f getGravity()
Returns:
the gravity

newBodyImpl

protected abstract Body newBodyImpl()
Creates a new Body.

Returns:
the newly created Body.

newBody

public final Body newBody()
Creates a new Body.

Returns:
the newly created Body.

addBodyImpl

protected abstract void addBodyImpl(Body body)
Put impl-specific stuff here.


addBody

public final void addBody(Body body)
Adds a body to the world.

Parameters:
body - the body to be added

removeBodyImpl

protected abstract void removeBodyImpl(Body body)
Put impl-specific stuff here.


removeBody

public final void removeBody(Body body)
Removes a body from the world.

Parameters:
body - the body to be removed

numBodies

public final int numBodies()
Returns:
the number of bodies in the world.

getBody

public final Body getBody(int i)
Gets a body from its index.

Parameters:
i - the index of the body
Returns:
the body

newJointLimitMotor

protected JointLimitMotor newJointLimitMotor(float defaultCFM,
                                             float defaultERP)

newJointLimitMotor

public final JointLimitMotor newJointLimitMotor()

newBallJointImpl

protected abstract BallJoint newBallJointImpl(Body body1,
                                              Body body2)
Creates a new BallJoint.

Parameters:
body1 -
body2 -
Returns:
the newly created BallJoint.

newBallJoint

public final BallJoint newBallJoint(Body body1,
                                    Body body2)
Creates a new BallJoint.

Parameters:
body1 -
body2 -
Returns:
the newly created BallJoint.

newFixedJointImpl

protected abstract FixedJoint newFixedJointImpl(Body body1,
                                                Body body2)
Creates a new FixedJoint.

Parameters:
body1 -
body2 -
Returns:
the newly created FixedJoint.

newFixedJoint

public final FixedJoint newFixedJoint(Body body1,
                                      Body body2)
Creates a new FixedJoint.

Parameters:
body1 -
body2 -
Returns:
the newly created Hinge2Joint.

newHingeJointImpl

protected abstract HingeJoint newHingeJointImpl(Body body1,
                                                Body body2)
Creates a new HingeJoint.

Parameters:
body1 -
body2 -
Returns:
the newly created HingeJoint.

newHingeJoint

public final HingeJoint newHingeJoint(Body body1,
                                      Body body2)
Creates a new HingeJoint.

Parameters:
body1 -
body2 -
Returns:
the newly created HingeJoint.

newHinge2JointImpl

protected abstract Hinge2Joint newHinge2JointImpl(Body body1,
                                                  Body body2)
Creates a new Hinge2Joint.

Parameters:
body1 -
body2 -
Returns:
the newly created Hinge2Joint.

newHinge2Joint

public final Hinge2Joint newHinge2Joint(Body body1,
                                        Body body2)
Creates a new Hinge2Joint.

Parameters:
body1 -
body2 -
Returns:
the newly created Hinge2Joint.

newSliderJointImpl

protected abstract SliderJoint newSliderJointImpl(Body body1,
                                                  Body body2)
Creates a new SliderJoint.

Parameters:
body1 -
body2 -
Returns:
the newly created SliderJoint.

newSliderJoint

public final SliderJoint newSliderJoint(Body body1,
                                        Body body2)
Creates a new SliderJoint.

Parameters:
body1 -
body2 -
Returns:
the newly created SliderJoint.

addJointImpl

protected abstract void addJointImpl(Joint joint)
Put impl-specific stuff here.


addJoint

public final void addJoint(Joint joint)
Adds a joint to the world.

Parameters:
joint - the joint to be added

removeJointImpl

protected abstract void removeJointImpl(Joint joint)
Put impl-specific stuff here


removeJoint

public final void removeJoint(Joint joint)
Removes a joint from the world.

Parameters:
joint - the joint to be removed

numJoints

public final int numJoints()
Returns:
the number of joints in the world

getJoint

public final Joint getJoint(int i)
Gets a joint from its index.

Parameters:
i - the index of the joint
Returns:
the joint

getStepperFunctions

public abstract java.util.Set<java.lang.String> getStepperFunctions()
Returns:
a list of all functions available for stepping this world

setStepperFunction

public abstract void setStepperFunction(java.lang.String stepperFunction)
Sets the stepping function to be used.

Parameters:
stepperFunction - the stepper function, it should be one of the stepper functions proposed by getStepperFunctions() If stepperFunction is not a valid stepping function, the stepping function will not be changed. If stepperFunction is null, the default stepping function will be set.

getStepperFunction

public abstract java.lang.String getStepperFunction()
Returns:
The current stepping function used

setStepSize

public final void setStepSize(long micros)
Sets the constant internal step time in microseconds.

Parameters:
micros -

getStepSize

public final long getStepSize()
Returns:
the constant internal step time in microseconds.

setMaxStepSize

public final void setMaxStepSize(long micros)
Sets the maximum internal step time in microseconds.

Parameters:
micros -

getMaxStepSize

public final long getMaxStepSize()
Returns:
the maximum internal step time in microseconds.

beforeStep

protected abstract void beforeStep()
This method is called before the stepImpl(long) method is called.


afterStep

protected abstract void afterStep()
This method is called after the stepImpl(long) method is called.


stepImpl

protected abstract void stepImpl(long stepMicros)
Step the simulation = advance the time

Parameters:
stepMicros - the size of the step which should be taken. Note that 2 steps of .01f isn't equal to 1 step of .02f : the smaller is your stepSize, the more accurate your simulation (but computations take more time). As always, you should find a tradeoff between speed and accuracy (which is the whole point of physic simulation, anyway). Begin with .01f and adjust it later if you don't know what to put. Note : you could also make the stepSize "adaptative", ie proportional to the (real) time that has passed since the last step, but sometimes adaptive stepSize can cause some simulation problems (jumps, instability). If you have these problems you could also try to advance by the right quantity of time by several fixed size steps.
See Also:
setStepperFunction(String)

step

public final void step(long stepMicros,
                       CollisionResolversManager collisionResolversManager)
Step the simulation = advance the time

Parameters:
stepMicros - the size of the step which should be taken. Note that 2 steps of .01f isn't equal to 1 step of .02f : the smaller is your stepSize, the more accurate your simulation (but computations take more time). As always, you should find a tradeoff between speed and accuracy (which is the whole point of physic simulation, anyway). Begin with .01f and adjust it later if you don't know what to put. Note : you could also make the stepSize "adaptative", ie proportional to the (real) time that has passed since the last step, but sometimes adaptive stepSize can cause some simulation problems (jumps, instability). If you have these problems you could also try to advance by the right quantity of time by several fixed size steps.
See Also:
setStepperFunction(String)

resolveCollision

public abstract void resolveCollision(Collision collision,
                                      Body body1,
                                      Body body2,
                                      SurfaceParameters surfParams)
This method should be called by yourself (yeah, SimulationWorld is listening to you !!) when you want a collision to be resolved by the SimulationWorld, which normally means, that the two bodies won't interpenetrate (well, if the constraint is solvable). You can set one Body to null, it means just one Body needs to be moved (e.g. when a basket ball hits the ground, you want the basket ball to react, not the ground :) ).

Parameters:
collision -
body1 -
body2 -
surfParams -

resolveCollision

public final void resolveCollision(Collision collision,
                                   SurfaceParameters surfParams)
This method should be called by yourself (yeah, SimulationWorld is listening to you !!) when you want a collision to be resolved by the SimulationWorld, which normally means, that the two bodies won't interpenetrate (well, if the constraint is solvable). One of the Collideables can have no body, it means just one Body needs to be moved (e.g. when a basket ball hit the ground, you want the basket ball to react, not the ground :) ).

Parameters:
collision -
surfParams -

setEnabled

public final void setEnabled(boolean enabled)
Sets this SimulationWorld enabled/disabled.
If not enabled, the update() method will do nothing.

Specified by:
setEnabled in interface org.jagatoo.datatypes.Enableable
Parameters:
enabled -

isEnabled

public final boolean isEnabled()
Specified by:
isEnabled in interface org.jagatoo.datatypes.Enableable
Returns:
if this SimulationWorld is enabled.
If not enabled, the update() method will do nothing.

update

public final void update(long gameTime,
                         long frameTime,
                         UpdatingThread.TimingMode timingMode)
Updates this Updatable object.

Specified by:
update in interface Updatable
Parameters:
gameTime - the gameTime in Milliseconds
frameTime - the frameTime in Milliseconds (needed time for the last frame)
timingMode - the TimingMode to use for frameTime.