public final class Vector3f extends java.lang.Object implements Savable, java.lang.Cloneable, java.io.Serializable
Vector3f
defines a Vector for a three float value tuple.
Vector3f
can represent any three dimensional value, such as a
vertex, a normal, etc. Utility methods are also included to aid in
mathematical calculations.Modifier and Type | Field and Description |
---|---|
static Vector3f |
NAN
shared instance of the all-NaN vector (NaN,NaN,NaN) - Do not modify!
|
static Vector3f |
NEGATIVE_INFINITY
shared instance of the all-negative-infinity vector (-Inf,-Inf,-Inf)
- Do not modify!
|
static Vector3f |
POSITIVE_INFINITY
shared instance of the all-plus-infinity vector (+Inf,+Inf,+Inf)
- Do not modify!
|
static Vector3f |
UNIT_X
shared instance of the +X direction (1,0,0) - Do not modify!
|
static Vector3f |
UNIT_XYZ
shared instance of the all-ones vector (1,1,1) - Do not modify!
|
static Vector3f |
UNIT_Y
shared instance of the +Y direction (0,1,0) - Do not modify!
|
static Vector3f |
UNIT_Z
shared instance of the +Z direction (0,0,1) - Do not modify!
|
float |
x
the x value of the vector.
|
float |
y
the y value of the vector.
|
float |
z
the z value of the vector.
|
static Vector3f |
ZERO
shared instance of the all-zero vector (0,0,0) - Do not modify!
|
Constructor and Description |
---|
Vector3f()
Constructor instantiates a new
Vector3f with default
values of (0,0,0). |
Vector3f(float x,
float y,
float z)
Constructor instantiates a new
Vector3f with provides
values. |
Vector3f(Vector3f copy)
Constructor instantiates a new
Vector3f that is a copy
of the provided vector |
Modifier and Type | Method and Description |
---|---|
Vector3f |
add(float addX,
float addY,
float addZ)
add adds the provided values to this vector, creating a
new vector that is then returned. |
Vector3f |
add(Vector3f vec)
add adds a provided vector to this vector creating a
resultant vector which is returned. |
Vector3f |
add(Vector3f vec,
Vector3f result)
add adds the values of a provided vector storing the
values in the supplied vector. |
Vector3f |
addLocal(float addX,
float addY,
float addZ)
addLocal adds the provided values to this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector3f |
addLocal(Vector3f vec)
addLocal adds a provided vector to this vector internally,
and returns a handle to this vector for easy chaining of calls. |
float |
angleBetween(Vector3f otherVector)
angleBetween returns (in radians) the angle between two vectors. |
Vector3f |
clone()
Create a copy of this vector.
|
Vector3f |
cross(float otherX,
float otherY,
float otherZ,
Vector3f result)
cross calculates the cross product of this vector with a
parameter vector v. |
Vector3f |
cross(Vector3f v)
cross calculates the cross product of this vector with a
parameter vector v. |
Vector3f |
cross(Vector3f v,
Vector3f result)
cross calculates the cross product of this vector with a
parameter vector v. |
Vector3f |
crossLocal(float otherX,
float otherY,
float otherZ)
crossLocal calculates the cross product of this vector
with a parameter vector v. |
Vector3f |
crossLocal(Vector3f v)
crossLocal calculates the cross product of this vector
with a parameter vector v. |
float |
distance(Vector3f v)
distance calculates the distance between this vector and
vector v. |
float |
distanceSquared(Vector3f v)
distanceSquared calculates the distance squared between
this vector and vector v. |
Vector3f |
divide(float scalar)
divide divides the values of this vector by a scalar and
returns the result. |
Vector3f |
divide(Vector3f scalar)
divide divides the values of this vector by a scalar and
returns the result. |
Vector3f |
divideLocal(float scalar)
divideLocal divides this vector by a scalar internally,
and returns a handle to this vector for easy chaining of calls. |
Vector3f |
divideLocal(Vector3f scalar)
divideLocal divides this vector by a scalar internally,
and returns a handle to this vector for easy chaining of calls. |
float |
dot(Vector3f 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,y,
and z values.
|
static void |
generateComplementBasis(Vector3f u,
Vector3f v,
Vector3f w) |
static void |
generateOrthonormalBasis(Vector3f u,
Vector3f v,
Vector3f w) |
float |
get(int index) |
float |
getX()
Determine the X component of this vector.
|
float |
getY()
Determine the Y component of this vector.
|
float |
getZ()
Determine the Z component of this vector.
|
int |
hashCode()
hashCode returns a unique code for this vector object based
on its values. |
Vector3f |
interpolateLocal(Vector3f finalVec,
float changeAmnt)
Sets this vector to the interpolation by changeAmnt from this to the finalVec
this=(1-changeAmnt)*this + changeAmnt * finalVec
|
Vector3f |
interpolateLocal(Vector3f beginVec,
Vector3f finalVec,
float changeAmnt)
Sets this vector to the interpolation by changeAmnt from beginVec to finalVec
this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
|
boolean |
isSimilar(Vector3f other,
float epsilon)
Returns true if this vector is similar to the specified vector within
some value of epsilon.
|
boolean |
isUnitVector()
Returns true if this vector is a unit vector (length() ~= 1),
returns false otherwise.
|
static boolean |
isValidVector(Vector3f 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. |
Vector3f |
maxLocal(Vector3f other)
maxLocal computes the maximum value for each
component in this and other vector. |
Vector3f |
minLocal(Vector3f other)
minLocal computes the minimum value for each
component in this and other vector. |
Vector3f |
mult(float scalar)
mult multiplies this vector by a scalar. |
Vector3f |
mult(float scalar,
Vector3f product)
mult multiplies this vector by a scalar. |
Vector3f |
mult(Vector3f vec)
multLocal multiplies a provided vector to this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector3f |
mult(Vector3f vec,
Vector3f store)
multLocal multiplies a provided vector to this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector3f |
multLocal(float scalar)
multLocal multiplies this vector by a scalar internally,
and returns a handle to this vector for easy chaining of calls. |
Vector3f |
multLocal(float x,
float y,
float z)
multLocal multiplies this vector by 3 scalars
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector3f |
multLocal(Vector3f vec)
multLocal multiplies a provided vector to this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector3f |
negate()
negate returns the negative of this vector. |
Vector3f |
negateLocal()
negateLocal negates the internal values of this vector. |
Vector3f |
normalize()
normalize returns the unit vector of this vector. |
Vector3f |
normalizeLocal()
normalizeLocal makes this vector into a unit vector of
itself. |
Vector3f |
project(Vector3f other)
Projects this vector onto another vector
|
Vector3f |
projectLocal(Vector3f other)
Projects this vector onto another vector, stores the result in this
vector
|
void |
read(JmeImporter e)
De-serialize this vector from the specified importer, for example
when loading from a J3O file.
|
Vector3f |
scaleAdd(float scalar,
Vector3f add)
scaleAdd multiplies this vector by a scalar then adds the
given Vector3f. |
Vector3f |
scaleAdd(float scalar,
Vector3f mult,
Vector3f add)
scaleAdd multiplies the given vector by a scalar then adds
the given vector. |
Vector3f |
set(float x,
float y,
float z)
set sets the x,y,z values of the vector based on passed
parameters. |
void |
set(int index,
float value) |
Vector3f |
set(Vector3f vect)
set sets the x,y,z values of the vector by copying the
supplied vector. |
Vector3f |
setX(float x)
Alter the X component of this vector.
|
Vector3f |
setY(float y)
Alter the Y component of this vector.
|
Vector3f |
setZ(float z)
Alter the Z component of this vector.
|
Vector3f |
subtract(float subtractX,
float subtractY,
float subtractZ)
subtract subtracts the provided values from this vector,
creating a new vector that is then returned. |
Vector3f |
subtract(Vector3f vec)
subtract subtracts the values of a given vector from those
of this vector creating a new vector object. |
Vector3f |
subtract(Vector3f vec,
Vector3f result)
subtract |
Vector3f |
subtractLocal(float subtractX,
float subtractY,
float subtractZ)
subtractLocal subtracts the provided values from this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector3f |
subtractLocal(Vector3f 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 Vector3f 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.
|
Vector3f |
zero()
zero resets this vector's data to zero internally. |
public static final Vector3f ZERO
public static final Vector3f NAN
public static final Vector3f UNIT_X
public static final Vector3f UNIT_Y
public static final Vector3f UNIT_Z
public static final Vector3f UNIT_XYZ
public static final Vector3f POSITIVE_INFINITY
public static final Vector3f NEGATIVE_INFINITY
public float x
public float y
public float z
public Vector3f()
Vector3f
with default
values of (0,0,0).public Vector3f(float x, float y, float z)
Vector3f
with provides
values.x
- the x value of the vector.y
- the y value of the vector.z
- the z value of the vector.public Vector3f(Vector3f copy)
Vector3f
that is a copy
of the provided vectorcopy
- The Vector3f to copypublic Vector3f set(float x, float y, float z)
set
sets the x,y,z values of the vector based on passed
parameters.x
- the x value of the vector.y
- the y value of the vector.z
- the z value of the vector.public Vector3f set(Vector3f vect)
set
sets the x,y,z values of the vector by copying the
supplied vector.vect
- the vector to copy.public Vector3f add(Vector3f 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 Vector3f add(Vector3f vec, Vector3f result)
add
adds the values of a provided vector storing the
values in the supplied vector.vec
- the vector to add to thisresult
- the vector to store the result inpublic Vector3f addLocal(Vector3f 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 Vector3f add(float addX, float addY, float addZ)
add
adds the provided values to this vector, creating a
new vector that is then returned.addX
- the x value to add.addY
- the y value to add.addZ
- the z value to add.public Vector3f addLocal(float addX, float addY, float addZ)
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 yaddZ
- value to add to zpublic Vector3f scaleAdd(float scalar, Vector3f add)
scaleAdd
multiplies this vector by a scalar then adds the
given Vector3f.scalar
- the value to multiply this vector by.add
- the value to addpublic Vector3f scaleAdd(float scalar, Vector3f mult, Vector3f add)
scaleAdd
multiplies the given vector by a scalar then adds
the given vector.scalar
- the value to multiply this vector by.mult
- the value to multiply the scalar byadd
- the value to addpublic float dot(Vector3f 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(Vector3f 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 Vector3f cross(Vector3f v, Vector3f result)
cross
calculates the cross product of this vector with a
parameter vector v. The result is stored in result
v
- the vector to take the cross product of with this.result
- the vector to store the cross product result.public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result)
cross
calculates the cross product of this vector with a
parameter vector v. The result is stored in result
otherX
- x component of the vector to take the cross product of with this.otherY
- y component of the vector to take the cross product of with this.otherZ
- z component of the vector to take the cross product of with this.result
- the vector to store the cross product result.public Vector3f crossLocal(Vector3f v)
crossLocal
calculates the cross product of this vector
with a parameter vector v.v
- the vector to take the cross product of with this.public Vector3f crossLocal(float otherX, float otherY, float otherZ)
crossLocal
calculates the cross product of this vector
with a parameter vector v.otherX
- x component of the vector to take the cross product of with this.otherY
- y component of the vector to take the cross product of with this.otherZ
- z component of the vector to take the cross product of with this.public Vector3f project(Vector3f other)
other
- The vector to project this vector ontopublic Vector3f projectLocal(Vector3f other)
other
- The vector to project this vector ontopublic boolean isUnitVector()
public 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(Vector3f v)
distanceSquared
calculates the distance squared between
this vector and vector v.v
- the second vector to determine the distance squared.public float distance(Vector3f v)
distance
calculates the distance between this vector and
vector v.v
- the second vector to determine the distance.public Vector3f mult(float scalar)
mult
multiplies this vector by a scalar. The resultant
vector is returned.scalar
- the value to multiply this vector by.public Vector3f mult(float scalar, Vector3f product)
mult
multiplies this vector by a scalar. The resultant
vector is supplied as the second parameter and returned.scalar
- the scalar to multiply this vector by.product
- the product to store the result in.public Vector3f 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 Vector3f multLocal(Vector3f 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.vec
- the vector to mult to this vector.public Vector3f multLocal(float x, float y, float z)
multLocal
multiplies this vector by 3 scalars
internally, and returns a handle to this vector for easy chaining of
calls.x
- the scale factor for the X componenty
- the scale factor for the Y componentz
- the scale factor for the Z componentpublic Vector3f mult(Vector3f 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.vec
- the vector to mult to this vector.public Vector3f mult(Vector3f vec, Vector3f store)
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.vec
- the vector to mult to this vector.store
- result vector (null to create a new vector)public Vector3f 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 Vector3f 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 Vector3f divide(Vector3f 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 Vector3f divideLocal(Vector3f 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 Vector3f negate()
negate
returns the negative of this vector. All values are
negated and set to a new vector.public Vector3f negateLocal()
negateLocal
negates the internal values of this vector.public Vector3f subtract(Vector3f 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.vec
- the vector to subtract from this vector.public Vector3f subtractLocal(Vector3f 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 Vector3f subtract(Vector3f vec, Vector3f result)
subtract
vec
- the vector to subtract from thisresult
- the vector to store the result inpublic Vector3f subtract(float subtractX, float subtractY, float subtractZ)
subtract
subtracts the provided values from this vector,
creating a new vector that is then returned.subtractX
- the x value to subtract.subtractY
- the y value to subtract.subtractZ
- the z value to subtract.public Vector3f subtractLocal(float subtractX, float subtractY, float subtractZ)
subtractLocal
subtracts the provided values from this vector
internally, and returns a handle to this vector for easy chaining of
calls.subtractX
- the x value to subtract.subtractY
- the y value to subtract.subtractZ
- the z value to subtract.public Vector3f normalize()
normalize
returns the unit vector of this vector.public Vector3f normalizeLocal()
normalizeLocal
makes this vector into a unit vector of
itself.public Vector3f maxLocal(Vector3f other)
maxLocal
computes the maximum value for each
component in this and other
vector. The result is stored
in this vector.other
- the vector to compare with (not null, unaffected)public Vector3f minLocal(Vector3f other)
minLocal
computes the minimum value for each
component in this and other
vector. The result is stored
in this vector.other
- the vector to compare with (not null, unaffected)public Vector3f zero()
zero
resets this vector's data to zero internally.public float angleBetween(Vector3f otherVector)
angleBetween
returns (in radians) the 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 Vector3f interpolateLocal(Vector3f 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 Vector3f interpolateLocal(Vector3f beginVec, Vector3f finalVec, float changeAmnt)
beginVec
- the beginning vector (changeAmnt=0)finalVec
- The final vector to interpolate towardschangeAmnt
- An amount between 0.0 - 1.0 representing a percentage
change from beginVec towards finalVecpublic static boolean isValidVector(Vector3f vector)
vector
- the vector to checkpublic static void generateOrthonormalBasis(Vector3f u, Vector3f v, Vector3f w)
public static void generateComplementBasis(Vector3f u, Vector3f v, Vector3f w)
public Vector3f clone()
clone
in class java.lang.Object
public float[] toArray(float[] floats)
floats
- The float[] to take this Vector3f. If null, a new float[3] is
created.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the object to compare for equalitypublic boolean isSimilar(Vector3f other, float epsilon)
other
- the vector to compare with (not null, unaffected)epsilon
- the desired error tolerance for each componentpublic 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 java.lang.String toString()
toString
returns a string representation of this vector.
The format is:
(XX.XXXX, YY.YYYY, ZZ.ZZZZ)toString
in class java.lang.Object
public void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter e) throws java.io.IOException
public float getX()
public Vector3f setX(float x)
x
- the desired valuepublic float getY()
public Vector3f setY(float y)
y
- the desired valuepublic float getZ()
public Vector3f setZ(float z)
z
- the desired valuepublic float get(int index)
index
- 0, 1, or 2java.lang.IllegalArgumentException
- if index is not one of 0, 1, 2.public void set(int index, float value)
index
- which field index in this vector to set.value
- to set to one of x, y or z.java.lang.IllegalArgumentException
- if index is not one of 0, 1, 2.