vooga.physicsEngine
Class GamePhysicalParameters

java.lang.Object
  extended by vooga.physicsEngine.geometry.GeometricParameters
      extended by vooga.physicsEngine.PhysicalParameters
          extended by vooga.physicsEngine.GamePhysicalParameters
All Implemented Interfaces:
java.util.EventListener, PositionChangeListener, RotationChangeListener

public class GamePhysicalParameters
extends PhysicalParameters
implements PositionChangeListener, RotationChangeListener

Class for linking PhysicalParameters (basis of our independent physics module) with PhysicalItem (linkage with the game engine). This links up the position and angular position of the two objects.

While this may seem bulky, it helps to decouple the core of the physics engine with the core of the game engine. One can view this setup as a type of controller between the game engine implementation of positions and rotations, which is intricately tied to their Texture objects (but may conceivably change in the future), with the physics engine implementation of positions and rotations. Hence, this class makes the rest of the physical engine closed (does not need to be changed) when game engine decides to change their underlying representation of rotations and positions, but also makes the physics engine open to adapting to whatever game engine decides to do. Only this adapter class needs to change when the game engine decides to change their core implementation. The apparent bulkiness of the design is a good sacrifice for the added independence.

Author:
Peng Shi

Field Summary
 
Fields inherited from class vooga.physicsEngine.geometry.GeometricParameters
shape
 
Constructor Summary
GamePhysicalParameters(Shape shape, PhysicalItem parent)
          Create a GamePhysicalParameters object based on given Shape and parent PhysicalItem.
GamePhysicalParameters(Texture texture, double centroidX, double centroidY, PhysicalItem parent)
          Create a GamePhysicalParameters object using texture, location of where the centroid of the object is in the texture's coordinates, and the parent PhysicalItem
 
Method Summary
 Vector2f getPosition()
           
 boolean inCollisionWith(PhysicalItem otherObject)
          Checks if the parent PhysicalItem is currently in collision with another PhysicalItem.
 void incrementAngularPosition(double difference)
           
 void incrementPosition(Vector2f difference)
           
 void positionChanged(PositionChangedEvent e)
          This is called whenever a Tangible object updates its position.
 void rotationChanged(RotationChangedEvent e)
          This is called whenever a Tangible object changes its rotation.
 void setAngularPosition(double angularPosition)
           
 void setCentroidPosition(Vector2f position)
           
 void setPosition(Vector2f position)
           
 
Methods inherited from class vooga.physicsEngine.PhysicalParameters
applyAngularImpulse, applyImpulse, endFrame, getAngularVelocity, getCollideSet, getConstantAcceleration, getConstantTorque, getDamping, getElasticity, getFrictionCoefficient, getInvI, getInvMass, getMass, getMomentOfInertia, getRotationalDamping, getVelocity, inCollisionWith, incrementAngularVelocity, incrementVelocity, isMovable, notifyCollided, setAngularVelocity, setConstantAcceleration, setConstantForce, setConstantTorque, setDamping, setElasticity, setFrictionCoefficient, setMass, setMomentOfInertia, setMovable, setRotationalDamping, setVelocity, startFrame
 
Methods inherited from class vooga.physicsEngine.geometry.GeometricParameters
drawShape, getAbsoluteCoordinate, getAngularPosition, getCentroidPosition, getJavaShape, getShape, getTransformedArea
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GamePhysicalParameters

public GamePhysicalParameters(Shape shape,
                              PhysicalItem parent)
Create a GamePhysicalParameters object based on given Shape and parent PhysicalItem.

Parameters:
shape -
parent -

GamePhysicalParameters

public GamePhysicalParameters(Texture texture,
                              double centroidX,
                              double centroidY,
                              PhysicalItem parent)
Create a GamePhysicalParameters object using texture, location of where the centroid of the object is in the texture's coordinates, and the parent PhysicalItem

Parameters:
texture -
centroidX -
centroidY -
parent -
Method Detail

setAngularPosition

public void setAngularPosition(double angularPosition)
Overrides:
setAngularPosition in class GeometricParameters
Parameters:
angularPosition - the angularPosition to set

incrementAngularPosition

public void incrementAngularPosition(double difference)
Overrides:
incrementAngularPosition in class GeometricParameters

setCentroidPosition

public void setCentroidPosition(Vector2f position)
Overrides:
setCentroidPosition in class GeometricParameters
Parameters:
position - the centroid position to set

incrementPosition

public void incrementPosition(Vector2f difference)
Overrides:
incrementPosition in class GeometricParameters
Parameters:
difference - the change in position

setPosition

public void setPosition(Vector2f position)

rotationChanged

public void rotationChanged(RotationChangedEvent e)
Description copied from interface: RotationChangeListener
This is called whenever a Tangible object changes its rotation.

Specified by:
rotationChanged in interface RotationChangeListener
Parameters:
e - the RotationChangedEvent

positionChanged

public void positionChanged(PositionChangedEvent e)
Description copied from interface: PositionChangeListener
This is called whenever a Tangible object updates its position.

Specified by:
positionChanged in interface PositionChangeListener
Parameters:
e - the PositionChangedEvent

getPosition

public Vector2f getPosition()
Returns:

inCollisionWith

public boolean inCollisionWith(PhysicalItem otherObject)
Checks if the parent PhysicalItem is currently in collision with another PhysicalItem. (This is used to count each new collision as one, instead of several, because technically objects will collide for several frames, but this will only return false at the first frame.)

Parameters:
otherObject -
Returns:
whether the parent PhysicalItem is already in collision with the otherObject