sim.physics2D
Class PhysicsState

java.lang.Object
  extended by sim.physics2D.PhysicsState

public class PhysicsState
extends java.lang.Object

PhysicsState holds the state of the physical objects in the system. The state consists of the state vector which holds the positions and velocities for all objects, the external forces vector which holds the force and torque accumulators for all objects, and the mass inverse matrix which holds the mass and mass moment of intertia inverses for all objects. Each of these variables is stored in blocks of 3 variables - x, y, and orientation. An object's position, external force, and mass inverse block starts at its index times 3. An object's velocity block starts at the number of objects in the system plus its index times 3. PhysicsState implements the "singleton" pattern so that any object can get a reference to the current PhysicsState object.


Field Summary
 Bag physObjs
           
 
Method Summary
 void addBody(PhysicalObject2D mobj)
          Adds a physical object to the system, expanding all state matrices and vectors to accomodate it.
 void addExternalForce(Double2D force, int index)
          Adds a force to an object's force accumulator in the external forces vector
 void addExternalTorque(double torque, int index)
          Adds a torque to an object's torque accumulator in the external forces vector
 void backupCurrentPosition()
          Copies the "current state" vector into the "saved state" vector.
 void clearAllForces()
          Clears all forces and torques
 double getAngularVelocity(int index)
          Returns an object's angular velocity
 Double2D getExternalForce(int index)
          Returns an object's force accumulator
 Vector getExternalForcesVector()
          Returns the external forces vector that holds the force and torque accumluators for every object in the system
 double getExternalTorque(int index)
          Returns an object's torque accumulator
static PhysicsState getInstance()
          Returns the current PhysicsState instance
 double getLastAngularVelocity(int index)
          Returns an object's angular velocity 1 timestep ago
 Angle getLastOrientation(int index)
          Returns an object's orientation 1 timestep ago
 Double2D getLastPosition(int index)
          Returns an object's last position 1 timestep ago
 Double2D getLastVelocity(int index)
          Returns an object's linear velocity one timestep ago
 double getMassInverse(int index)
          Returns an object's mass inverse
 DiagonalMatrix getMassInverseMatrix()
          Returns the diagonal mass inverse matrix that contains the mass and mass moment of inertia inverses for all objects in the system
 double getMassMomentOfInertiaInverse(int index)
          Returns an object's mass moment inertia inverse
 Angle getOrientation(int index)
          Returns an object's orientation
 Double2D getPosition(int index)
          Returns an object's position
 double getSavedAngularVelocity(int index)
          Returns an object's backed up angular velocity
 Angle getSavedOrientation(int index)
          Returns an object's backed up orientation
 Double2D getSavedPosition(int index)
          Returns an object's backed up position.
 Double2D getSavedVelocity(int index)
          Returns an object's backed up linear velocity
 Vector getStateVector()
          Returns the state vector that contains the positions and velocities of all objects in the system
 Vector getStateVectorCopy()
          Returns a copy of the state vector
 Double2D getVelocity(int index)
          Returns an object's linear velocity
 int numObjs()
          Returns the number of physical objects in the system
static PhysicsState reset()
          Resets the PhysicsState
 void restore()
          Restores the state of the object to the last time "backupCurrentPosition" was run.
 void revertPosition()
          Sets the state of the objects to what they were at the end of the previous timestep.
 void saveLastState()
          Copies the "current state" vector into the "last state" vector.
 void setAngularVelocity(double angularVelocity, int index)
          Updates an object's angular velocity variable in the state vector
 void setMassInverse(double massInverse, double massMomentOfInertiaInverse, int index)
          Updates an object's mass inverse variables in the mass inverse matrix
 void setOrientation(Angle orientation, int index)
          Updates an object's orientation variable in the state vector
 void setPosition(Double2D position, int index)
          Updates an object's position variables in the state vector
 void setStateVector(Vector stateVector)
          Updates the state vector
 void setVelocity(Double2D velocity, int index)
          Updates an object's linear velocity variables in the state vector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

physObjs

public Bag physObjs
Method Detail

getInstance

