org.deken.game.movement
Class GameVector

java.lang.Object
  extended by org.deken.game.movement.GameVector

public class GameVector
extends java.lang.Object

Title: GameVector

Description: Vector for storing direction and speed.

Copyright: Copyright (c) 2002

Version:
1.2
Author:
Gary Deken: Based Thomas Petchel (Java 2 Game Programming)

Nested Class Summary
static class GameVector.DIRECTION
           
 
Field Summary
static float EAST
           
static float EAST_NORTH_EAST
           
static float EAST_SOUTH_EAST
           
static float NO_DIRECTION
           
static float NORTH
           
static float NORTH_EAST
           
static float NORTH_NORTH_EAST
           
static float NORTH_NORTH_WEST
           
static float NORTH_WEST
           
static float SOUTH
           
static float SOUTH_EAST
           
static float SOUTH_SOUTH_EAST
           
static float SOUTH_SOUTH_WEST
           
static float SOUTH_WEST
           
static float WEST
           
static float WEST_NORTH_WEST
           
static float WEST_SOUTH_WEST
           
 
Constructor Summary
GameVector()
          GameVector
GameVector(double xMagnitude, double yMagnitude)
           
GameVector(float directionXY, double speedXY)
          XY direction in degrees and speed (magnitude).
 
Method Summary
 void add(double xMagnitude, double yMagnitude)
          Adds the specified (x, y) values to this GameVector.
 void add(GameVector vector)
          Adds the specified GameVector to this GameVector.
 GameVector copy()
          Make a copy of this GameVector
 double dot(GameVector vector)
          vectorA.vectorB
 boolean equals(GameVector vector)
           
 float getDirection()
          Gets the XY direction in degrees.
static float getDirection(double originX, double originY, double destinX, double destinY)
          Determine the direction from one point to the next point.
static float getDirection(double originX, double originY, GameLocation point)
           
static GameVector.DIRECTION getDirection4Enum(double originX, double originY, double destinX, double destinY)
          Determine the enum DIRECTION from one point to the next point.
static GameVector.DIRECTION getDirection4Enum(float direction)
          Determine the enum DIRECTION from one point to the next point.
static double getSpeed(double xMagnitude, double yMagnitude, float directionXY)
           
 double getSpeedXY()
          This returns the speedXY, number of pixels per millisecond.
 double getXMagnitude()
           
 double getYMagnitude()
           
 boolean isEastward()
          Returns true if the direction is at least a little East.
 boolean isNorthward()
          Returns true if the direction is at least a little North.
 boolean isSouthward()
          Returns true if the direction is at least a little South.
 boolean isWestward()
          Returns true if the direction is at least a little West.
 void normalize()
          normalize
 void reverseDirection()
          Changes the direction 180 degrees.
static double roundOff(double value)
          Round the double to "roundTo" decimal places.
 void scale(double scale)
           
 void setDirection(float direction, double speed)
          Set the direction and speed.
 void setDirection(GameVector.DIRECTION direction, double speed)
          Set the direction and speed.
 void setMagnitudes(double xMagnitude, double yMagnitude)
          Sets the X and Y magnitudes and then calculates the direction and speed.
 void setXMagnitude(double xMagnitude)
           
 void setYMagnitude(double yMagnitude)
           
 void subtract(double xMagnitude, double yMagnitude)
          Subtracts the specified (x, y) values to this vector
 void subtract(GameVector vector)
          Subtracts two vectors.
 java.lang.String toString()
           
 void updateSpeed(double speed)
          Set the speed, using the existing direction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_DIRECTION

public static final float NO_DIRECTION
See Also:
Constant Field Values

EAST

public static final float EAST
See Also:
Constant Field Values

EAST_SOUTH_EAST

public static final float EAST_SOUTH_EAST
See Also:
Constant Field Values

SOUTH_EAST

public static final float SOUTH_EAST
See Also:
Constant Field Values

SOUTH_SOUTH_EAST

public static final float SOUTH_SOUTH_EAST
See Also:
Constant Field Values

SOUTH

public static final float SOUTH
See Also:
Constant Field Values

SOUTH_SOUTH_WEST

public static final float SOUTH_SOUTH_WEST
See Also:
Constant Field Values

SOUTH_WEST

public static final float SOUTH_WEST
See Also:
Constant Field Values

WEST_SOUTH_WEST

public static final float WEST_SOUTH_WEST
See Also:
Constant Field Values

WEST

public static final float WEST
See Also:
Constant Field Values

WEST_NORTH_WEST

public static final float WEST_NORTH_WEST
See Also:
Constant Field Values

NORTH_WEST

public static final float NORTH_WEST
See Also:
Constant Field Values

NORTH_NORTH_WEST

public static final float NORTH_NORTH_WEST
See Also:
Constant Field Values

NORTH

public static final float NORTH
See Also:
Constant Field Values

NORTH_NORTH_EAST

