com.jme.math
Class Vector2f

java.lang.Object
  extended bycom.jme.math.Vector2f
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable

public class Vector2f
extends java.lang.Object
implements java.io.Externalizable

Vector2f defines a Vector for a two float value vector.

Version:
$Id: Vector2f.java,v 1.14 2004/09/14 21:52:20 mojomonkey Exp $
Author:
Mark Powell, Joshua Slack
See Also:
Serialized Form

Field Summary
 float x
          the x value of the vector.
 float y
          the y value of the vector.
 
Constructor Summary
Vector2f()
          Creates a Vector2f with x and y set to 0.
Vector2f(float x, float y)
          Creates a Vector2f with the given initial x and y values.
Vector2f(Vector2f vector2f)
          Creates a new Vector2f that contains the passed vector's information
 
Method Summary
 Vector2f add(Vector2f vec)
          add adds a provided vector to this vector creating a resultant vector which is returned.
 Vector2f add(Vector2f vec, Vector2f result)
          add adds this vector by vec and stores the result in result.
 Vector2f addLocal(float addX, float addY)
          addLocal adds the provided values to this vector internally, and returns a handle to this vector for easy chaining of calls.
 Vector2f addLocal(Vector2f vec)
          addLocal adds a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls.
 java.lang.Object clone()
          clone creates a new Vector2f object containing the same data as this one.
 Vector3f cross(Vector2f v)
          cross calculates the cross product of this vector with a parameter vector v.
 Vector2f divide(float scalar)
          divide divides the values of this vector by a scalar and returns the result.
 Vector2f divideLocal(float scalar)
          divideLocal divides this vector by a scalar internally, and returns a handle to this vector for easy chaining of calls.
 float dot(Vector2f vec)
          dot calculates the dot product of this vector with a provided vector.
 boolean equals(java.lang.Object o)
          are these two vectors the same? they are is they both have the same x and y values.
 int hashCode()
          hashCode returns a unique code for this vector object based on it's values.
 void interpolate(Vector2f finalVec, float changeAmnt)
          Sets this vector to the interpolation by changeAmnt from this to the finalVec this=(1-changeAmnt)*this + changeAmnt * finalVec
 void interpolate(Vector2f beginVec, Vector2f finalVec, float changeAmnt)
          Sets this vector to the interpolation by changeAmnt from beginVec to finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
 float length()
          length calculates the magnitude of this vector.
 float lengthSquared()
          lengthSquared calculates the squared value of the magnitude of the vector.
 Vector2f mult(float scalar)
          mult multiplies this vector by a scalar.
 Vector2f mult(float scalar, Vector2f product)
          Multiplies this Vector2f's x and y by the scalar and stores the result in product.
 Vector2f multLocal(float scalar)
          multLocal multiplies this vector by a scalar internally, and returns a handle to this vector for easy chaining of calls.
 Vector2f multLocal(Vector2f vec)
          multLocal multiplies a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls.
 Vector2f negate()
          negate returns the negative of this vector.
 Vector2f negateLocal()
          negateLocal negates the internal values of this vector.
 Vector2f normalize()
          normalize returns the unit vector of this vector.
 Vector2f normalizeLocal()
          normalizeLocal makes this vector into a unit vector of itself.
 void readExternal(java.io.ObjectInput in)
          Used with serialization.
 Vector2f set(float x, float y)
          set the x and y values of the vector
 Vector2f set(Vector2f vec)
          set the x and y values of the vector from another vector
 Vector2f subtract(Vector2f vec)
          subtract subtracts the values of a given vector from those of this vector creating a new vector object.
 Vector2f subtractLocal(Vector2f vec)
          subtractLocal subtracts a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls.
 java.lang.String toString()
          toString returns the string representation of this vector object.
 void writeExternal(java.io.ObjectOutput out)
          Used with serialization.
 void zero()
          zero resets this vector's data to zero internally.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x
the x value of the vector.


y

public float y
the y value of the vector.

Constructor Detail

Vector2f

public Vector2f(float x,
                float y)
Creates a Vector2f with the given initial x and y values.

Parameters:
x - The x value of this Vector2f.
y - The y value of this Vector2f.

Vector2f

public Vector2f()
Creates a Vector2f with x and y set to 0. Equivalent to Vector2f(0,0).


Vector2f

public Vector2f(Vector2f vector2f)
Creates a new Vector2f that contains the passed vector's information

Parameters:
vector2f - The vector to copy
Method Detail

set

public Vector2f set(float x,
                    float y)
set the x and y values of the vector

Parameters:
x - the x value of the vector.
y - the y value of the vector.
Returns:
this vector

set

public Vector2f set(Vector2f vec)
set the x and y values of the vector from another vector

Parameters:
vec - the vector to copy from
Returns:
this vector

add

public Vector2f add(Vector2f vec)
add adds a provided vector to this vector creating a resultant vector which is returned. If the provided vector is null, null is returned.

Parameters:
vec - the vector to add to this.
Returns:
the resultant vector.

addLocal

public Vector2f addLocal(Vector2f vec)
addLocal adds a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls. If the provided vector is null, null is returned.

Parameters:
vec - the vector to add to this vector.
Returns:
this

addLocal

public Vector2f addLocal(float addX,
                         float addY)
