public final class Vector4f extends java.lang.Object implements Savable, java.lang.Cloneable, java.io.Serializable
Vector4f
defines a Vector for a four float value tuple.
Vector4f
can represent any four 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 Vector4f |
NAN |
static Vector4f |
NEGATIVE_INFINITY |
static Vector4f |
POSITIVE_INFINITY |
static Vector4f |
UNIT_W |
static Vector4f |
UNIT_X |
static Vector4f |
UNIT_XYZW |
static Vector4f |
UNIT_Y |
static Vector4f |
UNIT_Z |
float |
w
the w value of the vector.
|
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 Vector4f |
ZERO |
Constructor and Description |
---|
Vector4f()
Constructor instantiates a new
Vector3f with default
values of (0,0,0). |
Vector4f(float x,
float y,
float z,
float w)
Constructor instantiates a new
Vector4f with provides
values. |
Vector4f(Vector4f copy)
Constructor instantiates a new
Vector3f that is a copy
of the provided vector |
Modifier and Type | Method and Description |
---|---|
Vector4f |
add(float addX,
float addY,
float addZ,
float addW)
add adds the provided values to this vector, creating a
new vector that is then returned. |
Vector4f |
add(Vector4f vec)
add adds a provided vector to this vector creating a
resultant vector which is returned. |
Vector4f |
add(Vector4f vec,
Vector4f result)
add adds the values of a provided vector storing the
values in the supplied vector. |
Vector4f |
addLocal(float addX,
float addY,
float addZ,
float addW)
addLocal adds the provided values to this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector4f |
addLocal(Vector4f vec)
addLocal adds a provided vector to this vector internally,
and returns a handle to this vector for easy chaining of calls. |
float |
angleBetween(Vector4f otherVector)
angleBetween returns (in radians) the angle between two vectors. |
Vector4f |
clone() |
float |
distance(Vector4f v)
distance calculates the distance between this vector and
vector v. |
float |
distanceSquared(Vector4f v)
distanceSquared calculates the distance squared between
this vector and vector v. |
Vector4f |
divide(float scalar)
divide divides the values of this vector by a scalar and
returns the result. |
Vector4f |
divide(Vector4f scalar)
divide divides the values of this vector by a scalar and
returns the result. |
Vector4f |
divideLocal(float scalar)
divideLocal divides this vector by a scalar internally,
and returns a handle to this vector for easy chaining of calls. |
Vector4f |
divideLocal(Vector4f scalar)
divideLocal divides this vector by a scalar internally,
and returns a handle to this vector for easy chaining of calls. |
float |
dot(Vector4f 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.
|
float |
get(int index) |
float |
getW() |
float |
getX() |
float |
getY() |
float |
getZ() |
int |
hashCode()
hashCode returns a unique code for this vector object based
on its values. |
Vector4f |
interpolateLocal(Vector4f finalVec,
float changeAmnt)
Sets this vector to the interpolation by changeAmnt from this to the finalVec
this=(1-changeAmnt)*this + changeAmnt * finalVec
|
Vector4f |
interpolateLocal(Vector4f beginVec,
Vector4f finalVec,
float changeAmnt)
Sets this vector to the interpolation by changeAmnt from beginVec to finalVec
this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
|
boolean |
isSimilar(Vector4f 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(Vector4f 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. |
Vector4f |
maxLocal(Vector4f other)
maxLocal computes the maximum value for each
component in this and other vector. |
Vector4f |
minLocal(Vector4f other)
minLocal computes the minimum value for each
component in this and other vector. |
Vector4f |
mult(float scalar)
mult multiplies this vector by a scalar. |
Vector4f |
mult(float scalar,
Vector4f product)
mult multiplies this vector by a scalar. |
Vector4f |
mult(Vector4f vec)
multLocal multiplies a provided vector to this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector4f |
mult(Vector4f vec,
Vector4f store)
multLocal multiplies a provided vector to this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector4f |
multLocal(float scalar)
multLocal multiplies this vector by a scalar internally,
and returns a handle to this vector for easy chaining of calls. |
Vector4f |
multLocal(float x,
float y,
float z,
float w)
multLocal multiplies this vector by 3 scalars
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector4f |
multLocal(Vector4f vec)
multLocal multiplies a provided vector to this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector4f |
negate()
negate returns the negative of this vector. |
Vector4f |
negateLocal()
negateLocal negates the internal values of this vector. |
Vector4f |
normalize()
normalize returns the unit vector of this vector. |
Vector4f |
normalizeLocal()
normalizeLocal makes this vector into a unit vector of
itself. |
Vector4f |
project(Vector4f other) |
void |
read(JmeImporter e) |
Vector4f |
scaleAdd(float scalar,
Vector4f add)
scaleAdd multiplies this vector by a scalar then adds the
given Vector3f. |
Vector4f |
scaleAdd(float scalar,
Vector4f mult,
Vector4f add)
scaleAdd multiplies the given vector by a scalar then adds
the given vector. |
Vector4f |
set(float x,
float y,
float z,
float w)
set sets the x,y,z,w values of the vector based on passed
parameters. |
void |
set(int index,
float value) |
Vector4f |
set(Vector4f vect)
set sets the x,y,z values of the vector by copying the
supplied vector. |
Vector4f |
setW(float w) |
Vector4f |
setX(float x) |
Vector4f |
setY(float y) |
Vector4f |
setZ(float z) |
Vector4f |
subtract(float subtractX,
float subtractY,
float subtractZ,
float subtractW)
subtract subtracts the provided values from this vector,
creating a new vector that is then returned. |
Vector4f |
subtract(Vector4f vec)
subtract subtracts the values of a given vector from those
of this vector creating a new vector object. |
Vector4f |
subtract(Vector4f vec,
Vector4f result)
subtract |
Vector4f |
subtractLocal(float subtractX,
float subtractY,
float subtractZ,
float subtractW)
subtractLocal subtracts the provided values from this vector
internally, and returns a handle to this vector for easy chaining of
calls. |
Vector4f |
subtractLocal(Vector4f 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 the string representation of this vector. |
void |
write(JmeExporter e) |
Vector4f |
zero()
zero resets this vector's data to zero internally. |
public static final Vector4f ZERO
public static final Vector4f NAN
public static final Vector4f UNIT_X
public static final Vector4f UNIT_Y
public static final Vector4f UNIT_Z
public static final Vector4f UNIT_W
public static final Vector4f UNIT_XYZW
public static final Vector4f POSITIVE_INFINITY
public static final Vector4f NEGATIVE_INFINITY
public float x
public float y
public float z
public float w
public Vector4f()
Vector3f
with default
values of (0,0,0).public Vector4f(float x, float y, float z, float w)
Vector4f
with provides
values.x
- the x value of the vector.y
- the y value of the vector.z
- the z value of the vector.w
- the w value of the vector.public Vector4f(Vector4f copy)
Vector3f
that is a copy
of the provided vectorcopy
- The Vector3f to copypublic Vector4f set(float x, float y, float z, float w)
set
sets the x,y,z,w 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.w
- the w value of the vector.public Vector4f set(Vector4f vect)
set
sets the x,y,z values of the vector by copying the
supplied vector.vect
- the vector to copy.public Vector4f add(Vector4f 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 Vector4f add(Vector4f vec, Vector4f 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 Vector4f addLocal(Vector4f 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 Vector4f add(float addX, float addY, float addZ, float addW)
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 Vector4f addLocal(float addX, float addY, float addZ, float addW)
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 Vector4f scaleAdd(float scalar, Vector4f 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 Vector4f scaleAdd(float scalar, Vector4f mult, Vector4f 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(Vector4f 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 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(Vector4f v)
distanceSquared
calculates the distance squared between
this vector and vector v.v
- the second vector to determine the distance squared.public float distance(Vector4f v)
distance
calculates the distance between this vector and
vector v.v
- the second vector to determine the distance.public Vector4f mult(float scalar)
mult
multiplies this vector by a scalar. The resultant
vector is returned.scalar
- the value to multiply this vector by.public Vector4f mult(float scalar, Vector4f 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 Vector4f 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 Vector4f multLocal(Vector4f 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 Vector4f multLocal(float x, float y, float z, float w)
multLocal
multiplies this vector by 3 scalars
internally, and returns a handle to this vector for easy chaining of
calls.x
- y
- z
- w
- public Vector4f mult(Vector4f 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 Vector4f mult(Vector4f vec, Vector4f 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 Vector4f 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 Vector4f 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 Vector4f divide(Vector4f 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 Vector4f divideLocal(Vector4f 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 Vector4f negate()
negate
returns the negative of this vector. All values are
negated and set to a new vector.public Vector4f negateLocal()
negateLocal
negates the internal values of this vector.public Vector4f subtract(Vector4f 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 Vector4f subtractLocal(Vector4f 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 Vector4f subtract(Vector4f vec, Vector4f result)
subtract
vec
- the vector to subtract from thisresult
- the vector to store the result inpublic Vector4f subtract(float subtractX, float subtractY, float subtractZ, float subtractW)
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.subtractW
- the w value to subtract.public Vector4f subtractLocal(float subtractX, float subtractY, float subtractZ, float subtractW)
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.subtractW
- the w value to subtract.public Vector4f normalize()
normalize
returns the unit vector of this vector.public Vector4f normalizeLocal()
normalizeLocal
makes this vector into a unit vector of
itself.public Vector4f maxLocal(Vector4f other)
maxLocal
computes the maximum value for each
component in this and other
vector. The result is stored
in this vector.other
- public Vector4f minLocal(Vector4f other)
minLocal
computes the minimum value for each
component in this and other
vector. The result is stored
in this vector.other
- public Vector4f zero()
zero
resets this vector's data to zero internally.public float angleBetween(Vector4f 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 Vector4f interpolateLocal(Vector4f 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 Vector4f interpolateLocal(Vector4f beginVec, Vector4f 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(Vector4f vector)
vector
- the vector to checkpublic Vector4f 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(Vector4f other, float epsilon)
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 java.lang.String toString()
toString
returns the string representation of this vector.
The format is:
org.jme.math.Vector3f [X=XX.XXXX, Y=YY.YYYY, Z=ZZ.ZZZZ, W=WW.WWWW]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 Vector4f setX(float x)
public float getY()
public Vector4f setY(float y)
public float getZ()
public Vector4f setZ(float z)
public float getW()
public Vector4f setW(float w)
public float get(int index)
index
- java.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, z or w.java.lang.IllegalArgumentException
- if index is not one of 0, 1, 2, 3.