public final class Vector2f extends java.lang.Object implements Savable, java.lang.Cloneable, java.io.Serializable
Vector2f
defines a Vector for a two float value vector.Modifier and Type | Field and Description |
---|---|
static Vector2f |
UNIT_XY
shared instance of the all-ones vector (1,1) - Do not modify!
|
float |
x
the x value of the vector.
|
float |
y
the y value of the vector.
|
static Vector2f |
ZERO
shared instance of the all-zero vector (0,0) - Do not modify!
|
Constructor and Description |
---|
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
|
Modifier and Type | Method and Description |
---|---|
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. |
float |
angleBetween(Vector2f otherVector)
angleBetween returns (in radians) the angle required to
rotate a ray represented by this vector to be collinear with a ray
described by the given vector. |
Vector2f |
clone()
Create a copy of this vector.
|
Vector3f |
cross(Vector2f v)
cross calculates the cross product of this vector with a
parameter vector v. |
float |
determinant(Vector2f v) |
float |
distance(Vector2f v)
distance calculates the distance between this vector and
vector v. |
float |
distanceSquared(float otherX,
float otherY)
distanceSquared calculates the distance squared between
this vector and vector v. |
float |
distanceSquared(Vector2f v)
distanceSquared calculates the distance squared between
this vector and 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 if they have the same x and
y values.
|
float |
getAngle()
getAngle returns (in radians) the angle represented by
this Vector2f as expressed by a conversion from rectangular coordinates (x , y )
to polar coordinates (r, theta). |
float |
getX()
Determine the X component of this vector.
|
float |
getY()
Determine the Y component of this vector.
|
int |
hashCode()
hashCode returns a unique code for this vector object
based on its values. |
Vector2f |
interpolateLocal(Vector2f finalVec,
float changeAmnt)
Sets this vector to the interpolation by changeAmnt from this to the
finalVec this=(1-changeAmnt)*this + changeAmnt * finalVec
|
Vector2f |
interpolateLocal(Vector2f beginVec,
Vector2f finalVec,
float changeAmnt)
Sets this vector to the interpolation by changeAmnt from beginVec to
finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
|
boolean |
isSimilar(Vector2f other,
float epsilon)
Returns true if this vector is similar to the specified vector within
some value of epsilon.
|
static boolean |
isValidVector(Vector2f vector)
Check a vector...
|
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 by 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 |
read(JmeImporter e)
De-serialize this vector from the specified importer, for example
when loading from a J3O file.
|
void |
readExternal(java.io.ObjectInput in)
Used with serialization.
|
void |
rotateAroundOrigin(float angle,
boolean cw) |
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 |
setX(float x)
Alter the X component of this vector.
|
Vector2f |
setY(float y)
Alter the Y component of this vector.
|
float |
smallestAngleBetween(Vector2f otherVector)
smallestAngleBetween returns (in radians) the minimum
angle between two vectors. |
Vector2f |
subtract(float valX,
float valY)
subtract subtracts the given x,y values from those of this
vector creating a new vector object. |
Vector2f |
subtract(Vector2f vec)
subtract subtracts the values of a given vector from those
of this vector creating a new vector object. |
Vector2f |
subtract(Vector2f vec,
Vector2f store)
subtract subtracts the values of a given vector from those
of this vector storing the result in the given vector object. |
Vector2f |
subtractLocal(float valX,
float valY)
subtractLocal subtracts the provided values from this
vector internally, and returns a handle to this vector for easy chaining
of calls. |
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. |
float[] |
toArray(float[] floats)
Saves this Vector2f into the given float[] object.
|
java.lang.String |
toString()
toString returns a string representation of this vector. |
void |
write(JmeExporter e)
Serialize this vector to the specified exporter, for example when
saving to a J3O file.
|
void |
writeExternal(java.io.ObjectOutput out)
Used with serialization.
|
Vector2f |
zero()
zero resets this vector's data to zero internally. |
public static final Vector2f ZERO
public static final Vector2f UNIT_XY
public float x
public float y
public Vector2f(float x, float y)
x
- The x value of this Vector2f.y
- The y value of this Vector2f.public Vector2f()
public Vector2f(Vector2f vector2f)
vector2f
- The vector to copypublic Vector2f set(float x, float y)
x
- the x value of the vector.y
- the y value of the vector.public Vector2f set(Vector2f vec)
vec
- the vector to copy frompublic 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.vec
- the vector to add to this.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.vec
- the vector to add to this vector.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.addX
- value to add to xaddY
- value to add to ypublic Vector2f add(Vector2f vec, Vector2f result)
add
adds this vector by vec
and stores the
result in result
.vec
- The vector to add.result
- The vector to store the result in.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.vec
- the vector to dot with this vector.public Vector3f cross(Vector2f v)
cross
calculates the cross product of this vector with a
parameter vector v.v
- the vector to take the cross product of with this.public float determinant(Vector2f v)
public Vector2f interpolateLocal(Vector2f finalVec, float changeAmnt)
finalVec
- The final vector to interpolate towardschangeAmnt
- An amount between 0.0 - 1.0 representing a percentage change
from this towards finalVecpublic Vector2f interpolateLocal(Vector2f beginVec, Vector2f finalVec, float changeAmnt)
beginVec
- The beginning vector (delta=0)finalVec
- The final vector to interpolate towards (delta=1)changeAmnt
- An amount between 0.0 - 1.0 representing a percentage change
from beginVec towards finalVecpublic static boolean isValidVector(Vector2f vector)
vector
- the vector to checkpublic float length()
length
calculates the magnitude of this vector.public float lengthSquared()
lengthSquared
calculates the squared value of the
magnitude of the vector.public float distanceSquared(Vector2f v)
distanceSquared
calculates the distance squared between
this vector and vector v.v
- the second vector to determine the distance squared.public float distanceSquared(float otherX, float otherY)
distanceSquared
calculates the distance squared between
this vector and vector v.otherX
- The X coordinate of the v vectorotherY
- The Y coordinate of the v vectorpublic float distance(Vector2f v)
distance
calculates the distance between this vector and
vector v.v
- the second vector to determine the distance.public Vector2f mult(float scalar)
mult
multiplies this vector by a scalar. The resultant
vector is returned.scalar
- the value to multiply this vector by.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.scalar
- the value to multiply this vector by.public Vector2f multLocal(Vector2f vec)
multLocal
multiplies a provided vector by this vector
internally, and returns a handle to this vector for easy chaining of
calls. If the provided vector is null, null is returned.vec
- the vector to mult to this vector.public Vector2f mult(float scalar, Vector2f product)
scalar
- The scalar to multiply by.product
- The vector2f to store the result in.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.scalar
- the value to divide this vectors attributes by.Vector
.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.scalar
- the value to divides this vector by.public Vector2f negate()
negate
returns the negative of this vector. All values are
negated and set to a new vector.public Vector2f negateLocal()
negateLocal
negates the internal values of this vector.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, an exception is thrown.vec
- the vector to subtract from this vector.public Vector2f subtract(Vector2f vec, Vector2f store)
subtract
subtracts the values of a given vector from those
of this vector storing the result in the given vector object. If the
provided vector is null, an exception is thrown.vec
- the vector to subtract from this vector.store
- the vector to store the result in. It is safe for this to be
the same as vec. If null, a new vector is created.public Vector2f subtract(float valX, float valY)
subtract
subtracts the given x,y values from those of this
vector creating a new vector object.valX
- value to subtract from xvalY
- value to subtract from ypublic 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.vec
- the vector to subtractpublic Vector2f subtractLocal(float valX, float valY)
subtractLocal
subtracts the provided values from this
vector internally, and returns a handle to this vector for easy chaining
of calls.valX
- value to subtract from xvalY
- value to subtract from ypublic Vector2f normalize()
normalize
returns the unit vector of this vector.public Vector2f normalizeLocal()
normalizeLocal
makes this vector into a unit vector of
itself.public float smallestAngleBetween(Vector2f otherVector)
smallestAngleBetween
returns (in radians) the minimum
angle between two vectors. It is assumed that both this vector and the
given vector are unit vectors (iow, normalized).otherVector
- a unit vector to find the angle againstpublic float angleBetween(Vector2f otherVector)
angleBetween
returns (in radians) the angle required to
rotate a ray represented by this vector to be collinear with a ray
described by the given vector. It is assumed that both this vector and
the given vector are unit vectors (iow, normalized).otherVector
- the "destination" unit vectorpublic float getX()
public Vector2f setX(float x)
x
- the desired valuepublic float getY()
public Vector2f setY(float y)
y
- the desired valuepublic float getAngle()
getAngle
returns (in radians) the angle represented by
this Vector2f as expressed by a conversion from rectangular coordinates (x
, y
)
to polar coordinates (r, theta).public Vector2f zero()
zero
resets this vector's data to zero internally.public int hashCode()
hashCode
returns a unique code for this vector object
based on its values. If two vectors are logically equivalent, they will
return the same hash code value.hashCode
in class java.lang.Object
public Vector2f clone()
clone
in class java.lang.Object
public float[] toArray(float[] floats)
floats
- The float[] to take this Vector2f. If null, a new float[2] is
created.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the object to compare for equalitypublic boolean isSimilar(Vector2f other, float epsilon)
other
- the vector to compare with (not null, unaffected)epsilon
- the desired error tolerance for each componentpublic java.lang.String toString()
toString
returns a string representation of this vector.
The format is:
(XX.XXXX, YY.YYYY)toString
in class java.lang.Object
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
in
- ObjectInputjava.io.IOException
- if an I/O error occursjava.lang.ClassNotFoundException
- when?Externalizable
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
out
- ObjectOutputjava.io.IOException
- if an I/O error occursExternalizable
public void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter e) throws java.io.IOException
public void rotateAroundOrigin(float angle, boolean cw)