glmodel
Class GL_Vector

java.lang.Object
  extended by glmodel.GL_Vector

public class GL_Vector
extends java.lang.Object

A 3D vector, with functions to perform common vector math operations.


Field Summary
 float x
           
 float y
           
 float z
           
 
Constructor Summary
GL_Vector()
          Create a 0,0,0 vector
GL_Vector(float[] float3)
          Create a vector from the given float[3] xyz values
GL_Vector(float xpos, float ypos, float zpos)
          Create a vector with the given xyz values
GL_Vector(GL_Vector v)
          Create a vector that duplicates the given vector
GL_Vector(GL_Vector point1, GL_Vector point2)
          Create a vector from point1 to point2
 
Method Summary
 GL_Vector add(float n)
          Add a value to this vector
 GL_Vector add(GL_Vector v)
          Add a vector to this vector
static GL_Vector add(GL_Vector a, GL_Vector b)
          Return a+b as a new vector
static float angle(GL_Vector a, GL_Vector b)
          returns the angle between 2 vectors
static float angleXY(GL_Vector a, GL_Vector b)
          returns the angle between 2 vectors on the XY plane.
static float angleXZ(GL_Vector a, GL_Vector b)
          returns the angle between 2 vectors on the XZ plane.
static GL_Vector crossProduct(GL_Vector a, GL_Vector b)
          Return the cross product of the two vectors, as a new vector.
 GL_Vector div(float n)
          Divide vector by a value
 GL_Vector div(GL_Vector v)
          Divide this vector by another vector
static GL_Vector div(GL_Vector a, GL_Vector b)
          Return a/b as a new vector
static float dotProduct(GL_Vector u, GL_Vector v)
          return the dot product of two vectors
 boolean equals(GL_Vector v)
          Return true if this vector has the same xyz values as the argument vector
 GL_Vector getClone()
          Return a copy of the vector
static GL_Vector getNormal(GL_Vector a, GL_Vector b)
          returns the normal vector of the plane defined by the a and b vectors
static GL_Vector getNormal(GL_Vector a, GL_Vector b, GL_Vector c)
          returns the normal vector from the three vectors
 float length()
          Return the length of the vector.
static float length(GL_Vector a)
          Return the length of the given vector
 GL_Vector mult(float n)
          Multiply vector by a value
 GL_Vector mult(GL_Vector v)
          Multiply this vector by another vector
static GL_Vector mult(GL_Vector a, GL_Vector b)
          Return a*b as a new vector
static GL_Vector multiply(GL_Vector v, float r)
          Return the given vector multiplied by the given numeric value, as a new vector
 GL_Vector normalize()
          Normalize the vector (make its length 0).
static GL_Vector normalize(GL_Vector v)
          Return the normalized vector as a new vector
 GL_Vector reverse()
          Reverse the vector
static GL_Vector rotationVector(float degrees)
          return a vector rotated the given number of degrees around the Y axis
static GL_Vector scale(GL_Vector a, float f)
          Return a new vector scaled by the given factor
 GL_Vector sub(float n)
          Subtract a value from this vector
 GL_Vector sub(GL_Vector v)
          Subtract vector from this vector
static GL_Vector sub(GL_Vector a, GL_Vector b)
          Return a-b as a new vector
 java.lang.String toString()
          Return a string representation of the vector
static GL_Vector vectorProduct(GL_Vector a, GL_Vector b)
          returns a x b
static GL_Vector vectorProduct(GL_Vector a, GL_Vector b, GL_Vector c)
          returns (b-a) x (c-a)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x

y

public float y

z

public float z
Constructor Detail

GL_Vector

public GL_Vector()
Create a 0,0,0 vector


GL_Vector

public GL_Vector(float xpos,
                 float ypos,
                 float zpos)
Create a vector with the given xyz values


GL_Vector

public GL_Vector(float[] float3)
Create a vector from the given float[3] xyz values


GL_Vector

public GL_Vector(GL_Vector v)
Create a vector that duplicates the given vector


