Package com.jogamp.opengl.math
Class Vec4f
- java.lang.Object
-
- com.jogamp.opengl.math.Vec4f
-
public final class Vec4f extends Object
4D Vector based upon four float components. Implementation borrowed from [gfxbox2](https://jausoft.com/cgit/cs_class/gfxbox2.git/tree/include/pixel/pixel3f.hpp#n29) and its data layout from JOAL's Vec3f.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vec4f
add(float dx, float dy, float dz, float dw)
this = this + { dx, dy, dz, dw }, returns this.Vec4f
add(Vec4f b)
this = this + b, returns this.float
angle(Vec4f o)
Return the angle between two vectors in radiansVec4f
copy()
float
cosAngle(Vec4f o)
Return the cosines of the angle between two vectorsfloat
dist(Vec4f o)
Return the distance between this vector and the given one.float
distSq(Vec4f o)
Return the squared distance between this vector and the given one.float
dot(Vec4f o)
Return the dot product of this vector and the given oneboolean
equals(Object o)
float[]
get(float[] xyzw)
xyzw = this, returns xyzw.float
get(int i)
Gets the ith component, 0 <= i < 4boolean
isEqual(Vec4f o)
Equals check usingFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.boolean
isEqual(Vec4f o, float epsilon)
Equals check using a givenFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.boolean
isZero()
Return true if all components are zero, i.e.float
length()
Return the length of this vector, a.k.a the norm or magnitudefloat
lengthSq()
Return the squared length of this vector, a.k.a the squared norm or squared magnitudeVec4f
max(Vec4f m)
this = max(this, m), returns this.Vec4f
min(Vec4f m)
this = min(this, m), returns this.Vec4f
minus(Vec4f arg)
Returns this - arg; creates new vectorVec4f
minus(Vec4f a, Vec4f b)
this = a - b, returns this.Vec4f
mul(float val)
Returns this * val; creates new vectorVec4f
mul(Vec4f a, Vec4f b)
this = a * b, returns this.Vec4f
normalize()
Normalize this vector in placeVec4f
plus(Vec4f arg)
Returns this + arg; creates new vectorVec4f
plus(Vec4f a, Vec4f b)
this = a + b, returns this.Vec4f
scale(float s)
this = this * s, returns this.Vec4f
scale(float sx, float sy, float sz, float sw)
this = this * { sx, sy, sz, sw }, returns this.Vec4f
set(float[] xyzw)
this = xyzw, returns this.Vec4f
set(float x, float y, float z, float w)
this = { x, y, z, w }, returns this.void
set(int i, float val)
Sets the ith component, 0 <= i < 4Vec4f
set(Vec3f o, float w)
this = { o, w }, returns this.Vec4f
set(Vec4f o)
this = o, returns this.void
setW(float w)
void
setX(float x)
void
setY(float y)
void
setZ(float z)
Vec4f
sub(Vec4f b)
this = this - b, returns this.String
toString()
float
w()
float
x()
float
y()
float
z()
-
-
-
Method Detail
-
copy
public Vec4f copy()
-
set
public Vec4f set(float x, float y, float z, float w)
this = { x, y, z, w }, returns this.
-
set
public Vec4f set(float[] xyzw)
this = xyzw, returns this.
-
set
public void set(int i, float val)
Sets the ith component, 0 <= i < 4
-
get
public float[] get(float[] xyzw)
xyzw = this, returns xyzw.
-
get
public float get(int i)
Gets the ith component, 0 <= i < 4
-
x
public float x()
-
y
public float y()
-
z
public float z()
-
w
public float w()
-
setX
public void setX(float x)
-
setY
public void setY(float y)
-
setZ
public void setZ(float z)
-
setW
public void setW(float w)
-
mul
public Vec4f mul(float val)
Returns this * val; creates new vector
-
scale
public Vec4f scale(float s)
this = this * s, returns this.
-
scale
public Vec4f scale(float sx, float sy, float sz, float sw)
this = this * { sx, sy, sz, sw }, returns this.
-
add
public Vec4f add(float dx, float dy, float dz, float dw)
this = this + { dx, dy, dz, dw }, returns this.
-
isZero
public boolean isZero()
Return true if all components are zero, i.e. it's absolute value <#EPSILON
.
-
length
public float length()
Return the length of this vector, a.k.a the norm or magnitude
-
lengthSq
public float lengthSq()
Return the squared length of this vector, a.k.a the squared norm or squared magnitude
-
normalize
public Vec4f normalize()
Normalize this vector in place
-
distSq
public float distSq(Vec4f o)
Return the squared distance between this vector and the given one.When comparing the relative distance between two points it is usually sufficient to compare the squared distances, thus avoiding an expensive square root operation.
-
dist
public float dist(Vec4f o)
Return the distance between this vector and the given one.
-
dot
public float dot(Vec4f o)
Return the dot product of this vector and the given one- Returns:
- the dot product as float
-
cosAngle
public float cosAngle(Vec4f o)
Return the cosines of the angle between two vectors
-
angle
public float angle(Vec4f o)
Return the angle between two vectors in radians
-
isEqual
public boolean isEqual(Vec4f o, float epsilon)
Equals check using a givenFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.Implementation considers following corner cases:
- NaN == NaN
- +Inf == +Inf
- -Inf == -Inf
- Parameters:
o
- comparison valueepsilon
- consider usingFloatUtil.EPSILON
- Returns:
- true if all components differ less than
epsilon
, otherwise false.
-
isEqual
public boolean isEqual(Vec4f o)
Equals check usingFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.Implementation considers following corner cases:
- NaN == NaN
- +Inf == +Inf
- -Inf == -Inf
- Parameters:
o
- comparison value- Returns:
- true if all components differ less than
FloatUtil.EPSILON
, otherwise false.
-
-