Package com.jogamp.opengl.math
Class Vec3f
- java.lang.Object
-
- com.jogamp.opengl.math.Vec3f
-
public final class Vec3f extends Object
3D Vector based upon three 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.
-
-
Field Summary
Fields Modifier and Type Field Description static Vec3fONEstatic Vec3fUNIT_Ystatic Vec3fUNIT_Y_NEGstatic Vec3fUNIT_Zstatic Vec3fUNIT_Z_NEG
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vec3fadd(float dx, float dy, float dz)this = this + { dx, dy, dz }, returns this.Vec3fadd(Vec3f b)this = this + b, returns this.floatangle(Vec3f o)Return the angle between two vectors in radiansVec3fcopy()floatcosAngle(Vec3f o)Return the cosines of the angle between two vectorsVec3fcross(Vec3f arg)Returns this cross arg; creates new vectorVec3fcross(Vec3f a, Vec3f b)this = a cross b.floatdist(Vec3f o)Return the distance between this vector and the given one.floatdistSq(Vec3f o)Return the squared distance between this vector and the given one.floatdot(Vec3f o)Return the dot product of this vector and the given onebooleanequals(Object o)float[]get(float[] xyz)xyz = this, returns xyz.floatget(int i)Gets the ith component, 0 <= i < 3booleanisEqual(Vec3f o)Equals check usingFloatUtil.EPSILONvalue andFloatUtil.isEqual(float, float, float).booleanisEqual(Vec3f o, float epsilon)Equals check using a givenFloatUtil.EPSILONvalue andFloatUtil.isEqual(float, float, float).booleanisZero()Return true if all components are zero, i.e.floatlength()Return the length of this vector, a.k.a the norm or magnitudefloatlengthSq()Return the squared length of this vector, a.k.a the squared norm or squared magnitudeVec3fmax(Vec3f m)this = max(this, m), returns this.Vec3fmin(Vec3f m)this = min(this, m), returns this.Vec3fminus(Vec3f arg)Returns this - arg; creates new vectorVec3fminus(Vec3f a, Vec3f b)this = a - b, returns this.Vec3fmul(float val)Returns this * val; creates new vectorVec3fmul(Vec3f a, Vec3f b)this = a * b, returns this.Vec3fnormalize()Normalize this vector in placeVec3fplus(Vec3f arg)Returns this + arg; creates new vectorVec3fplus(Vec3f a, Vec3f b)this = a + b, returns this.Vec3fscale(float s)this = this * s, returns this.Vec3fscale(float sx, float sy, float sz)this = this * { sx, sy, sz }, returns this.Vec3fset(float[] xyz)this = xyz, returns this.Vec3fset(float x, float y, float z)this = { x, y, z }, returns this.voidset(int i, float val)Sets the ith component, 0 <= i < 3Vec3fset(Vec2f o, float z)this = { o, z }, returns this.Vec3fset(Vec3f o)this = o, returns this.Vec3fset(Vec4f o)this = o while dropping w, returns this.voidsetX(float x)voidsetY(float y)voidsetZ(float z)Vec3fsub(Vec3f b)this = this - b, returns this.StringtoString()floatx()floaty()floatz()
-
-
-
Method Detail
-
copy
public Vec3f copy()
-
set
public Vec3f set(float x, float y, float z)
this = { x, y, z }, returns this.
-
set
public Vec3f set(float[] xyz)
this = xyz, returns this.
-
set
public void set(int i, float val)Sets the ith component, 0 <= i < 3
-
get
public float[] get(float[] xyz)
xyz = this, returns xyz.
-
get
public float get(int i)
Gets the ith component, 0 <= i < 3
-
x
public float x()
-
y
public float y()
-
z
public float z()
-
setX
public void setX(float x)
-
setY
public void setY(float y)
-
setZ
public void setZ(float z)
-
mul
public Vec3f mul(float val)
Returns this * val; creates new vector
-
scale
public Vec3f scale(float s)
this = this * s, returns this.
-
scale
public Vec3f scale(float sx, float sy, float sz)
this = this * { sx, sy, sz }, returns this.
-
add
public Vec3f add(float dx, float dy, float dz)
this = this + { dx, dy, dz }, 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 Vec3f normalize()
Normalize this vector in place
-
distSq
public float distSq(Vec3f 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(Vec3f o)
Return the distance between this vector and the given one.
-
dot
public float dot(Vec3f o)
Return the dot product of this vector and the given one- Returns:
- the dot product as float
-
cross
public Vec3f cross(Vec3f a, Vec3f b)
this = a cross b. NOTE: "this" must be a different vector than both a and b.
-
cosAngle
public float cosAngle(Vec3f o)
Return the cosines of the angle between two vectors
-
angle
public float angle(Vec3f o)
Return the angle between two vectors in radians
-
isEqual
public boolean isEqual(Vec3f o, float epsilon)
Equals check using a givenFloatUtil.EPSILONvalue 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(Vec3f o)
Equals check usingFloatUtil.EPSILONvalue 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.
-
-