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 Vec3f
ONE
static Vec3f
UNIT_Y
static Vec3f
UNIT_Y_NEG
static Vec3f
UNIT_Z
static Vec3f
UNIT_Z_NEG
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vec3f
add(float dx, float dy, float dz)
this = this + { dx, dy, dz }, returns this.Vec3f
add(Vec3f b)
this = this + b, returns this.float
angle(Vec3f o)
Return the angle between two vectors in radiansVec3f
copy()
float
cosAngle(Vec3f o)
Return the cosines of the angle between two vectorsVec3f
cross(Vec3f arg)
Returns this cross arg; creates new vectorVec3f
cross(Vec3f a, Vec3f b)
this = a cross b.float
dist(Vec3f o)
Return the distance between this vector and the given one.float
distSq(Vec3f o)
Return the squared distance between this vector and the given one.float
dot(Vec3f o)
Return the dot product of this vector and the given oneboolean
equals(Object o)
float[]
get(float[] xyz)
xyz = this, returns xyz.float
get(int i)
Gets the ith component, 0 <= i < 3boolean
isEqual(Vec3f o)
Equals check usingFloatUtil.EPSILON
value andFloatUtil.isEqual(float, float, float)
.boolean
isEqual(Vec3f 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 magnitudeVec3f
max(Vec3f m)
this = max(this, m), returns this.Vec3f
min(Vec3f m)
this = min(this, m), returns this.Vec3f
minus(Vec3f arg)
Returns this - arg; creates new vectorVec3f
minus(Vec3f a, Vec3f b)
this = a - b, returns this.Vec3f
mul(float val)
Returns this * val; creates new vectorVec3f
mul(Vec3f a, Vec3f b)
this = a * b, returns this.Vec3f
normalize()
Normalize this vector in placeVec3f
plus(Vec3f arg)
Returns this + arg; creates new vectorVec3f
plus(Vec3f a, Vec3f b)
this = a + b, returns this.Vec3f
scale(float s)
this = this * s, returns this.Vec3f
scale(float sx, float sy, float sz)
this = this * { sx, sy, sz }, returns this.Vec3f
set(float[] xyz)
this = xyz, returns this.Vec3f
set(float x, float y, float z)
this = { x, y, z }, returns this.void
set(int i, float val)
Sets the ith component, 0 <= i < 3Vec3f
set(Vec2f o, float z)
this = { o, z }, returns this.Vec3f
set(Vec3f o)
this = o, returns this.Vec3f
set(Vec4f o)
this = o while dropping w, returns this.void
setX(float x)
void
setY(float y)
void
setZ(float z)
Vec3f
sub(Vec3f b)
this = this - b, returns this.String
toString()
float
x()
float
y()
float
z()
-
-
-
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.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(Vec3f 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.
-
-