public static final float NORTH_NORTH_EAST
See Also:
Constant Field Values

NORTH_EAST

public static final float NORTH_EAST
See Also:
Constant Field Values

EAST_NORTH_EAST

public static final float EAST_NORTH_EAST
See Also:
Constant Field Values
Constructor Detail

GameVector

public GameVector()
GameVector


GameVector

public GameVector(double xMagnitude,
                  double yMagnitude)
Parameters:
xMagnitude - double
yMagnitude - double

GameVector

public GameVector(float directionXY,
                  double speedXY)
XY direction in degrees and speed (magnitude).

Parameters:
directionXY - int
speedXY - double
Method Detail

getDirection

public static float getDirection(double originX,
                                 double originY,
                                 GameLocation point)
Parameters:
originX -
originY -
point -
Returns:
direction in GameVector directions.

getDirection

public static float getDirection(double originX,
                                 double originY,
                                 double destinX,
                                 double destinY)
Determine the direction from one point to the next point. Returns NO_DIRECTION is they are the same.

Parameters:
originX -
originY -
destinX -
destinY -
Returns:
direction in GameVector directions.

getDirection4Enum

public static GameVector.DIRECTION getDirection4Enum(double originX,
                                                     double originY,
                                                     double destinX,
                                                     double destinY)
Determine the enum DIRECTION from one point to the next point. Returns DIRECTION.NULL is they are the same.

Parameters:
originX -
originY -
destinX -
destinY -
Returns:
DIRECTION

getDirection4Enum

public static GameVector.DIRECTION getDirection4Enum(float direction)
Determine the enum DIRECTION from one point to the next point. Returns DIRECTION.NULL is they are the same.

Parameters:
direction - as degrees
Returns:
DIRECTION

getSpeed

public static double getSpeed(double xMagnitude,
                              double yMagnitude,
                              float directionXY)

roundOff

public static double roundOff(double value)
Round the double to "roundTo" decimal places.

Parameters:
value -
Returns:
double

add

public void add(double xMagnitude,
                double yMagnitude)
Adds the specified (x, y) values to this GameVector.

Parameters:
xMagnitude -
yMagnitude -

add

public void add(GameVector vector)
Adds the specified GameVector to this GameVector.

Parameters:
vector - GameVector

copy

public GameVector copy()
Make a copy of this GameVector

Returns:
GameVector

dot

public double dot(GameVector vector)
vectorA.vectorB

Parameters:
vector - GameVector
Returns:
double

equals

public boolean equals(GameVector vector)
Parameters:
vector - GameVector
Returns:
boolean

getDirection

public float getDirection()
Gets the XY direction in degrees.

Returns:
int

getSpeedXY

public double getSpeedXY()
This returns the speedXY, number of pixels per millisecond. This is the same value as the length(), it uses its own attribute for quick return.

Returns:
double

getXMagnitude

public double getXMagnitude()
Returns:
double

getYMagnitude

public double getYMagnitude()
Returns:
double

isEastward

public boolean isEastward()
Returns true if the direction is at least a little East.

Returns:
boolean

isNorthward

public boolean isNorthward()
Returns true if the direction is at least a little North.

Returns:
boolean

isSouthward

public boolean isSouthward()
Returns true if the direction is at least a little South.

Returns:
boolean

isWestward

public boolean isWestward()
Returns true if the direction is at least a little West.

Returns:
boolean

normalize

public void normalize()
normalize


reverseDirection

public void reverseDirection()
Changes the direction 180 degrees.


scale

public void scale(double scale)
Parameters:
scale - double

setDirection

public void setDirection(float direction,
                         double speed)
Set the direction and speed. The speedXY is number of pixels per tick (game update). If the speed is zero it does not calculate magnitudes.

Parameters:
direction -
speed -

setDirection

public void setDirection(GameVector.DIRECTION direction,
                         double speed)
Set the direction and speed. The speedXY is number of pixels per tick (game update). If the speed is zero it does not calculate magnitudes.

Parameters:
direction - DIRECTION
speed -

setMagnitudes

public void setMagnitudes(double xMagnitude,
                          double yMagnitude)
Sets the X and Y magnitudes and then calculates the direction and speed.

Parameters:
xMagnitude -
yMagnitude -

setXMagnitude

public void setXMagnitude(double xMagnitude)
Parameters:
xMagnitude - double

setYMagnitude

public void setYMagnitude(double yMagnitude)
Parameters:
yMagnitude - double

subtract

public void subtract(double xMagnitude,
                     double yMagnitude)
Subtracts the specified (x, y) values to this vector

Parameters:
xMagnitude -
yMagnitude -

subtract

public void subtract(GameVector vector)
Subtracts two vectors.

Parameters:
vector - GameVector

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String

updateSpeed

public void updateSpeed(double speed)
Set the speed, using the existing direction. The speedXY is number of pixels per tick (game update).

Parameters:
speed -