vooga.physicsEngine
Class PhysicalItem

java.lang.Object
  extended by vooga.gameEngine.game.GameRelatedObject
      extended by vooga.gameEngine.item.GameItem
          extended by vooga.physicsEngine.PhysicalItem
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Renderable>, Renderable, Tangible
Direct Known Subclasses:
Ball, Ball, Barrier, Barrier, Block, Box, ImageObstacle, LookButNoTouchCharacter, PaddleLeft, PaddleRight, PongItem, Projectile, TestSquare

public class PhysicalItem
extends GameItem

A game item that involves physics. This is the game designer's main API to physics related functionalities.

Author:
Peng Shi
See Also:
Serialized Form

Field Summary
 GamePhysicalParameters parameters
          This is the internal parameters encapsulation of this physicalItem.
 
Constructor Summary
PhysicalItem(Shape shape)
          Create a PhysicalItem based on a vooga.physicsEngine.geometry.shapes.Shape object.
PhysicalItem(Shape shape, java.awt.Color color)
          Create a Physical item with given vooga.physicsEngine.geometry.shapes.Shape and color.
PhysicalItem(Texture texture, double centroidX, double centroidY)
           Creates a physical item based on a Texture object, which basically represents an object image.
 
Method Summary
 void applyAngularImpulse(double angularImpulse)
          Apply an angular impulse on the object
 void applyImpulse(Vector2f impulse)
          Apply an impulse on the object
 boolean getPhysicsOn()
          Checks if physics is turned on for this item.
 void setConstantForce(Vector2f constantForce)
          Sets a sustained force on the object (i.e.
 void setPhysicsOn(boolean physicsOn)
          Sets whether physics should be turned on for this item.
 void setPosition(double x, double y)
          Set the game position of an object.
 void setPosition(Vector2f position)
          Set the game position of an object.
 
Methods inherited from class vooga.gameEngine.item.GameItem
compareTo, getPosition, getRotation, getShape, getSize, getTexture, isVisible, move, resize, rotate, setPosition, setRotation, setSize, setVisibility
 
Methods inherited from class vooga.gameEngine.game.GameRelatedObject
addEventListener, clearListeners, equals, fire, fire, fire, getEventListeners, getID, getListenerCount, removeEventListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameters

public final GamePhysicalParameters parameters
This is the internal parameters encapsulation of this physicalItem. This is for advanced manipulation of the physicalItem. Many useful methods are in parameters, including changing physical properties such as mass, moment of inertia, elasticity, and modifying the underlying velocity/positions to implement advanced physical items (such as rocket always applying a certain thrust in its current forward direction).

Constructor Detail

PhysicalItem

public PhysicalItem(Shape shape)
Create a PhysicalItem based on a vooga.physicsEngine.geometry.shapes.Shape object. The default color is black.

Parameters:
parameters - internal encapsulation of physical properties

PhysicalItem

public PhysicalItem(Shape shape,
                    java.awt.Color color)
Create a Physical item with given vooga.physicsEngine.geometry.shapes.Shape and color.

Parameters:
shape -
color -

PhysicalItem

public PhysicalItem(Texture texture,
                    double centroidX,
                    double centroidY)

Creates a physical item based on a Texture object, which basically represents an object image. This will internally create a PhysicalParameters object based on the shape of the texture object.

The centroidX and centroidY are where the centroid of the texture object is IN THE TEXTURE's COORDINATES. This is important because we need this information to represent the texture object internally, and the wrong centroid can result in un-physical situations in which the centroid is outside, which will break the physics engine because that assumes the centroid is always inside the object and the object is convex.

Parameters:
texture -
centroidX -
centroidY -
Method Detail

setPosition

public void setPosition(Vector2f position)
Set the game position of an object. This simply calls the setPosition(Position) function.

Parameters:
position -

setPosition

public void setPosition(double x,
                        double y)
Set the game position of an object. This simply calls the setPosition(Position) function.

Parameters:
x -
y -

setPhysicsOn

public void setPhysicsOn(boolean physicsOn)
Sets whether physics should be turned on for this item.

Parameters:
physicsOn -

getPhysicsOn

public boolean getPhysicsOn()
Checks if physics is turned on for this item.


applyImpulse

public void applyImpulse(Vector2f impulse)
Apply an impulse on the object

Parameters:
impulse -

applyAngularImpulse

public void applyAngularImpulse(double angularImpulse)
Apply an angular impulse on the object

Parameters:
angularImpulse -

setConstantForce

public void setConstantForce(Vector2f constantForce)
Sets a sustained force on the object (i.e. 1 N left)

Parameters:
constantForce -