vehicle
Class MovementTracker

java.lang.Object
  |
  +--vehicle.MovementTracker

public class MovementTracker
extends java.lang.Object

A MovementTracker tracks the current position and orientation of an object with graphics components. It mostly handles converting from global to local coordinates for each object.

The position and orientation is relative to the orignal center position and orientation of the object. However, all positions are returned in global coordinates.


Field Summary
private  java.awt.geom.Area container
           
private  double orientation
           
private  double posX
           
private  double posY
           
private  double startX
           
private  double startY
           
 
Constructor Summary
MovementTracker()
          Creates a tracker
 
Method Summary
 java.awt.geom.Area getCurrentContainer()
          Retreives the current outline of the shapes
 double getOrientation()
          Gets the orientation changed from the inital drawing
 java.awt.geom.AffineTransform getTransform()
          Get the affine transform of this vehicle from global to local space
 double getX()
          Returns the current x position of the center point of all the shapes contained in this tracker
 double getY()
          Returns the current y position of the center point of all the shapes contained in this tracker
 void moveBy(double xoffset, double yoffset)
          Move by xoffset and yoffset pixels
 void moveTo(double x, double y)
          Move to (x, y) in the world
 void registerShape(java.awt.Shape s)
          Registers a shape as part of this tracker to track.
 void rotateBy(double theta)
          Rotate shapes by theta with postive sign meaning clockwise
 void setRotation(double theta)
          Set the current rotation with postive sign meaning clockwise
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startX

private double startX

startY

private double startY

posX

private double posX

posY

private double posY

orientation

private double orientation

container

private java.awt.geom.Area container
Constructor Detail

MovementTracker

public MovementTracker()
Creates a tracker

Method Detail

registerShape

public void registerShape(java.awt.Shape s)
Registers a shape as part of this tracker to track. All shapes created must be registered with their own MovementTracker in order to move around correctly. The position of the object might change slightly if shapes are register while the object is in motion.

Parameters:
s - the Shape to add to this tracker

getX

public double getX()
Returns the current x position of the center point of all the shapes contained in this tracker

Returns:
x-coordinate of the shapes' center

getY

public double getY()
Returns the current y position of the center point of all the shapes contained in this tracker

Returns:
y-coordinate of the shapes' center

getOrientation

public double getOrientation()
Gets the orientation changed from the inital drawing

Returns:
the angle in radians of the change

moveTo

public void moveTo(double x,
                   double y)
Move to (x, y) in the world

Parameters:
x - the x-coordinate to move to
y - the y-coordinate to move to

setRotation

public void setRotation(double theta)
Set the current rotation with postive sign meaning clockwise

Parameters:
theta - the angle in radians

moveBy

public void moveBy(double xoffset,
                   double yoffset)
Move by xoffset and yoffset pixels

Parameters:
xoffset - the number of pixels to move in the x-axis direction
yoffset - the number of pixelse to move in the y-axis direction

rotateBy

public void rotateBy(double theta)
Rotate shapes by theta with postive sign meaning clockwise

Parameters:
theta - the angle in radians

getTransform

public java.awt.geom.AffineTransform getTransform()
Get the affine transform of this vehicle from global to local space

Returns:
the affine transform

getCurrentContainer

public java.awt.geom.Area getCurrentContainer()
Retreives the current outline of the shapes

Returns:
the outline container of the shapes