Package com.jme3.math
Class Vector4f
java.lang.Object
com.jme3.math.Vector4f
- All Implemented Interfaces:
Savable
,Serializable
,Cloneable
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.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Vector4f
shared instance of the all-NaN vector (NaN,NaN,NaN,NaN) - Do not modify!static final Vector4f
shared instance of the all-negative-infinity vector (-Inf,-Inf,-Inf,-Inf) - Do not modify!static final Vector4f
shared instance of the all-plus-infinity vector (+Inf,+Inf,+Inf,+Inf) - Do not modify!static final Vector4f
shared instance of the +W direction (0,0,0,1) - Do not modify!static final Vector4f
shared instance of the +X direction (1,0,0,0) - Do not modify!static final Vector4f
shared instance of the all-ones vector (1,1,1,1) - Do not modify!static final Vector4f
shared instance of the +Y direction (0,1,0,0) - Do not modify!static final Vector4f
shared instance of the +Z direction (0,0,1,0) - Do not modify!float
the w value of the vector.float
the x value of the vector.float
the y value of the vector.float
the z value of the vector.static final Vector4f
shared instance of the all-zero vector (0,0,0,0) - Do not modify! -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(float addX, float addY, float addZ, float addW) add
adds the provided values to this vector, creating a new vector that is then returned.add
adds a provided vector to this vector creating a resultant vector which is returned.add
adds the values of a provided vector storing the values in the supplied vector.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.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.clone()
Create a copy of this vector.float
distance
calculates the distance between this vector and vector v.float
distanceSquared
calculates the distance squared between this vector and vector v.divide
(float scalar) divide
divides the values of this vector by a scalar and returns the result.divide
(float x, float y, float z, float w) Divides component-wise by the specified components and returns the quotient as a new instance.divide
divides the values of this vector by a scalar and returns the result.divideLocal
(float scalar) divideLocal
divides this vector by a scalar internally, and returns a handle to this vector for easy chaining of calls.divideLocal
(float x, float y, float z, float w) Divides component-wise by the specified components returns the (modified) current instance.divideLocal
(Vector4f divisor) divideLocal
divides this vector by a scalar internally, and returns a handle to this vector for easy chaining of calls.float
dot
calculates the dot product of this vector with a provided vector.boolean
Are these two vectors the same? They are if they have the same x, y, z, and w values.float
get
(int index) float
getW()
Determine the W component of this vector.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.interpolateLocal
(Vector4f finalVec, float changeAmount) Sets this vector to the interpolation by changeAmount from this to the finalVec this=(1-changeAmount)*this + changeAmount * finalVecinterpolateLocal
(Vector4f beginVec, Vector4f finalVec, float changeAmount) Sets this vector to the interpolation by changeAmount from beginVec to finalVec this=(1-changeAmount)*beginVec + changeAmount * finalVecboolean
Returns true if this vector is similar to the specified vector within some value of epsilon.boolean
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
calculates the squared value of the magnitude of the vector.maxLocal
computes the maximum value for each component in this andother
vector.minLocal
computes the minimum value for each component in this andother
vector.mult
(float scalar) mult
multiplies this vector by a scalar.mult
(float x, float y, float z, float w) Multiplies component-wise by the specified components and returns the product as a new instance.mult
multiplies this vector by a scalar.multLocal
multiplies a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls.multLocal
multiplies a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls.multLocal
(float scalar) multLocal
multiplies this vector by a scalar internally, and returns a handle to this vector for easy chaining of calls.multLocal
(float x, float y, float z, float w) multLocal
multiplies this vector by 4 scalars internally, and returns a handle to this vector for easy chaining of calls.multLocal
multiplies a provided vector to this vector internally, and returns a handle to this vector for easy chaining of calls.negate()
negate
returns the negative of this vector.negateLocal
negates the internal values of this vector.normalize
returns the unit vector of this vector.normalizeLocal
makes this vector into a unit vector of itself.void
read
(JmeImporter importer) De-serialize this vector from the specified importer, for example when loading from a J3O file.scaleAdd
multiplies this vector by a scalar then adds the given Vector4f.scaleAdd
multiplies the given vector by a scalar then adds the given vector.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) set
sets the x,y,z values of the vector by copying the supplied vector.setW
(float w) Alter the W component of this vector.setX
(float x) Alter the X component of this vector.setY
(float y) Alter the Y component of this vector.setZ
(float z) Alter the Z component of this vector.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.subtract
subtracts the values of a given vector from those of this vector creating a new vector object.subtract
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.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 Vector4f into the given float[] object.toString()
toString
returns the string representation of this vector.void
write
(JmeExporter e) Serialize this vector to the specified exporter, for example when saving to a J3O file.zero()
zero
resets this vector's data to zero internally.
-
Field Details
-
ZERO
shared instance of the all-zero vector (0,0,0,0) - Do not modify! -
NAN
shared instance of the all-NaN vector (NaN,NaN,NaN,NaN) - Do not modify! -
UNIT_X
shared instance of the +X direction (1,0,0,0) - Do not modify! -
UNIT_Y
shared instance of the +Y direction (0,1,0,0) - Do not modify! -
UNIT_Z
shared instance of the +Z direction (0,0,1,0) - Do not modify! -
UNIT_W
shared instance of the +W direction (0,0,0,1) - Do not modify! -
UNIT_XYZW
shared instance of the all-ones vector (1,1,1,1) - Do not modify! -
POSITIVE_INFINITY
shared instance of the all-plus-infinity vector (+Inf,+Inf,+Inf,+Inf) - Do not modify! -
NEGATIVE_INFINITY
shared instance of the all-negative-infinity vector (-Inf,-Inf,-Inf,-Inf) - Do not modify! -
x
public float xthe x value of the vector. -
y
public float ythe y value of the vector. -
z
public float zthe z value of the vector. -
w
public float wthe w value of the vector.
-
-
Constructor Details
-
Vector4f
public Vector4f()Instantiate aVector4f
with the value (0,0,0,0). -
Vector4f
public Vector4f(float x, float y, float z, float w) Constructor instantiates a newVector4f
with provides values.- 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.
-
Vector4f
Instantiate aVector4f
that is a copy of the provided vector.- Parameters:
copy
- The Vector4f to copy
-
-
Method Details
-
set
set
sets the x,y,z,w values of the vector based on passed parameters.- 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.- Returns:
- this vector
-
set
set
sets the x,y,z values of the vector by copying the supplied vector.- Parameters:
vect
- the vector to copy.- Returns:
- this vector
-
add
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.
-
add
add
adds the values of a provided vector storing the values in the supplied vector.- Parameters:
vec
- the vector to add to thisresult
- the vector to store the result in- Returns:
- result returns the supplied result vector.
-
addLocal
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
-
add
add
adds the provided values to this vector, creating a new vector that is then returned.- Parameters:
addX
- the x value to add.addY
- the y value to add.addZ
- the z value to add.addW
- the w value to add.- Returns:
- the result vector.
-
addLocal
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 xaddY
- value to add to yaddZ
- value to add to zaddW
- the w value to add.- Returns:
- this
-
scaleAdd
scaleAdd
multiplies this vector by a scalar then adds the given Vector4f.- Parameters:
scalar
- the value to multiply this vector by.add
- the value to add- Returns:
- this
-
scaleAdd
scaleAdd
multiplies the given vector by a scalar then adds the given vector.- Parameters:
scalar
- the value to multiply this vector by.mult
- the value to multiply the scalar byadd
- the value to add- Returns:
- this
-
dot
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.
-
project
-
isUnitVector
public boolean isUnitVector()Returns true if this vector is a unit vector (length() ~= 1), returns false otherwise.- Returns:
- true if this vector is a unit vector (length() ~= 1), or false otherwise.
-
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.
-
distanceSquared
distanceSquared
calculates the distance squared between this vector and vector v.- Parameters:
v
- the second vector to determine the distance squared.- Returns:
- the distance squared between the two vectors.
-
distance
distance
calculates the distance between this vector and vector v.- Parameters:
v
- the second vector to determine the distance.- Returns:
- the distance between the two vectors.
-
mult
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.
-
mult
mult
multiplies this vector by a scalar. The resultant vector is supplied as the second parameter and returned.- Parameters:
scalar
- the scalar to multiply this vector by.product
- the product to store the result in.- Returns:
- product
-
mult
Multiplies component-wise by the specified components and returns the product as a new instance. The current instance is unaffected.- Parameters:
x
- the scale factor for the X componenty
- the scale factor for the Y componentz
- the scale factor for the Z componentw
- the scale factor for the W component- Returns:
- a new Vector4f
-
multLocal
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
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
-
multLocal
multLocal
multiplies this vector by 4 scalars internally, and returns a handle to this vector for easy chaining of calls.- Parameters:
x
- the scaling factor for the X componenty
- the scaling factor for the Y componentz
- the scaling factor for the Z componentw
- the scaling factor for the W component- Returns:
- this
-
mult
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
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.store
- result vector (null to create a new vector)- Returns:
- this
-
divide
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
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
-
divide
divide
divides the values of this vector by a scalar and returns the result. The values of this vector remain untouched.- Parameters:
divisor
- the value to divide this vectors attributes by.- Returns:
- the result
Vector
.
-
divideLocal
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:
divisor
- the value to divides this vector by.- Returns:
- this
-
divideLocal
Divides component-wise by the specified components returns the (modified) current instance.- Parameters:
x
- the divisor for the X componenty
- the divisor for the Y componentz
- the divisor for the Z componentw
- the divisor for the W component- Returns:
- the (modified) current instance (for chaining)
-
divide
Divides component-wise by the specified components and returns the quotient as a new instance. The current instance is unaffected.- Parameters:
x
- the divisor for the X componenty
- the divisor for the Y componentz
- the divisor for the Z componentw
- the divisor for the W component- Returns:
- a new Vector4f
-
negate
negate
returns the negative of this vector. All values are negated and set to a new vector.- Returns:
- the negated vector.
-
negateLocal
negateLocal
negates the internal values of this vector.- Returns:
- this.
-
subtract
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
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
-
subtract
subtract
- Parameters:
vec
- the vector to subtract from thisresult
- the vector to store the result in- Returns:
- result
-
subtract
subtract
subtracts the provided values from this vector, creating a new vector that is then returned.- Parameters:
subtractX
- the x value to subtract.subtractY
- the y value to subtract.subtractZ
- the z value to subtract.subtractW
- the w value to subtract.- Returns:
- the result vector.
-
subtractLocal
subtractLocal
subtracts the provided values from this vector internally, and returns a handle to this vector for easy chaining of calls.- Parameters:
subtractX
- the x value to subtract.subtractY
- the y value to subtract.subtractZ
- the z value to subtract.subtractW
- the w value to subtract.- Returns:
- this
-
normalize
normalize
returns the unit vector of this vector.- Returns:
- unit vector of this vector.
-
normalizeLocal
normalizeLocal
makes this vector into a unit vector of itself.- Returns:
- this.
-
maxLocal
maxLocal
computes the maximum value for each component in this andother
vector. The result is stored in this vector.- Parameters:
other
- the vector to compare with (not null, unaffected)- Returns:
- this
-
minLocal
minLocal
computes the minimum value for each component in this andother
vector. The result is stored in this vector.- Parameters:
other
- the vector to compare with (not null, unaffected)- Returns:
- this
-
zero
zero
resets this vector's data to zero internally.- Returns:
- this, with all components set to zero
-
angleBetween
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).- Parameters:
otherVector
- a unit vector to find the angle against- Returns:
- the angle in radians.
-
interpolateLocal
Sets this vector to the interpolation by changeAmount from this to the finalVec this=(1-changeAmount)*this + changeAmount * finalVec- Parameters:
finalVec
- The final vector to interpolate towardschangeAmount
- An amount between 0.0 - 1.0 representing a percentage change from this towards finalVec- Returns:
- this
-
interpolateLocal
Sets this vector to the interpolation by changeAmount from beginVec to finalVec this=(1-changeAmount)*beginVec + changeAmount * finalVec- Parameters:
beginVec
- the beginning vector (changeAmount=0)finalVec
- The final vector to interpolate towardschangeAmount
- An amount between 0.0 - 1.0 representing a percentage change from beginVec towards finalVec- Returns:
- this
-
isValidVector
Check a vector... if it is null or its floats are NaN or infinite, return false. Else return true.- Parameters:
vector
- the vector to check- Returns:
- true or false as stated above.
-
clone
Create a copy of this vector. -
toArray
public float[] toArray(float[] floats) Saves this Vector4f into the given float[] object.- Parameters:
floats
- The float[] to take this Vector4f. If null, a new float[4] is created.- Returns:
- The array, with X, Y, Z, W float values in that order
-
equals
Are these two vectors the same? They are if they have the same x, y, z, and w values. -
isSimilar
Returns true if this vector is similar to the specified vector within some value of epsilon.- Parameters:
other
- the vector to compare with (not null, unaffected)epsilon
- the desired error tolerance for each component- Returns:
- true if all 4 components are within tolerance, otherwise false
-
hashCode
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. -
toString
toString
returns the string representation of this vector. The format is: (XX.XXXX, YY.YYYY, ZZ.ZZZZ, WW.WWWW) -
write
Serialize this vector to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfaceSavable
- Parameters:
e
- (not null)- Throws:
IOException
- from the exporter
-
read
De-serialize this vector from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
getX
public float getX()Determine the X component of this vector.- Returns:
- x
-
setX
Alter the X component of this vector.- Parameters:
x
- the desired value- Returns:
- this vector, modified
-
getY
public float getY()Determine the Y component of this vector.- Returns:
- y
-
setY
Alter the Y component of this vector.- Parameters:
y
- the desired value- Returns:
- this vector, modified
-
getZ
public float getZ()Determine the Z component of this vector.- Returns:
- z
-
setZ
Alter the Z component of this vector.- Parameters:
z
- the desired value- Returns:
- this vector, modified
-
getW
public float getW()Determine the W component of this vector.- Returns:
- w
-
setW
Alter the W component of this vector.- Parameters:
w
- the desired value- Returns:
- this vector, modified
-
get
public float get(int index) - Parameters:
index
- which component (≥0, <4)- Returns:
- x value if index == 0, y value if index == 1 or z value if index == 2
- Throws:
IllegalArgumentException
- if index is not one of 0, 1, 2.
-
set
public void set(int index, float value) - Parameters:
index
- which field index in this vector to set.value
- to set to one of x, y, z or w.- Throws:
IllegalArgumentException
- if index is not one of 0, 1, 2, 3.
-