public final class Vector3f extends java.lang.Object implements Savable, java.lang.Cloneable, java.io.Serializable
Methods with names ending in "Local" modify the current instance. They are used to cut down on the creation of new instances.
Modifier and Type | Field and Description |
---|---|
static Vector3f |
NAN
Shared instance of the all-NaN vector (NaN,NaN,NaN).
|
static Vector3f |
NEGATIVE_INFINITY
Shared instance of the all-negative-infinity vector (-Inf,-Inf,-Inf).
|
static Vector3f |
POSITIVE_INFINITY
Shared instance of the all-plus-infinity vector (+Inf,+Inf,+Inf).
|
static Vector3f |
UNIT_X
Shared instance of the +X direction (1,0,0).
|
static Vector3f |
UNIT_XYZ
Shared instance of the all-ones vector (1,1,1).
|
static Vector3f |
UNIT_Y
Shared instance of the +Y direction (0,1,0).
|
static Vector3f |
UNIT_Z
Shared instance of the +Z direction (0,0,1).
|
float |
x
The first (X) component.
|
float |
y
The 2nd (Y) component.
|
float |
z
The 3rd (Z) component.
|
static Vector3f |
ZERO
Shared instance of the all-zero vector (0,0,0).
|
Constructor and Description |
---|
Vector3f()
Instantiates an all-zero vector (0,0,0).
|
Vector3f(float x,
float y,
float z)
Instantiates a vector with specified components.
|
Vector3f(Vector3f copy)
Instantiates a copy of the argument.
|
Modifier and Type | Method and Description |
---|---|
Vector3f |
add(float addX,
float addY,
float addZ)
Adds specified amounts to the vector's components and returns the sum as
a new instance.
|
Vector3f |
add(Vector3f vec)
Adds the argument and returns the sum as a new instance.
|
Vector3f |
add(Vector3f vec,
Vector3f result)
Adds a specified vector and returns the sum in a 3rd vector.
|
Vector3f |
addLocal(float addX,
float addY,
float addZ)
Adds specified amounts to the vector's components and returns the
(modified) current instance.
|
Vector3f |
addLocal(Vector3f vec)
Adds the argument and returns the (modified) current instance.
|
float |
angleBetween(Vector3f otherVector)
Returns the angle (in radians) between this vector and the argument,
provided both vectors have length=1.
|
Vector3f |
clone()
Creates a copy.
|
Vector3f |
cross(float otherX,
float otherY,
float otherZ,
Vector3f result)
Calculates a cross product with specified components and returns the
product in the specified vector.
|
Vector3f |
cross(Vector3f v)
Calculates a cross product with the argument and returns the product as a
new instance.
|
Vector3f |
cross(Vector3f v,
Vector3f result)
Calculates a cross product with a specified vector and returns the
product in a 3rd vector.
|
Vector3f |
crossLocal(float otherX,
float otherY,
float otherZ)
Right multiplies by the specified components (cross product) and returns
the (modified) current instance.
|
Vector3f |
crossLocal(Vector3f v)
Right multiplies by the argument (cross product) and returns the
(modified) current instance.
|
float |
distance(Vector3f v)
Returns the distance between this vector and the argument.
|
float |
distanceSquared(Vector3f v)
Returns the square of the distance between this vector and the argument.
|
Vector3f |
divide(float scalar)
Divides by the argument and returns the quotient as a new instance.
|
Vector3f |
divide(Vector3f scalar)
Divides component-wise by the argument and returns the quotient as a new
instance.
|
Vector3f |
divideLocal(float scalar)
Divides by the argument and returns the (modified) current instance.
|
Vector3f |
divideLocal(Vector3f scalar)
Divides component-wise by the argument and returns the (modified) current
instance.
|
float |
dot(Vector3f vec)
Returns the dot (or inner) product with the argument.
|
boolean |
equals(java.lang.Object o)
Tests for exact equality with the argument, distinguishing -0 from 0.
|
static void |
generateComplementBasis(Vector3f u,
Vector3f v,
Vector3f w) |
static void |
generateOrthonormalBasis(Vector3f u,
Vector3f v,
Vector3f w) |
float |
get(int index)
Returns the indexed component.
|
float |
getX()
Returns the X component.
|
float |
getY()
Returns the Y component.
|
float |
getZ()
Returns the Z component.
|
int |
hashCode()
Returns a hash code.
|
Vector3f |
interpolateLocal(Vector3f finalVec,
float changeAmnt)
Interpolates linearly between this vector and the specified vector,
returning the (modified) current instance.
|
Vector3f |
interpolateLocal(Vector3f beginVec,
Vector3f finalVec,
float changeAmnt)
Interpolates linearly between the specified beginning and final vectors,
returning the (modified) current instance.
|
boolean |
isSimilar(Vector3f other,
float epsilon)
Tests for approximate equality with the specified vector, using the
specified tolerance.
|
boolean |
isUnitVector()
Tests for a unit vector, with 1% tolerance.
|
static boolean |
isValidVector(Vector3f vector)
Tests whether the argument is a valid vector, returning false if it's
null or if any component is NaN or infinite.
|
float |
length()
Returns the length (or magnitude).
|
float |
lengthSquared()
Returns the square of the length.
|
Vector3f |
maxLocal(Vector3f other)
Compares this vector component-wise with the argument (keeping the most
positive value for each component) and returns the (modified) current
instance.
|
Vector3f |
minLocal(Vector3f other)
Compares this vector component-wise with the argument (keeping the most
negative value for each component) and returns the (modified) current
instance.
|
Vector3f |
mult(float scalar)
Multiplies with the argument and returns the product as a new instance.
|
Vector3f |
mult(float scalar,
Vector3f product)
Multiplies with the specified scalar and returns the product in the
specified vector.
|
Vector3f |
mult(Vector3f vec)
Multiplies component-wise with the argument and returns the product as a
new instance.
|
Vector3f |
mult(Vector3f vec,
Vector3f store)
Multiplies component-wise with the specified vector and returns the
product in a 3rd vector.
|
Vector3f |
multLocal(float scalar)
Multiplies by the argument and returns the (modified) current instance.
|
Vector3f |
multLocal(float x,
float y,
float z)
Multiplies component-wise by the specified components and returns the
(modified) current instance.
|
Vector3f |
multLocal(Vector3f vec)
Multiplies component-wise by the argument and returns the (modified)
current instance.
|
Vector3f |
negate()
Returns the negative.
|
Vector3f |
negateLocal()
Negates all 3 components and returns the (modified) current instance.
|
Vector3f |
normalize()
Normalizes the vector to length=1 and returns the result as a new
instance.
|
Vector3f |
normalizeLocal()
Normalizes the vector to length=1 and returns the (modified) current
instance.
|
Vector3f |
project(Vector3f other)
Projects onto the argument and returns the result as a new vector.
|
Vector3f |
projectLocal(Vector3f other)
Projects onto the argument and returns the (modified) current instance.
|
void |
read(JmeImporter e)
De-serializes from the argument, for example when loading from a J3O
file.
|
Vector3f |
scaleAdd(float scalar,
Vector3f add)
Multiplies by the specified scalar, adds the specified vector, and
returns the (modified) current instance.
|
Vector3f |
scaleAdd(float scalar,
Vector3f mult,
Vector3f add)
Multiplies a specified vector by a specified scalar, then adds another
specified vector to it, before storing the result in the current
instance.
|
Vector3f |
set(float x,
float y,
float z)
Sets all 3 components to specified values.
|
void |
set(int index,
float value)
Sets the indexed component.
|
Vector3f |
set(Vector3f vect)
Copies all 3 components from the argument.
|
Vector3f |
setX(float x)
Sets the X component.
|
Vector3f |
setY(float y)
Sets the Y component.
|
Vector3f |
setZ(float z)
Sets the Z component.
|
Vector3f |
subtract(float subtractX,
float subtractY,
float subtractZ)
Subtracts the specified amounts from the vector's components and returns
the difference as a new instance.
|
Vector3f |
subtract(Vector3f vec)
Subtracts the argument and returns the difference as a new instance.
|
Vector3f |
subtract(Vector3f vec,
Vector3f result)
Subtracts the specified vector and returns the difference in a 3rd
vector.
|
Vector3f |
subtractLocal(float subtractX,
float subtractY,
float subtractZ)
Subtracts the specified amounts from the vector's components and returns
the (modified) current instance.
|
Vector3f |
subtractLocal(Vector3f vec)
Subtracts the argument and returns the (modified) current instance.
|
float[] |
toArray(float[] floats)
Copies the vector into the argument.
|
java.lang.String |
toString()
Returns a string representation.
|
void |
write(JmeExporter e)
Serializes to the argument, for example when saving to a J3O file.
|
Vector3f |
zero()
Sets all 3 components to zero.
|
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()
public Vector3f(float x, float y, float z)
x
- the desired X componenty
- the desired Y componentz
- the desired Z componentpublic Vector3f(Vector3f copy)
copy
- the vector to copy (not null, unaffected)public Vector3f set(float x, float y, float z)
x
- the desired X componenty
- the desired Y componentz
- the desired Z componentpublic Vector3f set(Vector3f vect)
vect
- the Vector3f to copy (not null, unaffected)public Vector3f add(Vector3f vec)
vec
- the vector to add (unaffected) or null for nonepublic Vector3f add(Vector3f vec, Vector3f result)
result
.vec
- the vector to add (not null, unaffected unless it's
result
)result
- storage for the sum (not null)result
(for chaining)public Vector3f addLocal(Vector3f vec)
vec
- the vector to add (unaffected unless it's this
)
or null for nonepublic Vector3f add(float addX, float addY, float addZ)
addX
- the amount to add to the X componentaddY
- the amount to add to the Y componentaddZ
- the amount to add to the Z componentpublic Vector3f addLocal(float addX, float addY, float addZ)
addX
- the amount to add to the X componentaddY
- the amount to add to the Y componentaddZ
- the amount to add to the Z componentpublic Vector3f scaleAdd(float scalar, Vector3f add)
this = scalar * this + add
scalar
- the scaling factoradd
- the vector to add (not null, unaffected unless it's
this
)public Vector3f scaleAdd(float scalar, Vector3f mult, Vector3f add)
this = scalar * mult + add
scalar
- the scaling factormult
- the vector to scale (not null, unaffected unless it's
this
)add
- the vector to add (not null, unaffected unless it's
this
)public float dot(Vector3f vec)
vec
- the vector to multiply (unaffected) or null for nonepublic Vector3f cross(Vector3f v)
v
- the right factor (not null, unaffected)this
cross v
(a new Vector3f)public Vector3f cross(Vector3f v, Vector3f result)
result
.v
- the right factor (not null, unaffected unless it's
result
)result
- storage for the product, or null for a new Vector3fthis
cross v
(either
result
or a new Vector3f)public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result)
result
.otherX
- the X component of the right factorotherY
- the Y component of the right factorotherZ
- the Z component of the right factorresult
- storage for the product, or null for a new Vector3fthis
cross v
(either
result
or a new Vector3f)public Vector3f crossLocal(Vector3f v)
v
- the right factor (not null, unaffected unless it's
this
)public Vector3f crossLocal(float otherX, float otherY, float otherZ)
otherX
- the X component of the right factorotherY
- the Y component of the right factorotherZ
- the Z component of the right factorpublic Vector3f project(Vector3f other)
other
- the vector to project onto (not null, unaffected)public Vector3f projectLocal(Vector3f other)
other
- the vector to project onto (not null, unaffected unless it's
this
)public boolean isUnitVector()
public float length()
public float lengthSquared()
public float distanceSquared(Vector3f v)
v
- the vector to compare (not null, unaffected)public float distance(Vector3f v)
v
- the vector to compare (not null, unaffected)public Vector3f mult(float scalar)
scalar
- the scaling factorpublic Vector3f mult(float scalar, Vector3f product)
product
.scalar
- the scaling factorproduct
- storage for the product, or null for a new Vector3fproduct
or a new Vector3fpublic Vector3f multLocal(float scalar)
scalar
- the scaling factorpublic Vector3f multLocal(Vector3f vec)
vec
- the scale vector (unaffected unless it's this
) or
null for nonepublic Vector3f multLocal(float x, float y, float z)
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)
vec
- the scale vector (unaffected) or null for nonepublic Vector3f mult(Vector3f vec, Vector3f store)
store
.vec
- the scale vector (unaffected unless it's store
)
or null for nonestore
- storage for the product, or null for a new Vector3fstore
or a new Vector3f or nullpublic Vector3f divide(float scalar)
scalar
- the divisorpublic Vector3f divideLocal(float scalar)
scalar
- the divisorpublic Vector3f divide(Vector3f scalar)
scalar
- the divisor (not null, unaffected) TODO rename argument!public Vector3f divideLocal(Vector3f scalar)
scalar
- the divisor (not null, unaffected) TODO rename argument!public Vector3f negate()
public Vector3f negateLocal()
public Vector3f subtract(Vector3f vec)
vec
- the vector to subtract (not null, unaffected)public Vector3f subtractLocal(Vector3f vec)
vec
- the vector to subtract (unaffected unless it's
this
) or null for nonepublic Vector3f subtract(Vector3f vec, Vector3f result)
result
.vec
- the vector to subtract (not null, unaffected unless it's
result
)result
- storage for the difference, or null for a new Vector3fresult
or a new Vector3fpublic Vector3f subtract(float subtractX, float subtractY, float subtractZ)
subtractX
- the amount to subtract from the X componentsubtractY
- the amount to subtract from the Y componentsubtractZ
- the amount to subtract from the Z componentpublic Vector3f subtractLocal(float subtractX, float subtractY, float subtractZ)
subtractX
- the amount to subtract from the X componentsubtractY
- the amount to subtract from the Y componentsubtractZ
- the amount to subtract from the Z componentpublic Vector3f normalize()
public Vector3f normalizeLocal()
public Vector3f maxLocal(Vector3f other)
other
- the vector to compare (not null, unaffected)public Vector3f minLocal(Vector3f other)
other
- the vector to compare (not null, unaffected)public Vector3f zero()
public float angleBetween(Vector3f otherVector)
otherVector
- a unit vector to compare (not null, unaffected)public Vector3f interpolateLocal(Vector3f finalVec, float changeAmnt)
this = (1 - changeAmnt) * this + changeAmnt * finalVec
finalVec
- the desired value when changeAmnt=1 (not null, unaffected
unless it's this
)changeAmnt
- the fractional change amountpublic Vector3f interpolateLocal(Vector3f beginVec, Vector3f finalVec, float changeAmnt)
this = (1 - changeAmnt) * beginVec + changeAmnt * finalVec
beginVec
- the desired value when changeAmnt=0 (not null, unaffected
unless it's this
)finalVec
- the desired value when changeAmnt=1 (not null, unaffected
unless it's this
)changeAmnt
- the fractional change amountpublic static boolean isValidVector(Vector3f vector)
vector
- the vector to test (unaffected)public 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
- storage for the components (must have length≥3) or null
for a new float[3]floats
or a new float[3])public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the object to compare (may be null, unaffected)public boolean isSimilar(Vector3f other, float epsilon)
other
- the vector to compare (not null, unaffected)epsilon
- the tolerance for each componentpublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
(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()
x
componentpublic Vector3f setX(float x)
x
- the desired valuepublic float getY()
y
componentpublic Vector3f setY(float y)
y
- the desired valuepublic float getZ()
z
componentpublic Vector3f setZ(float z)
z
- the desired valuepublic float get(int index)
index
- 0, 1, or 2java.lang.IllegalArgumentException
- if index is not 0, 1, or 2public void set(int index, float value)
index
- which component to set: 0 → the X component, 1 →
the Y component, 2 → the Z componentvalue
- the desired component valuejava.lang.IllegalArgumentException
- if index is not 0, 1, or 2