public static PhysicsState getInstance()
Returns the current PhysicsState instance


reset

public static PhysicsState reset()
Resets the PhysicsState


getStateVector

public Vector getStateVector()
Returns the state vector that contains the positions and velocities of all objects in the system


setStateVector

public void setStateVector(Vector stateVector)
Updates the state vector


getStateVectorCopy

public Vector getStateVectorCopy()
Returns a copy of the state vector


saveLastState

public void saveLastState()
Copies the "current state" vector into the "last state" vector. This is run at the end of each timestep after all state updates are made.


revertPosition

public void revertPosition()
Sets the state of the objects to what they were at the end of the previous timestep.


backupCurrentPosition

public void backupCurrentPosition()
Copies the "current state" vector into the "saved state" vector. This is used for collision detection so a penetrating pair of objects can be moved back in time over the last timestep to search for their exact collision point and then restored once the collision is found.


restore

public void restore()
Restores the state of the object to the last time "backupCurrentPosition" was run.


setPosition

public void setPosition(Double2D position,
                        int index)
Updates an object's position variables in the state vector


getPosition

public Double2D getPosition(int index)
Returns an object's position


getLastPosition

public Double2D getLastPosition(int index)
Returns an object's last position 1 timestep ago


getSavedPosition

public Double2D getSavedPosition(int index)
Returns an object's backed up position.


setOrientation

public void setOrientation(Angle orientation,
                           int index)
Updates an object's orientation variable in the state vector


getOrientation

public Angle getOrientation(int index)
Returns an object's orientation


getLastOrientation

public Angle getLastOrientation(int index)
Returns an object's orientation 1 timestep ago


getSavedOrientation

public Angle getSavedOrientation(int index)
Returns an object's backed up orientation


setVelocity

public void setVelocity(Double2D velocity,
                        int index)
Updates an object's linear velocity variables in the state vector


getVelocity

public Double2D getVelocity(int index)
Returns an object's linear velocity


getLastVelocity

public Double2D getLastVelocity(int index)
Returns an object's linear velocity one timestep ago


getSavedVelocity

public Double2D getSavedVelocity(int index)
Returns an object's backed up linear velocity


setAngularVelocity

public void setAngularVelocity(double angularVelocity,
                               int index)
Updates an object's angular velocity variable in the state vector


getAngularVelocity

public double getAngularVelocity(int index)
Returns an object's angular velocity


getLastAngularVelocity

public double getLastAngularVelocity(int index)
Returns an object's angular velocity 1 timestep ago


getSavedAngularVelocity

public double getSavedAngularVelocity(int index)
Returns an object's backed up angular velocity


getExternalForcesVector

public Vector getExternalForcesVector()
Returns the external forces vector that holds the force and torque accumluators for every object in the system


addExternalForce

public void addExternalForce(Double2D force,
                             int index)
Adds a force to an object's force accumulator in the external forces vector


getExternalForce

public Double2D getExternalForce(int index)
Returns an object's force accumulator


addExternalTorque

public void addExternalTorque(double torque,
                              int index)
Adds a torque to an object's torque accumulator in the external forces vector


getExternalTorque

public double getExternalTorque(int index)
Returns an object's torque accumulator


clearAllForces

public void clearAllForces()
Clears all forces and torques


getMassInverseMatrix

public DiagonalMatrix getMassInverseMatrix()
Returns the diagonal mass inverse matrix that contains the mass and mass moment of inertia inverses for all objects in the system


setMassInverse

public void setMassInverse(double massInverse,
                           double massMomentOfInertiaInverse,
                           int index)
Updates an object's mass inverse variables in the mass inverse matrix


getMassInverse

public double getMassInverse(int index)
Returns an object's mass inverse


getMassMomentOfInertiaInverse

public double getMassMomentOfInertiaInverse(int index)
Returns an object's mass moment inertia inverse


numObjs

public int numObjs()
Returns the number of physical objects in the system


addBody

public void addBody(PhysicalObject2D mobj)
Adds a physical object to the system, expanding all state matrices and vectors to accomodate it.