org.xith3d.physics.simulation
Class SimulationEngine

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

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

A simulation engine


Field Summary
protected  java.util.ArrayList<SimulationWorld> worlds
           
 
Constructor Summary
protected SimulationEngine()
           
 
Method Summary
 void destroyWorld(SimulationWorld world)
          Destroys the given SimulationWorld.
 long getMaxStepSize()
           
 long getStepSize()
           
 java.util.ArrayList<SimulationWorld> getWorlds()
           
 boolean isEnabled()
           
 SurfaceParameters newSurfaceParameters()
           
abstract  SurfaceParameters newSurfaceParameters(java.lang.String[] paramStrings, java.lang.Object[] paramValues)
          Creates a new SurfaceParameters with specified params.
 SimulationWorld newWorld()
          Creates a new Simulation World.
abstract  SimulationWorld newWorldImpl()
          Creates a new Simulation World.
 void setCollisionResolversManager(CollisionResolversManager collisionResolversManager)
           
 void setEnabled(boolean enabled)
          Sets this SimulationEngine enabled/disabled.
 void setMaxStepSize(long micros)
          Sets the maximum internal step time in microseconds.
 void setStepSize(long micros)
          Sets the constant internal step time in microseconds.
 void step(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

worlds

protected final java.util.ArrayList<SimulationWorld> worlds
Constructor Detail

SimulationEngine

protected SimulationEngine()
Method Detail

getWorlds

public final java.util.ArrayList<SimulationWorld> getWorlds()
Returns:
the list of worlds created and managed by this SimulationEngine.

newWorldImpl

public abstract SimulationWorld newWorldImpl()
Creates a new Simulation World.

Returns:
the newly created World.

newWorld

public final SimulationWorld newWorld()
Creates a new Simulation World.

Returns:
the newly created World.

newSurfaceParameters

public abstract SurfaceParameters newSurfaceParameters(java.lang.String[] paramStrings,
                                                       java.lang.Object[] paramValues)
Creates a new SurfaceParameters with specified params.

Parameters:
paramStrings - the param strings to be specified, e.g. "mu" or "bounce"
paramValues - the values of the params to be specified, e.g. ".1f" or "true"

newSurfaceParameters

public final SurfaceParameters newSurfaceParameters()
Returns:
a new instance of SurfaceParameters filled with default values.

destroyWorld

public void destroyWorld(SimulationWorld world)
Destroys the given SimulationWorld.

Parameters:
world -

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.

step

public final void step(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.

setCollisionResolversManager

public final void setCollisionResolversManager(CollisionResolversManager collisionResolversManager)

setEnabled

public final void setEnabled(boolean enabled)
Sets this SimulationEngine 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 SimulationEngine 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.