Packageorg.MARS.simulation
Classpublic class Simulation
InheritanceSimulation Inheritance flash.display.Sprite

Encapsulates all methods required to run a simulation and provides a user-friendly access to the PhysicsEngine class.

Note: Simulation class is implemented as a Singleton, therefore at most one instance of this class can exist. Use Simulation.getInstance() to access this instance.



Public Properties
 PropertyDefined by
  engine : PhysicsEngine
[read-only]
Simulation
  focusObject : ISimulatable
Simulation
  isRunning : Boolean
[read-only]
Simulation
  renderer : IRenderer
[read-only]
Simulation
  scale : Number
Simulation
Public Methods
 MethodDefined by
  
constructor
Simulation
  
addElement(element:ISimulatable, collide:Boolean = true, render:Boolean = true, solver:IODESolver = null):void
Adds an element to the simulation

This will probably be the most used method- it handles a lot of the logic necessary to give the user a lot of control without worrying about dividing up the element to its respective places in the application.

Simulation
  
addGlobalForceGenerator(forceGenerator:IForceGenerator, applyToExisting:Boolean = true):void
Adds a global force to the simulation

This force will be added to all future and current (as defined by applyToExisting) elements

Simulation
  
addRenderable(renderable:Renderable):void
Adds a renderable element to the renderer
Simulation
  
[static] Gets the instance of the singleton
Simulation
  
removeElement(element:*):void
Removes the element from the simulation
Simulation
  
removeGlobalForceGenerator(forceGenerator:IForceGenerator, remainInEffect:Boolean = false):void
Removes a global force from the simulation

This force will be removed from all elements its currently generating for depending on remainInEffect

Simulation
  
start():void
Starts running the simulation
Simulation
  
stepForward(event:Event = null):void
Advances the simulation one step
Simulation
  
still():void
Starts and pauses the simulation
Simulation
  
stop():void
Stops the simulation
Simulation
  
useMouseDragger(value:Boolean):void
Depicts whether to use the MouseSpring on bodies or not
Simulation
  
zoom(amount:Number, focus:ISimulatable = null):void
Zooms on the selected object in the simulation
Simulation
Public Constants
 ConstantDefined by
  DEFAULT_COARSE_COLLISION_DETECTOR : Class
[static] offers a default ICoarseCollisionDetector class
Simulation
  DEFAULT_ODE_SOLVER : Class
[static] offers a default solver class for differential equations
Simulation
  DEFAULT_RENDERER : Class
[static] offers a default IRenderer class
Simulation
  FRICTION_MAGNITUDE : Number = 0.05
[static] offers a default amount of friction applied to every object
Simulation
Property detail
engineproperty
engine:PhysicsEngine  [read-only]Implementation
    public function get engine():PhysicsEngine
focusObjectproperty 
focusObject:ISimulatable  [read-write]Implementation
    public function get focusObject():ISimulatable
    public function set focusObject(value:ISimulatable):void
isRunningproperty 
isRunning:Boolean  [read-only]Implementation
    public function get isRunning():Boolean
rendererproperty 
renderer:IRenderer  [read-only]Implementation
    public function get renderer():IRenderer
scaleproperty 
scale:Number  [read-write]Implementation
    public function get scale():Number
    public function set scale(value:Number):void
Constructor detail
Simulation()constructor
public function Simulation()

constructor

Method detail
addElement()method
public function addElement(element:ISimulatable, collide:Boolean = true, render:Boolean = true, solver:IODESolver = null):void

Adds an element to the simulation

This will probably be the most used method- it handles a lot of the logic necessary to give the user a lot of control without worrying about dividing up the element to its respective places in the application.

Parameters
element:ISimulatable — ISimulatable to add
 
collide:Boolean (default = true) — defines whether this element should be tested for collision during simulation
 
render:Boolean (default = true) — defines whether this element should be drawn
 
solver:IODESolver (default = null) — a unique object to be interpreted by your IFoamRenderer and associated with this element

See also

ISimulatable
RigidBody
IRenderer
Renderable.data
IODESolver
addRenderable
addGlobalForceGenerator()method 
public function addGlobalForceGenerator(forceGenerator:IForceGenerator, applyToExisting:Boolean = true):void

Adds a global force to the simulation

This force will be added to all future and current (as defined by applyToExisting) elements

Parameters
forceGenerator:IForceGenerator — IForceGenerator to add
 
applyToExisting:Boolean (default = true) — whether to add this force generator to all elements already added to FOAM

See also

ISimulatable.addForceGenerator
addRenderable()method 
public function addRenderable(renderable:Renderable):void

Adds a renderable element to the renderer

Parameters
renderable:Renderable — Renderable to add

See also

Renderable
IFoamRenderer
getInstance()method 
public static function getInstance():Simulation

Gets the instance of the singleton

Returns
Simulation — Simulation instance
removeElement()method 
public function removeElement(element:*):void

Removes the element from the simulation

Parameters
element:* — element to remove
removeGlobalForceGenerator()method 
public function removeGlobalForceGenerator(forceGenerator:IForceGenerator, remainInEffect:Boolean = false):void

Removes a global force from the simulation

This force will be removed from all elements its currently generating for depending on remainInEffect

Parameters
forceGenerator:IForceGenerator — IForceGenerator to remove
 
remainInEffect:Boolean (default = false) — whether to allow it to keep generating, but remove it from new additions to FOAM, or remove it from all affected ISimulatables

See also

ISimulatable.addForceGenerator
start()method 
public function start():void

Starts running the simulation

See also

IFoamRenderer.draw
stepForward()
stop()
stepForward()method 
public function stepForward(event:Event = null):void

Advances the simulation one step

Parameters
event:Event (default = null)
still()method 
public function still():void

Starts and pauses the simulation

See also

stop()method 
public function stop():void

Stops the simulation

See also

useMouseDragger()method 
public function useMouseDragger(value:Boolean):void

Depicts whether to use the MouseSpring on bodies or not

Parameters
value:Boolean — true to use the dragger, false otherwise
zoom()method 
public function zoom(amount:Number, focus:ISimulatable = null):void

Zooms on the selected object in the simulation

Parameters
amount:Number — - zoom amount
 
focus:ISimulatable (default = null) — - object to center the screen at
Constant detail
DEFAULT_COARSE_COLLISION_DETECTORconstant
public static const DEFAULT_COARSE_COLLISION_DETECTOR:Class

offers a default ICoarseCollisionDetector class

DEFAULT_ODE_SOLVERconstant 
public static const DEFAULT_ODE_SOLVER:Class

offers a default solver class for differential equations

DEFAULT_RENDERERconstant 
public static const DEFAULT_RENDERER:Class

offers a default IRenderer class

FRICTION_MAGNITUDEconstant 
public static const FRICTION_MAGNITUDE:Number = 0.05

offers a default amount of friction applied to every object