com.cult3d.math
Class Vector2

java.lang.Object
  |
  +--com.cult3d.math.Vector2

public class Vector2
extends java.lang.Object

A two element Vector with x, y coordinates.

Since:
Cult3D 5.2

Constructor Summary
Vector2()
          Constructs and initializes a new vector.
Vector2(float[] array)
          Constructs a new vector and initializes it from the array parameter.
Vector2(float x, float y)
          Constructs a new vector and initializes it to the specified values.
Vector2(Vector2 v)
          Constructs a new vector and initializes it from the vector parameter.
 
Method Summary
 void add(Vector2 v)
          Sets this vector to the sum of itself and the vector parameter.
 void add(Vector2 v1, Vector2 v2)
          Sets this vector to the sum of the two vector parameters.
 float angle(Vector2 v)
          Returns the angle in radians between this vector and the parameter.
 void div(float f)
          Divides this vector with the parameter.
 void div(Vector2 v, float f)
          Sets this vector to the v parameter divided with the f parameter
 float dot(Vector2 v)
          Computes the dot product of itself and the parameter.
 float dot(Vector2 v1, Vector2 v2)
          Computes the dot product of vectors v1 and v2.
 boolean equals(java.lang.Object obj)
          Returns true if the Object obj is of type Vector2 and all of the coordinates of obj are equal to the corresponding coordinates in this Vector2.
 java.lang.String getInfo()
           This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations and versions of Cult3D.
 float getX()
          Gets this vectors x coordinate.
 float getY()
          Gets this vectors y coordinate.
 float length()
          Returns the length of this vector.
 void mult(float f)
          Multiplies this vector with the parameter.
 void mult(Vector2 v, float f)
          Sets this vector to the v parameter multiplied with the f parameter
 void normalize()
          Sets this vector to its normal.
 void normalize(Vector2 v)
          Sets this vector to the parameters normal.
 void rotate(float a)
          Rotates the vector by a specified angle.
 void setVector(float[] array)
          Sets this vector to the values in the array parameter.
 void setVector(float x, float y)
          Sets this vector to the parameter values.
 void setVector(Vector2 v)
          Sets this vector to the same values as the parameter.
 void setX(float x)
          Sets this vectors x coordinate.
 void setY(float y)
          Sets this vectors y coordinate.
 void sub(Vector2 v)
          Sets this vector to the difference of itself and the vector parameter.
 void sub(Vector2 v1, Vector2 v2)
          Sets this vector to the difference of the two vector parameters.
 java.lang.String toString()
           Returns a string representation of the values of this object.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector2

public Vector2()
Constructs and initializes a new vector.
Since:
Cult3D 5.2

Vector2

public Vector2(float x,
               float y)
Constructs a new vector and initializes it to the specified values.
Parameters:
x - the x coordinate
y - the y coordinate
Since:
Cult3D 5.2

Vector2

public Vector2(float[] array)
Constructs a new vector and initializes it from the array parameter.
Parameters:
array - array of length 2
Since:
Cult3D 5.2

Vector2

public Vector2(Vector2 v)
Constructs a new vector and initializes it from the vector parameter.
Parameters:
v - the source vector
Since:
Cult3D 5.2
Method Detail

setVector

public void setVector(float x,
                      float y)
Sets this vector to the parameter values.
Parameters:
x - the x coordinate
y - the y coordinate
Since:
Cult3D 5.2

setVector

public void setVector(float[] array)
Sets this vector to the values in the array parameter.
Parameters:
array - array of length 2
Since:
Cult3D 5.2

setVector

public void setVector(Vector2 v)
Sets this vector to the same values as the parameter.
Parameters:
v - the source vector
Since:
Cult3D 5.2

setX

public void setX(float x)
Sets this vectors x coordinate.
Parameters:
x - the x coordinate
Since:
Cult3D 5.2

setY

public void setY(float y)
Sets this vectors y coordinate.
Parameters:
y - the y coordinate
Since:
Cult3D 5.2

getX

public float getX()
Gets this vectors x coordinate.
Returns:
the x coordinate
Since:
Cult3D 5.2

getY

public float getY()
Gets this vectors y coordinate.
Returns:
the y coordinate
Since:
Cult3D 5.2

add

public void add(Vector2 v)
Sets this vector to the sum of itself and the vector parameter.
Parameters:
v - the vector to add
Since:
Cult3D 5.2

add

public void add(Vector2 v1,
                Vector2 v2)
Sets this vector to the sum of the two vector parameters.
Parameters:
v1 - the first vector to add
v2 - the second vector to add
Since:
Cult3D 5.2

sub

public void sub(Vector2 v)
Sets this vector to the difference of itself and the vector parameter.
Parameters:
v - the vector to subtract
Since:
Cult3D 5.2

sub

public void sub(Vector2 v1,
                Vector2 v2)
Sets this vector to the difference of the two vector parameters.
Parameters:
v1 - the first vector
v2 - the second vector
Since:
Cult3D 5.2

div

public void div(float f)
Divides this vector with the parameter.
Parameters:
f - value to divide with.
Since:
Cult3D 5.2

div

public void div(Vector2 v,
                float f)
Sets this vector to the v parameter divided with the f parameter
Parameters:
v - the vector to divide
f - value to divide with.
Since:
Cult3D 5.2

mult

public void mult(float f)
Multiplies this vector with the parameter.
Parameters:
f - value to multiplie with.
Since:
Cult3D 5.2

mult

public void mult(Vector2 v,
                 float f)
Sets this vector to the v parameter multiplied with the f parameter
Parameters:
v - the vector to multiplie
f - value to multiplie with.
Since:
Cult3D 5.2

dot

public float dot(Vector2 v)
Computes the dot product of itself and the parameter.
Parameters:
v - the vector
Returns:
the dot product
Since:
Cult3D 5.2

dot

public float dot(Vector2 v1,
                 Vector2 v2)
Computes the dot product of vectors v1 and v2.
Parameters:
v1 - the first vector
v2 - the second vector
Returns:
the dot product
Since:
Cult3D 5.2

length

public final float length()
Returns the length of this vector.
Returns:
the length of this vector
Since:
Cult3D 5.2

normalize

public final void normalize()
Sets this vector to its normal.
Since:
Cult3D 5.2

normalize

public final void normalize(Vector2 v)
Sets this vector to the parameters normal.
Parameters:
v - the vector to normalize.
Since:
Cult3D 5.2

angle

public final float angle(Vector2 v)
Returns the angle in radians between this vector and the parameter.
Parameters:
v - the other vector.
Returns:
the angle in radians.
Since:
Cult3D 5.2

rotate

public final void rotate(float a)
Rotates the vector by a specified angle.
Parameters:
a - angle to roatate the vector
Since:
Cult3D 5.2

equals

public boolean equals(java.lang.Object obj)
Returns true if the Object obj is of type Vector2 and all of the coordinates of obj are equal to the corresponding coordinates in this Vector2.
Overrides:
equals in class java.lang.Object
Since:
Cult3D 5.2

getInfo

public java.lang.String getInfo()

This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations and versions of Cult3D.

Returns:
A string representing this object.
Since:
Cult3D 5.3

toString

public java.lang.String toString()

Returns a string representation of the values of this object.

The string contains the name of this class and the current x,y values of this vector.

This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations and versions of Cult3D.

Overrides:
toString in class java.lang.Object
Returns:
A string representing this object.