addLocal adds the provided values to this vector internally, and returns a handle to this vector for easy chaining of calls.

Parameters:
addX - value to add to x
addY - value to add to y
Returns:
this

add

public Vector2f add(Vector2f vec,
                    Vector2f result)
add adds this vector by vec and stores the result in result.

Parameters:
vec - The vector to add.
result - The vector to store the result in.
Returns:
The result vector, after adding.

dot

public float dot(Vector2f vec)
dot calculates the dot product of this vector with a provided vector. If the provided vector is null, 0 is returned.

Parameters:
vec - the vector to dot with this vector.
Returns:
the resultant dot product of this vector and a given vector.

cross

public Vector3f cross(Vector2f v)
cross calculates the cross product of this vector with a parameter vector v.

Parameters:
v - the vector to take the cross product of with this.
Returns:
the cross product vector.

interpolate

public void interpolate(Vector2f finalVec,
                        float changeAmnt)
Sets this vector to the interpolation by changeAmnt from this to the finalVec this=(1-changeAmnt)*this + changeAmnt * finalVec

Parameters:
finalVec - The final vector to interpolate towards
changeAmnt - An amount between 0.0 - 1.0 representing a precentage change from this towards finalVec

interpolate

public void interpolate(Vector2f beginVec,
                        Vector2f finalVec,
                        float changeAmnt)
Sets this vector to the interpolation by changeAmnt from beginVec to finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec

Parameters:
beginVec - The begining vector (delta=0)
finalVec - The final vector to interpolate towards (delta=1)
changeAmnt - An amount between 0.0 - 1.0 representing a precentage change from beginVec towards finalVec

length

public float length()
length calculates the magnitude of this vector.

Returns:
the length or magnitude of the vector.

lengthSquared

public float lengthSquared()
lengthSquared calculates the squared value of the magnitude of the vector.

Returns:
the magnitude squared of the vector.

mult

public Vector2f mult(float scalar)
mult multiplies this vector by a scalar. The resultant vector is returned.

Parameters:
scalar - the value to multiply this vector by.
Returns:
the new vector.

multLocal

public Vector2f multLocal(float scalar)
multLocal multiplies this vector by a scalar internally, and returns a handle to this vector for easy chaining of calls.

Parameters:
scalar - the value to multiply this vector by.
Returns:
this

multLocal

public Vector2f multLocal(Vector2f vec)
multLocal multiplies a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls. If the provided vector is null, null is returned.

Parameters:
vec - the vector to mult to this vector.
Returns:
this

mult

public Vector2f mult(float scalar,
                     Vector2f product)
Multiplies this Vector2f's x and y by the scalar and stores the result in product. The result is returned for chaining. Similar to product=this*scalar;

Parameters:
scalar - The scalar to multiply by.
product - The vector2f to store the result in.
Returns:
product, after multiplication.

divide

public Vector2f divide(float scalar)
divide divides the values of this vector by a scalar and returns the result. The values of this vector remain untouched.

Parameters:
scalar - the value to divide this vectors attributes by.
Returns:
the result Vector.

divideLocal

public Vector2f divideLocal(float scalar)
divideLocal divides this vector by a scalar internally, and returns a handle to this vector for easy chaining of calls. Dividing by zero will result in an exception.

Parameters:
scalar - the value to divides this vector by.
Returns:
this

negate

public Vector2f negate()
negate returns the negative of this vector. All values are negated and set to a new vector.

Returns:
the negated vector.

negateLocal

public Vector2f negateLocal()
negateLocal negates the internal values of this vector.

Returns:
this.

subtract

public Vector2f subtract(Vector2f vec)
subtract subtracts the values of a given vector from those of this vector creating a new vector object. If the provided vector is null, null is returned.

Parameters:
vec - the vector to subtract from this vector.
Returns:
the result vector.

subtractLocal

public Vector2f subtractLocal(Vector2f vec)
subtractLocal subtracts a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls. If the provided vector is null, null is returned.

Parameters:
vec - the vector to subtract
Returns:
this

normalize

public Vector2f normalize()
normalize returns the unit vector of this vector.

Returns:
unit vector of this vector.

normalizeLocal

public Vector2f normalizeLocal()
normalizeLocal makes this vector into a unit vector of itself.

Returns:
this.

zero

public void zero()
zero resets this vector's data to zero internally.


hashCode

public int hashCode()
hashCode returns a unique code for this vector object based on it's values. If two vectors are logically equivalent, they will return the same hash code value.

Returns:
the hash code value of this vector.

clone

public java.lang.Object clone()
clone creates a new Vector2f object containing the same data as this one.

Returns:
the new Vector2f

equals

public boolean equals(java.lang.Object o)
are these two vectors the same? they are is they both have the same x and y values.

Parameters:
o - the object to compare for equality
Returns:
true if they are equal

toString

public java.lang.String toString()
toString returns the string representation of this vector object. The format of the string is such: com.jme.math.Vector2f [X=XX.XXXX, Y=YY.YYYY]

Returns:
the string representation of this vector.

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Used with serialization. Not to be called manually.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - ObjectInput
Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
Externalizable

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Used with serialization. Not to be called manually.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - ObjectOutput
Throws:
java.io.IOException
See Also:
Externalizable