java.lang.Object
com.github.stephengold.joltjni.Vec4
- All Implemented Interfaces:
Vec4Arg
A vector composed of 4 single-precision components, used to construct
matrices.
-
Constructor Summary
ConstructorsConstructorDescriptionVec4()Instantiate an all-zero vector (0,0,0,0).Vec4(double x, double y, double z, double w) Instantiate a vector with specified components.Vec4(float[] array) Instantiate a vector from the specified array.Vec4(float x, float y, float z, float w) Instantiate a vector with specified components.Instantiate from a 3-D vector.Instantiate a copy of the argument. -
Method Summary
Modifier and TypeMethodDescriptionfloatReturn the dot product with the specified vector.booleanTests for exact equality with the argument, distinguishing -0 from 0.floatget(int index) Return the specified component.floatgetW()Return the 4th (W) component in single precision.floatgetX()Return the first (X) component in single precision.floatgetY()Return the 2nd (Y) component in single precision.floatgetZ()Return the 3rd (Z) component in single precision.inthashCode()Return a hash code.voidset(float[] array) Set all 4 components from the specified array.voidset(float x, float y, float z, float w) Set all 4 components to the specified values.voidSet all 4 components from the argument.voidsetW(float w) Alter the 4th (W) component.voidsetX(float x) Alter the first (X) component.voidsetY(float y) Alter the 2nd (Y) component.voidsetZ(float z) Alter the 3rd (Z) component.voidsplatW()Copy the W component to all components.voidsplatX()Copy the X component to all components.voidsplatY()Copy the Y component to all components.voidsplatZ()Copy the Z component to all components.static Vec4sReplicate(float value) Create a vector with all components identical.static Vec4sZero()Create a vector with all components zero.float[]toArray()Copy the components to an array.toString()Return a string representation of the vector, which is unaffected.
-
Constructor Details
-
Vec4
public Vec4()Instantiate an all-zero vector (0,0,0,0). -
Vec4
public Vec4(double x, double y, double z, double w) Instantiate a vector with specified components.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z componentw- the desired W component
-
Vec4
public Vec4(float x, float y, float z, float w) Instantiate a vector with specified components.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z componentw- the desired W component
-
Vec4
public Vec4(float[] array) Instantiate a vector from the specified array.- Parameters:
array- the desired component values (not null, length≥4, unaffected)
-
Vec4
Instantiate from a 3-D vector.- Parameters:
vec- the vector to copy (not null, unaffected)w- the desired W component
-
Vec4
Instantiate a copy of the argument.- Parameters:
vec- the vector to copy (not null, unaffected)
-
-
Method Details
-
set
public void set(float x, float y, float z, float w) Set all 4 components to the specified values.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z componentw- the desired W component
-
set
public void set(float[] array) Set all 4 components from the specified array.- Parameters:
array- the desired component values (not null, length≥4, unaffected)
-
set
Set all 4 components from the argument.- Parameters:
source- the vector to copy (not null, unaffected)
-
setW
public void setW(float w) Alter the 4th (W) component.- Parameters:
w- the desired value
-
setX
public void setX(float x) Alter the first (X) component.- Parameters:
x- the desired value
-
setY
public void setY(float y) Alter the 2nd (Y) component.- Parameters:
y- the desired value
-
setZ
public void setZ(float z) Alter the 3rd (Z) component.- Parameters:
z- the desired value
-
splatW
public void splatW()Copy the W component to all components. -
splatX
public void splatX()Copy the X component to all components. -
splatY
public void splatY()Copy the Y component to all components. -
splatZ
public void splatZ()Copy the Z component to all components. -
sReplicate
Create a vector with all components identical.- Parameters:
value- the desired component value- Returns:
- a new vector
-
sZero
Create a vector with all components zero.- Returns:
- a new vector
-
dot
Return the dot product with the specified vector. The current vector is unaffected. -
get
public float get(int index) Return the specified component. The vector is unaffected.- Specified by:
getin interfaceVec4Arg- Parameters:
index- 0, 1, 2, or 3- Returns:
- the X component if index=0, the Y component if index=1, the Z component if index=2, or the W component if index=3
- Throws:
IllegalArgumentException- if index is not 0, 1, 2, or 3
-
getW
public float getW()Return the 4th (W) component in single precision. The vector is unaffected. -
getX
public float getX()Return the first (X) component in single precision. The vector is unaffected. -
getY
public float getY()Return the 2nd (Y) component in single precision. The vector is unaffected. -
getZ
public float getZ()Return the 3rd (Z) component in single precision. The vector is unaffected. -
toArray
public float[] toArray()Copy the components to an array. The vector is unaffected. -
equals
Tests for exact equality with the argument, distinguishing -0 from 0. Ifotheris null, false is returned. Either way, the current instance is unaffected. -
hashCode
public int hashCode()Return a hash code. If two vectors have identical values, they will have the same hash code. The vector is unaffected. -
toString
Return a string representation of the vector, which is unaffected. For example, a zero vector is represented by:Vec4(0.0 0.0 0.0 0.0)
-