GL_Vector

public GL_Vector(GL_Vector point1,
                 GL_Vector point2)
Create a vector from point1 to point2

Method Detail

add

public GL_Vector add(GL_Vector v)
Add a vector to this vector


sub

public GL_Vector sub(GL_Vector v)
Subtract vector from this vector


mult

public GL_Vector mult(GL_Vector v)
Multiply this vector by another vector


div

public GL_Vector div(GL_Vector v)
Divide this vector by another vector


add

public GL_Vector add(float n)
Add a value to this vector


sub

public GL_Vector sub(float n)
Subtract a value from this vector


mult

public GL_Vector mult(float n)
Multiply vector by a value


div

public GL_Vector div(float n)
Divide vector by a value


normalize

public GL_Vector normalize()
Normalize the vector (make its length 0).


reverse

public GL_Vector reverse()
Reverse the vector


length

public float length()
Return the length of the vector.


toString

public java.lang.String toString()
Return a string representation of the vector

Overrides:
toString in class java.lang.Object

getClone

public GL_Vector getClone()
Return a copy of the vector


equals

public boolean equals(GL_Vector v)
Return true if this vector has the same xyz values as the argument vector


add

public static GL_Vector add(GL_Vector a,
                            GL_Vector b)
Return a+b as a new vector


sub

public static GL_Vector sub(GL_Vector a,
                            GL_Vector b)
Return a-b as a new vector


mult

public static GL_Vector mult(GL_Vector a,
                             GL_Vector b)
Return a*b as a new vector


div

public static GL_Vector div(GL_Vector a,
                            GL_Vector b)
Return a/b as a new vector


multiply

public static GL_Vector multiply(GL_Vector v,
                                 float r)
Return the given vector multiplied by the given numeric value, as a new vector


scale

public static GL_Vector scale(GL_Vector a,
                              float f)
Return a new vector scaled by the given factor


length

public static float length(GL_Vector a)
Return the length of the given vector


dotProduct

public static float dotProduct(GL_Vector u,
                               GL_Vector v)
return the dot product of two vectors


normalize

public static GL_Vector normalize(GL_Vector v)
Return the normalized vector as a new vector


crossProduct

public static GL_Vector crossProduct(GL_Vector a,
                                     GL_Vector b)
Return the cross product of the two vectors, as a new vector. The returned vector is perpendicular to the plane created by a and b.


getNormal

public static GL_Vector getNormal(GL_Vector a,
                                  GL_Vector b)
returns the normal vector of the plane defined by the a and b vectors


getNormal

public static GL_Vector getNormal(GL_Vector a,
                                  GL_Vector b,
                                  GL_Vector c)
returns the normal vector from the three vectors


vectorProduct

public static GL_Vector vectorProduct(GL_Vector a,
                                      GL_Vector b)
returns a x b


vectorProduct

public static GL_Vector vectorProduct(GL_Vector a,
                                      GL_Vector b,
                                      GL_Vector c)
returns (b-a) x (c-a)


angle

public static float angle(GL_Vector a,
                          GL_Vector b)
returns the angle between 2 vectors


angleXZ

public static float angleXZ(GL_Vector a,
                            GL_Vector b)
returns the angle between 2 vectors on the XZ plane. angle is 0-360 where the 0/360 divide is directly in front of the A vector Ie. when A is pointing directly at B, angle will be 0. If B moves one degree to the right, angle will be 1, If B moves one degree to the left, angle will be 360. right side is 0-180, left side is 360-180


angleXY

public static float angleXY(GL_Vector a,
                            GL_Vector b)
returns the angle between 2 vectors on the XY plane. angle is 0-360 where the 0/360 divide is directly in front of the A vector Ie. when A is pointing directly at B, angle will be 0. If B moves one degree to the right, angle will be 1, If B moves one degree to the left, angle will be 360. right side is 0-180, left side is 360-180


rotationVector

public static GL_Vector rotationVector(float degrees)
return a vector rotated the given number of degrees around the Y axis