netwar.utils
Class Point3D

java.lang.Object
  |
  +--netwar.utils.Point3D

public class Point3D
extends java.lang.Object

This class is used to represent a location or vector in gamespace. A Point3D can be translated into a Point2D using the internal transform matrix, and that matrix can be manipulated for zooming and changes in angle.

Note that the get_ functions return a new Point2D/3D while the do_ funtions affect this Point3D.

Author:
Daniel Grund and Kyle Kakligian

Field Summary
 float x
          X-axis value or length.
 float y
          Y-axis value or length.
 float z
          Z-axis value or length.
 
Constructor Summary
Point3D()
          Constructor for the orgin.
Point3D(double X, double Y, double Z)
          Constructs a Point3D, converting the doubles to floats.
Point3D(float X, float Y, float Z)
          Constructs a Point3D
Point3D(Point3D v)
          Copy constructor
 
Method Summary
 Point3D doCrossProduct(Point3D v)
          Evalutates the cross (vector) product of two vectors.
 Point3D doDifference(Point3D v)
          Returns the vector difference of this Point3D and the given Point3D.
 Point3D doProduct(float scalar)
          Returns a new Point3D that is the scalar product of this one.
 Point3D doSum(Point3D v)
          Returns the sum of this Point3D and the given vector.
 boolean equals(float X, float Y, float Z)
          Implementation of Object.equals().
 boolean equals(Point3D p)
          Implementation of Object.equals().
 Point3D getCrossProduct(Point3D v)
          Evalutates the cross (vector) product of two vectors.
 Point3D getDifference(Point3D v)
          Returns the vector difference of this Point3D and the given Point3D.
 float getDotProduct(Point3D v)
          Evalutates the dot (scalar) product of two vectors.
 float getLength()
          Returns the distance to the orgin, or, returns the length of the vector.
 float getLengthSquared()
          Same as getLength() without the square root.
 Point2D getPoint2D()
          Converts this gamespace point into a 2D screenspace point using the transform matrix.
static Point2D getPoint2D(Point3D v)
          Converts this gamespace point into a 2D screenspace point using the transform matrix.
static Point3D getPoint3D(int x, int y)
          Converts a 2D screenspace point into a 3D gamespace point using the transform matrix.
static Point3D getPoint3D(Point2D pt)
          Converts a 2D screenspace point into a 3D gamespace point using the transform matrix.
 Point3D getProduct(float scalar)
          Returns a new Point3D that is the scalar product of this one.
static float getScale()
          Returns the current scaling value.
 Point3D getSum(Point3D v)
          Returns the sum of this Point3D and the given vector.
 void Normalize()
          Changes the length of this vector to 1.
 Point3D set(float X, float Y, float Z)
          Sets this point from the given information.
 Point3D set(Point3D p)
          Sets this point as a copy of the given one.
static void translate(int x, int y)
          Adjusts the transform matrix in the (x,y,0) direction.
static void zoom(float factor, int halfwidth, int halfheight)
          Adjusts the transform matrix in the (0,0,z) direction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

public float x
X-axis value or length.

y

public float y
Y-axis value or length.

z

public float z
Z-axis value or length.
Constructor Detail

Point3D

public Point3D()
Constructor for the orgin.

Point3D

public Point3D(float X,
               float Y,
               float Z)
Constructs a Point3D
Parameters:
X - X-axis value or length.
Y - Y-axis value or length.
Z - Z-axis value or length.

Point3D

public Point3D(double X,
               double Y,
               double Z)
Constructs a Point3D, converting the doubles to floats.
Parameters:
X - X-axis value or length.
Y - Y-axis value or length.
Z - Z-axis value or length.

Point3D

public Point3D(Point3D v)
Copy constructor
Parameters:
v - Copy.
Method Detail

getProduct

public Point3D getProduct(float scalar)
Returns a new Point3D that is the scalar product of this one.
Parameters:
scalar - Multiplier
Returns:
Returns a new Point3D

getDotProduct

public float getDotProduct(Point3D v)
Evalutates the dot (scalar) product of two vectors.
Parameters:
v - Secound vector in the dot product operation.
Returns:
Scalar.

getCrossProduct

public Point3D getCrossProduct(Point3D v)
Evalutates the cross (vector) product of two vectors.
Parameters:
v - Secound vector in the cross product operation.
Returns:
Returns a new Point3D

getSum

public Point3D getSum(Point3D v)
Returns the sum of this Point3D and the given vector.
Parameters:
v - The vector to add to this.
Returns:
Returns a new Point3D.

