com.annahid.libs.artenus.physics
PhysicsSimulator
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 Type | Field and Description |
---|---|
public static | pixelsPerMeter Holds the number of pixels per meter. |
public | timeScale Holds time scale. |
Constructor Summary
Modifier and Type | Constructor and Description |
---|---|
public | PhysicsSimulator() Creates a new instance of PhysicsSimulator. |
Method Summary
Modifier and Type | Method and Description |
---|---|
public void | attach(PhysicalBody body) Attaches a physical body to the simulator. |
public void | detach(PhysicalBody body) Detaches a physical body from the simulator. |
public CollisionListener | getCollisionListener() Gets the collision listener currently appointed for handling collisions. |
public Point2D | getGravity() Gets the 2-dimensional gravity of the physical world (in meters per seconds squared). |
public void | handleCollisions() Signals the simulator that it is a good time to handle collisions. |
public boolean | isPaused() Indicates whether the simulator is paused. |
public void | setCollisionListener(CollisionListener listener) Sets the listener responsible handling collision events. |
public void | setGravity(float xFactor, float yFactor) Sets the 2-dimensional gravity of the physical world (in meters per seconds squared). |
public void | setPaused(boolean p) Changes the paused state of the simulator. |
public void | step(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:
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:
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:
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:
|
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:
|
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:
|