Package limn.math
Record Class Vec3
java.lang.Object
java.lang.Record
limn.math.Vec3
An immutable 3-component vector (single precision), right-handed. Used for
positions, directions, normals and colors in the 3D subsystem. Operations
return new instances, cheap enough for UI-scale 3D (a handful of transforms
per frame, not a hot game loop); the allocation-free forms live in
MutVec3 and the *Into methods elsewhere in this package.
The arithmetic is component-wise; the operations with an edge case worth knowing are
div(float), normalize(), lerp(limn.math.Vec3, float) and get(int).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatdiv(float s) Component-wise division.floatfinal booleanIndicates whether some other object is "equal to" this one.floatget(int i) Component by index,0= x,1= y,2= z.final inthashCode()Returns a hash code value for this object.floatlength()floatLinear interpolation towardso.mul(float s) Component-wise multiply (e.g.negate()Unit vector in the same direction; returnsZEROfor a zero-length input.static Vec3of(float s) The same value in all three components.final StringtoString()Returns a string representation of this record class.toVec4(float w) This vector with an explicit w:1for a position,0for a direction.floatx()Returns the value of thexrecord component.floaty()Returns the value of theyrecord component.floatz()Returns the value of thezrecord component.
-
Field Details
-
ZERO
-
ONE
-
UNIT_X
-
UNIT_Y
-
UNIT_Z
-
-
Constructor Details
-
Vec3
public Vec3(float x, float y, float z) Creates an instance of aVec3record class.- Parameters:
x- the value for thexrecord componenty- the value for theyrecord componentz- the value for thezrecord component
-
-
Method Details
-
of
The same value in all three components. -
add
- Returns:
- the sum of this vector and
o
-
sub
- Returns:
- this vector minus
o
-
mul
- Returns:
- this vector scaled by
s
-
mul
Component-wise multiply (e.g. modulating a color). -
div
Component-wise division. Not guarded:s == 0yields infinities or NaN rather than throwing, so divide by a length only after checking it. -
negate
- Returns:
- this vector pointing the other way
-
dot
- Returns:
- the dot product of this vector and
o
-
cross
- Returns:
- the cross product, right-handed:
UNIT_X.cross(UNIT_Y)isUNIT_Z
-
lengthSquared
public float lengthSquared()- Returns:
- the squared length, which needs no square root
-
length
public float length()- Returns:
- the Euclidean length
-
distance
- Returns:
- the distance between this point and
o
-
normalize
Unit vector in the same direction; returnsZEROfor a zero-length input. -
lerp
Linear interpolation towardso.tis not clamped: values outside[0,1]extrapolate, which is what makes this usable for easing curves that overshoot. -
min
- Returns:
- the smaller of each pair of components
-
max
- Returns:
- the larger of each pair of components
-
get
public float get(int i) Component by index,0= x,1= y,2= z.- Throws:
IndexOutOfBoundsException- for any other index
-
toVec4
This vector with an explicit w:1for a position,0for a direction. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
x
public float x()Returns the value of thexrecord component.- Returns:
- the value of the
xrecord component
-
y
public float y()Returns the value of theyrecord component.- Returns:
- the value of the
yrecord component
-
z
public float z()Returns the value of thezrecord component.- Returns:
- the value of the
zrecord component
-