Artenus 2D Framework
Artenus Reference
Performs physical simulation in the framework. It handles everything related to physical bodies, joints and physical animation. It is highly recommended that you do not directly instantiate this class. Each Scene internally contains a PhysicsSimulator instance and it is recommended that you take advantage of that through entities such as PhysicalBody.

See Also:

public final class PhysicsSimulator

Field Summary

Modifier and TypeField and Description
public static pixelsPerMeter
Holds the number of pixels per meter.
public timeScale
Holds time scale.

Constructor Summary

Modifier and TypeConstructor and Description
public PhysicsSimulator()
Creates a new instance of PhysicsSimulator.

Method Summary

Modifier and TypeMethod and Description
public voidattach(PhysicalBody body)
Attaches a physical body to the simulator.
public voiddetach(PhysicalBody body)
Detaches a physical body from the simulator.
public CollisionListenergetCollisionListener()
Gets the collision listener currently appointed for handling collisions.
public Point2DgetGravity()
Gets the 2-dimensional gravity of the physical world (in meters per seconds squared).
public voidhandleCollisions()
Signals the simulator that it is a good time to handle collisions.
public booleanisPaused()
Indicates whether the simulator is paused.
public voidsetCollisionListener(CollisionListener listener)
Sets the listener responsible handling collision events.
public voidsetGravity(float xFactor, float yFactor)
Sets the 2-dimensional gravity of the physical world (in meters per seconds squared).
public voidsetPaused(boolean p)
Changes the paused state of the simulator.
public voidstep(float elapsedTime, int velocityIterations, int positionIterations)
Advances the world by the given time.

Methods inherited from java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

pixelsPerMeter
public static pixelsPerMeter
Holds the number of pixels per meter. This framework is based on pixel measures. However, everything other than distances are calculated by their SI units in physics simulations. To conform distances to the SI unit, this value indicates how many pixels define a meter. Note that setting this value to zero causes division by zero and results in application crash.
timeScale
public timeScale
Holds time scale. Use this field to scale the physical time. The value of this parameter is originally 1, which means that the time in the physical world is as fast as the time in scene animations. Setting this value enables you to speed up or slow down physics.

Constructor Detail

PhysicsSimulator
public  PhysicsSimulator()
Creates a new instance of PhysicsSimulator.

Method Detail

attach
public void attach(
    PhysicalBody body
)
Attaches a physical body to the simulator. You do not need to call this method directly if you are using physics simulation through a scene.
Parameters:
bodyThe new physical body
See Also:
detach
public void detach(
    PhysicalBody body
)
Detaches a physical body from the simulator. You do not need to call this method directly if you are using physics simulation through the scene. Once a body is detached from the simulator, it must be disposed. Physical objects removed from the scene are NOT reusable.
Parameters:
bodyThe physical body to remove
See Also:
getCollisionListener
public CollisionListener getCollisionListener()
Gets the collision listener currently appointed for handling collisions.
Returns:
The collision listener, or null if none is assigned
See Also:
getGravity
public Point2D getGravity()
Gets the 2-dimensional gravity of the physical world (in meters per seconds squared).
Returns:
Gravity
handleCollisions
public void handleCollisions()
Signals the simulator that it is a good time to handle collisions. Normally all collisions are queued in the simulator when they happen. This is to avoid concurrent modification of sensitive variables. This method is then called when it is safe, and it handles all collisions in the queue until the queue is empty. You do not need to call this method manually if you are using physics simulation through a scene.
isPaused
public boolean isPaused()
Indicates whether the simulator is paused.
Returns:
true if paused or false otherwise
setCollisionListener
public void setCollisionListener(
    CollisionListener listener
)
Sets the listener responsible handling collision events.
Parameters:
listenerCollision listener; setting this value to null removes the listener
See Also:
setGravity
public void setGravity(
    float xFactor,
    float yFactor
)
Sets the 2-dimensional gravity of the physical world (in meters per seconds squared).
Parameters:
xFactorThe x factor of gravity
yFactorThe y factor of gravity
setPaused
public void setPaused(
    boolean p
)
Changes the paused state of the simulator. Physical bodies in a paused simulator remain halted until the simulator is resumed.
Parameters:
ptrue to pause the simulator or false to un-pause it
step
public void step(
    float elapsedTime,
    int velocityIterations,
    int positionIterations
)
Advances the world by the given time. This method is called internally by the scene and you do not need to directly invoke it.
Parameters:
elapsedTimeThe time passed since last frame. This value will be scaled using timeScale
velocityIterationsThe number of velocity points to interpolate between
positionIterationsThe number of position points to interpolate between