getDifference

public Point3D getDifference(Point3D v)
Returns the vector difference of this Point3D and the given Point3D.
Parameters:
v - The secound point in this operation that the returned vector points to. (this + returned = v)
Returns:
Returns a new Point3D

doProduct

public Point3D doProduct(float scalar)
Returns a new Point3D that is the scalar product of this one.
Parameters:
scalar - Multiplier.
Returns:
Returns a reference to this where the result is stored.

doCrossProduct

public Point3D doCrossProduct(Point3D v)
Evalutates the cross (vector) product of two vectors.
Parameters:
v - Secound vector in the cross product operation.
Returns:
Returns a reference to this where the result is stored.

doSum

public Point3D doSum(Point3D v)
Returns the sum of this Point3D and the given vector.
Parameters:
v - The vector to add to this.
Returns:
Returns a reference to this where the result is stored.

doDifference

public Point3D doDifference(Point3D v)
Returns the vector difference of this Point3D and the given Point3D.
Parameters:
v - The secound point in this operation that the returned vector points to. (prethis + postthis = v)
Returns:
Returns a reference to this where the result is stored.

Normalize

public void Normalize()
Changes the length of this vector to 1. The direction is kept constant.

getLength

public float getLength()
Returns the distance to the orgin, or, returns the length of the vector. (Whether this is a vector or a point, both values are the same but have different meanings)
Returns:
Length.
See Also:
getLengthSquared()

getLengthSquared

public float getLengthSquared()
Same as getLength() without the square root. Since all distances are positive and reletive, we can compare their square distances. This is an optimization.
Returns:
x*x + y*y + z*z
See Also:
getLength()

getPoint2D

public Point2D getPoint2D()
Converts this gamespace point into a 2D screenspace point using the transform matrix.
Returns:
Returns a new Point2D.

getPoint2D

public static Point2D getPoint2D(Point3D v)
Converts this gamespace point into a 2D screenspace point using the transform matrix.
Parameters:
v - The point to convert.
Returns:
Returns a new Point2D.

getPoint3D

public static Point3D getPoint3D(Point2D pt)
Converts a 2D screenspace point into a 3D gamespace point using the transform matrix.
Parameters:
pt - A Point2D in screen space.
Returns:
Returns a new Point3D.

getPoint3D

public static Point3D getPoint3D(int x,
                                 int y)
Converts a 2D screenspace point into a 3D gamespace point using the transform matrix.
Parameters:
x - The x-axis value in screen space.
y - The x-axis value in screen space.
Returns:
Returns a new Point3D.

equals

public boolean equals(Point3D p)
Implementation of Object.equals(). Compares two Point3Ds for equality. This operation is reflexive, symmetric, and transitive. For any reference value x, x.equals(null) returns false.
Parameters:
p - The reference Point3D with which to compare.
Returns:
true if this Point3D is the same as the p argument; false otherwise.

equals

public boolean equals(float X,
                      float Y,
                      float Z)
Implementation of Object.equals(). Compares two Point3Ds for equality. This operation is reflexive, symmetric, and transitive. For any reference value x, x.equals(null) returns false.
Parameters:
X - The x-axis value with which to compare.
Y - The y-axis value with which to compare.
Z - The z-axis value with which to compare.
Returns:
true if this Point3D is the same as described in the arguments; false otherwise.

set

public Point3D set(Point3D p)
Sets this point as a copy of the given one.
Parameters:
p - The Point3D to copy.
Returns:
Returns a reference to itself.

set

public Point3D set(float X,
                   float Y,
                   float Z)
Sets this point from the given information.
Parameters:
X - The new x-axis value.
Y - The new y-axis value.
Z - The new z-axis value.
Returns:
Returns a reference to itself.

translate

public static void translate(int x,
                             int y)
Adjusts the transform matrix in the (x,y,0) direction. Use this method for the effect of scrolling.
Parameters:
x - Change in the x direction.
y - Change in the y direction.

zoom

public static void zoom(float factor,
                        int halfwidth,
                        int halfheight)
Adjusts the transform matrix in the (0,0,z) direction. Use this method for the effect of zooming in and out.
Parameters:
factor - The magnification factor.
halfwidth - Half the width of the screen, in screenspace
halfheight - Half the height of the screen, in screenspace.

getScale

public static float getScale()
Returns the current scaling value. This is constant until zoom() is called.
Returns:
Scale.