javoids
Class Common

java.lang.Object
  extended by javoids.Common
All Implemented Interfaces:
java.io.Serializable

public class Common
extends java.lang.Object
implements java.io.Serializable

A class of commonly used static functions that should not apply to any specific class getDistanceXY -calculate the distance between two cartesian coordinates getDistanceM -calculate the distance between two cartesian coordinates w/ Mobeus effect smallest of XY and XY2 getQuadrantXY -calculate the relative quadrant that another sprite is in getQuadrantM -calculate the relative quadrant that another sprite is in w/ Mobeus effect getAngleOrigin -calculate the angle between two cartesian coordinates effect relative to 0 (straight up) 0..359 clockwise getAngleXY -calculate the angle between two cartesian coordinates effect relative to 0 (straight up) 0..359 clockwise getAngleM -calculate the angle between two cartesian coordinates w/ Mobeus effect relative to 0 (straight up) 0..359 clockwise target -have one sprite turn to face another sprite (instantaneous turns)

Author:
mallette
See Also:
Serialized Form

Field Summary
static double PI2
          constant for 2*PI used in calculations
private static long serialVersionUID
          This is the version used for serializing/deserializing (storing/retrieving) this object
static double toRadians
          constant to quickly convert to radian values (for calling Java's math functions that use radian values)
static java.lang.String URL_SEPARATOR
          constant for separating URLs
 
Constructor Summary
Common()
           
 
Method Summary
static double getAngleM(double x1, double y1, double x2, double y2, double width, double height)
           
static double getAngleOrigin(double x1, double y1, double x2, double y2)
           
static double getAngleXY(double x1, double y1, double x2, double y2)
           
static double getDistanceM(double x1, double y1, double x2, double y2, double width, double height)
           
static double getDistanceM(Move move1, Move move2)
           
static double getDistanceXY(double x1, double y1, double x2, double y2)
           
static int getQuadrantM(double x1, double y1, double x2, double y2, double width, double height)
           
static int getQuadrantXY(double x1, double y1, double x2, double y2)
           
static double pow2(double x)
           
static void target(Move move1, Move move2)
          change the direction of move1 toward the location in move2 (to target that point)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
This is the version used for serializing/deserializing (storing/retrieving) this object

See Also:
Constant Field Values

URL_SEPARATOR

public static java.lang.String URL_SEPARATOR
constant for separating URLs


PI2

public static double PI2
constant for 2*PI used in calculations


toRadians

public static double toRadians
constant to quickly convert to radian values (for calling Java's math functions that use radian values)

Constructor Detail

Common

public Common()
Method Detail

pow2

public static double pow2(double x)
Parameters:
x - the value to square
Returns:
the square of x

getDistanceXY

public static double getDistanceXY(double x1,
                                   double y1,
                                   double x2,
                                   double y2)
Parameters:
x1 - point1's x coordinate
y1 - point1's y coordinate
x2 - point2's x coordinate
y2 - point2's y coordinate
Returns:
the distance between two points

getDistanceM

public static double getDistanceM(double x1,
                                  double y1,
                                  double x2,
                                  double y2,
                                  double width,
                                  double height)
Parameters:
x1 - point1's x coordinate
y1 - point1's y coordinate
x2 - point2's x coordinate
y2 - point2's y coordinate
width - the width of the screen
height - the height of the screen
Returns:
the shortest distance between two points (where Mobeus wrapping occurs around screen sides)

getQuadrantXY

public static int getQuadrantXY(double x1,
                                double y1,
                                double x2,
                                double y2)
Parameters:
x1 - point1's x coordinate
y1 - point1's y coordinate
x2 - point2's x coordinate
y2 - point2's y coordinate
Returns:
the quadrant that the point2 is in relative to point1

getQuadrantM

public static int getQuadrantM(double x1,
                               double y1,
                               double x2,
                               double y2,
                               double width,
                               double height)
Parameters:
x1 - point1's x coordinate
y1 - point1's y coordinate
x2 - point2's x coordinate
y2 - point2's y coordinate
width - the width of the screen
height - the height of the screen
Returns:
the quadrant that the point2 is in relative to point1 (taking Mobeus distances around screen sides into account)

getAngleOrigin

public static double getAngleOrigin(double x1,
                                    double y1,
                                    double x2,
                                    double y2)
Parameters:
x1 - point1's x coordinate
y1 - point1's y coordinate
x2 - point2's x coordinate
y2 - point2's y coordinate
Returns:
the angle between the rays formed by point1 and point2 relative to the horizontal

getAngleXY

public static double getAngleXY(double x1,
                                double y1,
                                double x2,
                                double y2)
Parameters:
x1 - point1's x coordinate
y1 - point1's y coordinate
x2 - point2's x coordinate
y2 - point2's y coordinate
Returns:
the angle between the rays formed by point1 and point2 relative to the horizontal

getAngleM

public static double getAngleM(double x1,
                               double y1,
                               double x2,
                               double y2,
                               double width,
                               double height)
Parameters:
x1 - point1's x coordinate
y1 - point1's y coordinate
x2 - point2's x coordinate
y2 - point2's y coordinate
width - the width of the screen
height - the height of the screen
Returns:
the angle between the rays formed by point1 and point2 relative to the horizontal (taking Mobeus distances around screen sides into account)

getDistanceM

public static double getDistanceM(Move move1,
                                  Move move2)
Parameters:
move1 - the first location information
move2 - the second location information
Returns:
the distance between the two locations (taking Mobeus distances around screen sides into account)

target

public static void target(Move move1,
                          Move move2)
change the direction of move1 toward the location in move2 (to target that point)

Parameters:
move1 - the first location information
move2 - the second location information