java.lang.Object
com.github.stephengold.joltjni.Vec3
- All Implemented Interfaces:
Vec3Arg
A vector composed of 3 single-precision components, used to represent
directions, extents, forces, impulses, offsets, scaling factors, torques, and
velocities in 3-dimensional space.
-
Constructor Summary
ConstructorsConstructorDescriptionVec3()Instantiate an all-zero vector (0,0,0).Vec3(double x, double y, double z) Instantiate a vector with the specified components.Vec3(float[] array) Instantiate from the specified array.Vec3(float x, float y, float z) Instantiate a vector with the specified components.Instantiate from aFloat3.Instantiate from a location vector.Instantiate a copy of the argument.Vec3(FloatBuffer buffer) Instantiate from a buffer. -
Method Summary
Modifier and TypeMethodDescriptionabs()Return the absolute value of each component.voidaddInPlace(float xOffset, float yOffset, float zOffset) Add the specified offsets.voidcopyTo(FloatBuffer storeFloats) Write all 3 components to the start of the specified buffer.voidcopyTo(FloatBuffer storeFloats, int startPos) Write all 3 components to the specified position in the specified buffer.Return the cross product with the argument.floatReturn the dot product with the argument.booleanTests for exact equality with the argument, distinguishing -0 from 0.floatget(int index) Return the specified component.Return an arbitrary unit vector perpendicular to the current vector.getSign()Return the component-wise (binary) sign.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.booleanTest whether the specified vector lies within the specified squared distance of this one.booleanisFinite()Test whether the vector contains infinities or NaNs.booleanisNan()Test whether the vector contains NaNs.booleanTest whether the squared length is within 10^-12 of zero.booleanisNearZero(float tolerance) Test whether the squared length is within the specified tolerance of zero.booleanTest whether the vector is normalized to within a tolerance of 10^-6.booleanisNormalized(float tolerance) Test whether the vector is normalized to within the specified tolerance.floatlength()Return the length.floatlengthSq()Return the squared length.voidloadOne()Set all components to 1.voidloadZero()Set all components to 0.Generate a unit vector with the same direction.normalizedOr(Vec3Arg zeroValue) Return a copy of the argument if the length of the current vector is zero.voidChange the current vector to a unit vector with the same direction.voidput(FloatBuffer storeBuffer) Write all 3 components to the specified buffer and advance the buffer's position by 3.Generate the component-wise reciprocal.floatReturn the maximum component.floatReturn the minimum component.voidrotateInPlace(QuatArg rotation) Rotate the current vector by the specified quaternion.static Vec3Return the bitwise AND of the specified vectors.static Vec3sAxisX()Create a unit vector along the 1st (X) principal axis.static Vec3sAxisY()Create a unit vector along the 2nd (Y) principal axis.static Vec3sAxisZ()Create a unit vector along the 3rd (Z) principal axis.voidscaleInPlace(float scale) Uniformly scale all 3 components.voidscaleInPlace(float xScale, float yScale, float zScale) Separately scale each component.voidset(float[] array) Set all 3 components from the specified array.voidset(float x, float y, float z) Set all 3 components to specified values.voidSet all 3 components from the specified location vector.voidSet all 3 components from the argument.voidset(FloatBuffer buffer) Set all 3 components from the specified buffer.voidset(FloatBuffer buffer, int startPos) Set all 3 components from the specified position in the specified buffer.setX(float x) Alter the first (X) component.setY(float y) Alter the 2nd (Y) component.setZ(float z) Alter the 3rd (Z) component.static UVec4Component-wise comparison of 2 vectors.static UVec4sGreaterOrEqual(Vec3Arg v1, Vec3Arg v2) Component-wise comparison of 2 vectors.static UVec4Component-wise comparison of 2 vectors.static UVec4sLessOrEqual(Vec3Arg v1, Vec3Arg v2) Component-wise comparison of 2 vectors.static Vec3sOne()Create a vector with all components set to one.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 Vec3sRandom(RandomNumberEngine engine) Generate a pseudo-random unit vector.static Vec3sReplicate(float value) Create a vector with all components identical.static Vec3Component-wise selection between 2 specified vectors.voidReplace any -0 elements with +0, in preparation for hashing.voidstoreFloat3(Float3 target) Copy to aFloat3object.static Vec3Return the component-wise sum of the specified vectors.static Vec3sUnitSpherical(float theta, float phi) Generate a unit vector with the specified spherical coordinates.swizzle(int xi, int yi, int zi) Copy the specified components to a new vector.static Vec3sZero()Create a vector with all components zero.float[]toArray()Copy the components to an array.toBuffer()Copy the components to a direct buffer.toRVec3()Copy the components to a new location vector.toString()Return a string representation of the vector, which is unaffected.voidtransformInPlace(Mat44Arg matrix) Transform the current vector by the specified matrix.
-
Constructor Details
-
Vec3
public Vec3()Instantiate an all-zero vector (0,0,0). -
Vec3
public Vec3(double x, double y, double z) Instantiate a vector with the specified components.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z component
-
Vec3
public Vec3(float x, float y, float z) Instantiate a vector with the specified components.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z component
-
Vec3
public Vec3(float[] array) Instantiate from the specified array.- Parameters:
array- the desired component values (not null, length≥3, unaffected)
-
Vec3
Instantiate from aFloat3.- Parameters:
float3- the desired component values (not null, unaffected)
-
Vec3
Instantiate from a buffer.- Parameters:
buffer- the desired component values (not null, unaffected, capacity≥3)
-
Vec3
Instantiate from a location vector.- Parameters:
vec- the vector to convert (not null, unaffected)
-
Vec3
Instantiate a copy of the argument.- Parameters:
vec- the vector to copy (not null, unaffected)
-
-
Method Details
-
addInPlace
public void addInPlace(float xOffset, float yOffset, float zOffset) Add the specified offsets.- Parameters:
xOffset- the amount to add to the X componentyOffset- the amount to add to the Y componentzOffset- the amount to add to the Z component
-
loadOne
public void loadOne()Set all components to 1. -
loadZero
public void loadZero()Set all components to 0. -
normalizeInPlace
public void normalizeInPlace()Change the current vector to a unit vector with the same direction. -
rotateInPlace
Rotate the current vector by the specified quaternion.- Parameters:
rotation- the rotation to apply (not null, normalized, unaffected)
-
sAnd
Return the bitwise AND of the specified vectors.- Parameters:
v1- the first vector (not null, unaffected)v2- the 2nd vector (not null, unaffected)- Returns:
- a new vector
-
sAxisX
Create a unit vector along the 1st (X) principal axis.- Returns:
- a new vector
-
sAxisY
Create a unit vector along the 2nd (Y) principal axis.- Returns:
- a new vector
-
sAxisZ
Create a unit vector along the 3rd (Z) principal axis.- Returns:
- a new vector
-
scaleInPlace
public void scaleInPlace(float scale) Uniformly scale all 3 components.- Parameters:
scale- the scale factor to apply
-
scaleInPlace
public void scaleInPlace(float xScale, float yScale, float zScale) Separately scale each component.- Parameters:
xScale- the scale factor to apply to the X componentyScale- the scale factor to apply to the Y componentzScale- the scale factor to apply to the Z component
-
set
public void set(float x, float y, float z) Set all 3 components to specified values.- Parameters:
x- the desired X componenty- the desired Y componentz- the desired Z component
-
set
public void set(float[] array) Set all 3 components from the specified array.- Parameters:
array- the desired component values (not null, length≥3, unaffected)
-
set
Set all 3 components from the specified buffer.- Parameters:
buffer- the desired component values (not null, length≥3, unaffected)
-
set
Set all 3 components from the specified position in the specified buffer.- Parameters:
buffer- the desired component values (not null, unaffected)startPos- the starting position in the buffer (≥0)
-
set
Set all 3 components from the specified location vector.- Parameters:
source- the vector to copy (not null, unaffected)
-
set
Set all 3 components from the argument.- Parameters:
source- the vector to copy (not null, unaffected)
-
setX
Alter the first (X) component.- Parameters:
x- the desired value- Returns:
- the modified vector, for chaining
-
setY
Alter the 2nd (Y) component.- Parameters:
y- the desired value- Returns:
- the modified vector, for chaining
-
setZ
Alter the 3rd (Z) component.- Parameters:
z- the desired value- Returns:
- the modified vector, for chaining
-
sGreater
Component-wise comparison of 2 vectors.- Parameters:
v1- the first vector (not null, unaffected)v2- the 2nd vector (not null, unaffected)- Returns:
- a new vector (each component 0 or -1)
-
sGreaterOrEqual
Component-wise comparison of 2 vectors.- Parameters:
v1- the first vector (not null, unaffected)v2- the 2nd vector (not null, unaffected)- Returns:
- a new vector (each component 0 or -1)
-
sLess
Component-wise comparison of 2 vectors.- Parameters:
v1- the first vector (not null, unaffected)v2- the 2nd vector (not null, unaffected)- Returns:
- a new vector (each component 0 or -1)
-
sLessOrEqual
Component-wise comparison of 2 vectors.- Parameters:
v1- the first vector (not null, unaffected)v2- the 2nd vector (not null, unaffected)- Returns:
- a new vector (each component 0 or -1)
-
sOne
Create a vector with all components set to one.- Returns:
- a new vector
-
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. -
sRandom
Generate a pseudo-random unit vector.The results are not uniformly distributed over the unit sphere.
- Parameters:
engine- the generator to use (not null)- Returns:
- a new unit vector
-
sReplicate
Create a vector with all components identical.- Parameters:
value- the desired component value- Returns:
- a new vector
-
sSelect
Component-wise selection between 2 specified vectors.- Parameters:
notSet- components to select where the control is zero (not null, unaffected)set- components to select where the control is non-zero (not null, unaffected)control- to control the selection (not null, unaffected)- Returns:
- a new vector
-
standardizeInPlace
public void standardizeInPlace()Replace any -0 elements with +0, in preparation for hashing. -
sum
Return the component-wise sum of the specified vectors.- Parameters:
vArray- an array of input vectors (not null, unaffected)- Returns:
- a new vector
-
sUnitSpherical
Generate a unit vector with the specified spherical coordinates.- Parameters:
theta- angle from the +Z axis (in radians)phi- angle from the +X axis in the X-Y plane (in radians)- Returns:
- a new unit vector
-
sZero
Create a vector with all components zero.- Returns:
- a new vector
-
transformInPlace
Transform the current vector by the specified matrix.- Parameters:
matrix- the transformation to apply (not null, unaffected)
-
abs
Return the absolute value of each component. The vector is unaffected. -
copyTo
Write all 3 components to the start of the specified buffer. The vector is unaffected. -
copyTo
Write all 3 components to the specified position in the specified buffer. -
cross
Return the cross product with the argument. Both vectors are unaffected. -
dot
Return the dot product with the argument. Both vectors are unaffected. -
get
public float get(int index) Return the specified component. The vector is unaffected.- Specified by:
getin interfaceVec3Arg- Parameters:
index- 0, 1, or 2- Returns:
- the X component if index=0, the Y component if index=1, or the Z component if index=2
- Throws:
IllegalArgumentException- if index is not 0, 1, or 2
-
getNormalizedPerpendicular
Return an arbitrary unit vector perpendicular to the current vector. The current vector is unaffected.- Specified by:
getNormalizedPerpendicularin interfaceVec3Arg- Returns:
- a new vector
-
getSign
Return the component-wise (binary) sign. The current 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. -
isFinite
public boolean isFinite()Test whether the vector contains infinities or NaNs. The vector is unaffected. -
isNan
public boolean isNan()Test whether the vector contains NaNs. The vector is unaffected. -
isNearZero
public boolean isNearZero()Test whether the squared length is within 10^-12 of zero. The vector is unaffected.- Specified by:
isNearZeroin interfaceVec3Arg- Returns:
trueif nearly zero, otherwisefalse
-
isNearZero
public boolean isNearZero(float tolerance) Test whether the squared length is within the specified tolerance of zero. The vector is unaffected.- Specified by:
isNearZeroin interfaceVec3Arg- Parameters:
tolerance- the desired tolerance (≥0, default=1e-12)- Returns:
trueif nearly zero, otherwisefalse
-
isNormalized
public boolean isNormalized()Test whether the vector is normalized to within a tolerance of 10^-6. The vector is unaffected.- Specified by:
isNormalizedin interfaceVec3Arg- Returns:
trueif normalized, otherwisefalse
-
isNormalized
public boolean isNormalized(float tolerance) Test whether the vector is normalized to within the specified tolerance. The vector is unaffected.- Specified by:
isNormalizedin interfaceVec3Arg- Parameters:
tolerance- the desired tolerance (≥0, default=1e-6)- Returns:
trueif normalized, otherwisefalse
-
isClose
Test whether the specified vector lies within the specified squared distance of this one. Both vectors are unaffected. -
length
public float length()Return the length. The vector is unaffected. -
lengthSq
public float lengthSq()Return the squared length. The vector is unaffected. -
normalized
Generate a unit vector with the same direction. The current vector is unaffected.- Specified by:
normalizedin interfaceVec3Arg- Returns:
- a new vector
-
normalizedOr
Return a copy of the argument if the length of the current vector is zero. Otherwise, generate a unit vector with the same direction as the current vector. The current vector is unaffected.- Specified by:
normalizedOrin interfaceVec3Arg- Parameters:
zeroValue- the value to return if the length is zero (not null, unaffected)- Returns:
- a new vector
-
put
Write all 3 components to the specified buffer and advance the buffer's position by 3. The vector is unaffected. -
reciprocal
Generate the component-wise reciprocal. The current vector is unaffected.- Specified by:
reciprocalin interfaceVec3Arg- Returns:
- a new vector
-
reduceMax
public float reduceMax()Return the maximum component. The current vector is unaffected. -
reduceMin
public float reduceMin()Return the minimum component. The current vector is unaffected. -
storeFloat3
Copy to aFloat3object. The vector is unaffected.- Specified by:
storeFloat3in interfaceVec3Arg- Parameters:
target- the destination (not null, modified)
-
swizzle
Copy the specified components to a new vector. The current vector is unaffected.- Specified by:
swizzlein interfaceVec3Arg- Parameters:
xi- index of the component to copy to the first (X) component of the result (0, 1, or 2)yi- index of the component to copy to the 2nd (Y) component of the result (0, 1, or 2)zi- index of the component to copy to the 3rd (Z) component of the result (0, 1, or 2)- Returns:
- the new vector
-
toArray
public float[] toArray()Copy the components to an array. The vector is unaffected. -
toBuffer
Copy the components to a direct buffer. The vector is unaffected. -
toRVec3
Copy the components to a new location vector. The current 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:Vec3(0.0 0.0 0.0)
-