public final class Vector3f
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Methods with names ending in "Local" modify the current instance. They are used to to avoid creating temporary vectors.
| Modifier and Type | Field and Description |
|---|---|
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.
|
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.
|
float |
distance(Vector3f v)
Returns the distance between this vector and the argument.
|
Vector3f |
divide(float x,
float y,
float z)
Divides component-wise by the specified components and returns the
quotient as a new instance.
|
Vector3f |
divide(Vector3f divisor)
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(float x,
float y,
float z)
Divides component-wise by the specified components returns the (modified)
current instance.
|
Vector3f |
divideLocal(Vector3f divisor)
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.
|
float |
get(int index)
Returns the indexed component.
|
int |
hashCode()
Returns a hash code.
|
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 |
mult(float scalar)
Multiplies with the argument and returns the product as a new instance.
|
Vector3f |
mult(float x,
float y,
float z)
Multiplies component-wise by the specified components 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 |
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 |
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.
|
java.lang.String |
toString()
Returns a string representation of the vector, which is unaffected.
|
Vector3f |
zero()
Sets all 3 components to zero.
|
public static final Vector3f ZERO
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 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 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 (X,Y,Z) (either result or a new
Vector3f)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 boolean isUnitVector()
public float length()
public float lengthSquared()
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(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, 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 divideLocal(float scalar)
scalar - the divisorpublic Vector3f divideLocal(float x, float y, float z)
x - the divisor for the X componenty - the divisor for the Y componentz - the divisor for the Z componentpublic Vector3f divide(Vector3f divisor)
divisor - the divisor (not null, unaffected)public Vector3f divide(float x, float y, float z)
x - the divisor for the X componenty - the divisor for the Y componentz - the divisor for the Z componentpublic Vector3f divideLocal(Vector3f divisor)
divisor - the divisor (not null, unaffected unless it's
this)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 zero()
public static boolean isValidVector(Vector3f vector)
vector - the vector to test (unaffected)public Vector3f clone()
clone in class java.lang.Objectpublic boolean equals(java.lang.Object o)
o is null, false is returned. Either way, the current instance is
unaffected.equals in class java.lang.Objecto - the object to compare (may be null, unaffected)this and o have identical values,
otherwise falsepublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
(1.0, 0.0, 0.0)
toString in class java.lang.Objectpublic 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