Top Description Fields Constructors Methods
com.jogamp.opengl.math

public final Class FloatUtil

extends Object
Class Inheritance
Imports
java.nio.FloatBuffer, com.jogamp.opengl.GLException, jogamp.opengl.Debug, com.jogamp.common.os.Platform, com.jogamp.opengl.math.geom.AABBox, .Frustum

Basic Float math utility functions.

Implementation assumes linear matrix layout in column-major order matching OpenGL's implementation, illustration:

   Row-Major                  Column-Major (OpenGL):

       |  0   1   2   3 |         |  0   4   8  12 |
       |                |         |                |
       |  4   5   6   7 |         |  1   5   9  13 |
   M = |                |     M = |                |
       |  8   9  10  11 |         |  2   6  10  14 |
       |                |         |                |
       | 12  13  14  15 |         |  3   7  11  15 |

          C   R                      C   R
        m[0*4+3] = tx;             m[0+4*3] = tx;
        m[1*4+3] = ty;             m[1+4*3] = ty;
        m[2*4+3] = tz;             m[2+4*3] = tz;

Implementation utilizes unrolling of small vertices and matrices wherever possible while trying to access memory in a linear fashion for performance reasons, see:

Field Summary

Modifier and TypeField and Description
public static final boolean
private static final boolean
public static final float
E

public static final float
EPSILON

Epsilon for floating point , as once computed via getMachineEpsilon() on an AMD-64 CPU.

public static final float
HALF_PI

The value PI/2, i.e. 90 degrees in radians.

public static final float
INV_DEVIANCE

Inversion Epsilon, used with equals method to determine if two inverted matrices are close enough to be considered equal.

private static float
private static volatile boolean
public static final float
PI

The value PI, i.e. 180 degrees in radians.

public static final float
QUARTER_PI

The value PI/4, i.e. 45 degrees in radians.

public static final float
SQUARED_PI

The value PI^2.

public static final float
TWO_PI

The value 2PI, i.e. 360 degrees in radians.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static float
abs(final float a)

public static float
acos(final float a)

public static float
asin(final float a)

public static float
atan(final float a)

public static float
atan2(final float y, final float x)

private static void
public static int
compare(final float a, final float b)

Return true if both values are equal w/o regarding an epsilon.

public static int
compare(final float a, final float b, final float epsilon)

Return true if both values are equal, i.e. their absolute delta < epsilon.

public static float[]

Returns:

given result vector v_out for chaining
copyMatrixColumn
(final float[]
input column-major matrix
m_in
,
final int
offset to input matrix
m_in_off
,
final int
named column to copy
column
,
final float[]
the column-vector storage, at least 3 components long
v_out
,
final int
offset to storage
v_out_off
)

Copy the named column of the given column-major matrix to v_out.

public static float[]

Returns:

given result vector v_out for chaining
copyMatrixRow
(final float[]
input column-major matrix
m_in
,
final int
offset to input matrix
m_in_off
,
final int
named row to copy
row
,
final float[]
the row-vector storage, at least 3 components long
v_out
,
final int
offset to storage
v_out_off
)

Copy the named row of the given column-major matrix to v_out.

public static float
cos(final float a)

public static float
getMachineEpsilon()

Return computed machine Epsilon value.

public static float
getOrthoWinZ(final float orthoZ, final float zNear, final float zFar)

Returns orthogonal distance (1f/zNear-1f/orthoDist)/(1f/zNear-1f/zFar);

public static float

Returns:

smallest resolvable Z separation at this range.
getZBufferEpsilon
(final int
number of bits of Z precision, i.e. z-buffer depth
zBits
,
final float
distance from the eye to the object
z
,
final float
distance from eye to near clip plane
zNear
)

Returns resolution of Z buffer of given parameter, see Love Your Z-Buffer.

public static int

Returns:

z buffer value
getZBufferValue
(final int
number of bits of Z precision, i.e. z-buffer depth
zBits
,
final float
distance from the eye to the object
z
,
final float
distance from eye to near clip plane
zNear
,
final float
distance from eye to far clip plane
zFar
)

Returns Z buffer value of given parameter, see Love Your Z-Buffer.

public static float[]

Returns:

given result matrix mres for chaining if successful, otherwise null. See above.
invertMatrix
(final float[]
4x4 matrix in column-major order, the source
msrc
,
final int
offset in given array msrc, i.e. start of the 4x4 matrix
msrc_offset
,
final float[]
4x4 matrix in column-major order, the result - may be msrc (in-place)
mres
,
final int
offset in given array mres, i.e. start of the 4x4 matrix - may be msrc_offset (in-place)
mres_offset
)

Invert the given matrix.

public static float[]

Returns:

given result matrix mres for chaining if successful, otherwise null. See above.
invertMatrix
(final float[]
4x4 matrix in column-major order, the source
msrc
,
final float[]
4x4 matrix in column-major order, the result - may be msrc (in-place)
mres
)

Invert the given matrix.

public static boolean
isEqual(final float a, final float b)

Return true if both values are equal w/o regarding an epsilon.

public static boolean
isEqual(final float a, final float b, final float epsilon)

Return true if both values are equal, i.e. their absolute delta < epsilon.

public static boolean
isZero(final float a, final float epsilon)

Return true if value is zero, i.e. it's absolute value < epsilon.

public static float[]

Returns:

given matrix for chaining
makeFrustum
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final boolean
if true, given matrix will be initialized w/ identity matrix, otherwise only the frustum fields are set.
initM
,
final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)

Make given matrix the frustum matrix based on given parameters.

public static float[]

Returns:

given matrix for chaining
makeIdentity
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
)

Make matrix an identity matrix

public static float[]

Returns:

given matrix for chaining
makeIdentity
(final float[]
4x4 matrix in column-major order (also result)
m
)

Make matrix an identity matrix

public static float[]

Returns:

given matrix m for chaining
makeLookAt
(final float[]
4x4 matrix in column-major order, result only
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final float[]
3 component eye vector
eye
,
final int eye_offset, final float[]
3 component center vector
center
,
final int center_offset, final float[]
3 component up vector
up
,
final int up_offset, final float[]
temp float[16] storage
mat4Tmp
)

Make given matrix the look-at matrix based on given parameters.

public static float[]

Returns:

given matrix for chaining
makeOrtho
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final boolean
if true, given matrix will be initialized w/ identity matrix, otherwise only the orthogonal fields are set.
initM
,
final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)

Make given matrix the orthogonal matrix based on given parameters.

public static float[]

Returns:

given matrix for chaining
makePerspective
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_off
,
final boolean
if true, given matrix will be initialized w/ identity matrix, otherwise only the frustum fields are set.
initM
,
final float
angle in radians
fovy_rad
,
final float
aspect ratio width / height
aspect
,
final float zNear, final float zFar)

Make given matrix the perspective frustum matrix based on given parameters.

public static float[]

Returns:

given matrix for chaining
makePerspective
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final boolean
if true, given matrix will be initialized w/ identity matrix, otherwise only the frustum fields are set.
initM
,
final FovHVHalves
FovHVHalves field of view in both directions, may not be centered, either in radians or tangent
fovhv
,
final float zNear, final float zFar)

Make given matrix the perspective frustum matrix based on given parameters.

public static float[]

Returns:

given matrix m for chaining or null if either delta value is <= zero.
makePick
(final float[]
4x4 matrix in column-major order, result only
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final float
the center x-component of a picking region in window coordinates
x
,
final float
the center y-component of a picking region in window coordinates
y
,
final float
the width of the picking region in window coordinates.
deltaX
,
final float
the height of the picking region in window coordinates.
deltaY
,
final int[]
4 component viewport vector
viewport
,
final int viewport_offset, final float[]
temp float[16] storage
mat4Tmp
)

Make given matrix the pick matrix based on given parameters.

public static float[]

Returns:

given matrix for chaining
makeRotationAxis
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final float angrad, float x, float y, float z, final float[] tmpVec3f)

Make a rotation matrix from the given axis and angle in radians.

public static float[]

Returns:

given matrix for chaining

Implementation does not use Quaternion and hence is exposed to Gimbal-Lock

makeRotationEuler
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final float
the Euler pitch angle in radians. (rotation about the X axis)
bankX
,
final float
the Euler yaw angle in radians. (rotation about the Y axis)
headingY
,
final float
the Euler roll angle in radians. (rotation about the Z axis)
attitudeZ
)

Make a concatenated rotation matrix in column-major order from the given Euler rotation angles in radians.

public static float[]

Returns:

given matrix for chaining
makeScale
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final boolean
if true, given matrix will be initialized w/ identity matrix, otherwise only the diagonal and last-row is set. The latter can be utilized to share a once identity set matrix for scaling and translation, while leaving the other fields untouched for performance reasons.
initM
,
final float sx, final float sy, final float sz)

Make a scale matrix in column-major order from the given axis factors

     Scale matrix (Any Order):
     x 0 0 0
     0 y 0 0
     0 0 z 0
     0 0 0 1
public static float[]

Returns:

given matrix for chaining
makeScale
(final float[]
4x4 matrix in column-major order (also result)
m
,
final boolean
if true, given matrix will be initialized w/ identity matrix, otherwise only the diagonal and last-row is set. The latter can be utilized to share a once identity set matrix for scaling and translation, while leaving the other fields untouched for performance reasons.
initM
,
final float sx, final float sy, final float sz)

Make a scale matrix in column-major order from the given axis factors

     Scale matrix (Any Order):
     x 0 0 0
     0 y 0 0
     0 0 z 0
     0 0 0 1
public static float[]

Returns:

given matrix for chaining
makeTranslation
(final float[]
4x4 matrix in column-major order (also result)
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
,
final boolean
if true, given matrix will be initialized w/ identity matrix, otherwise only the diagonal and last-row is set. The latter can be utilized to share a once identity set matrix for scaling and translation, while leaving the other fields untouched for performance reasons.
initM
,
final float tx, final float ty, final float tz)

Make a translation matrix in column-major order from the given axis deltas

     Translation matrix (Column Order):
     1 0 0 0
     0 1 0 0
     0 0 1 0
     x y z 1
public static float[]

Returns:

given matrix for chaining
makeTranslation
(final float[]
4x4 matrix in column-major order (also result)
m
,
final boolean
if true, given matrix will be initialized w/ identity matrix, otherwise only the diagonal and last-row is set. The latter can be utilized to share a once identity set matrix for scaling and translation, while leaving the other fields untouched for performance reasons.
initM
,
final float tx, final float ty, final float tz)

Make a translation matrix in column-major order from the given axis deltas

     Translation matrix (Column Order):
     1 0 0 0
     0 1 0 0
     0 0 1 0
     x y z 1
public static boolean

Returns:

true if successful, otherwise false (z is 1)
mapObjToWinCoords
(final float objx, final float objy, final float objz, final float[]
4x4 modelview matrix
modelMatrix
,
final int modelMatrix_offset, final float[]
4x4 projection matrix
projMatrix
,
final int projMatrix_offset, final int[]
4 component viewport vector
viewport
,
final int viewport_offset, final float[]
3 component window coordinate, the result
win_pos
,
final int win_pos_offset, final float[]
4 component vector for temp storage
vec4Tmp1
,
final float[]
4 component vector for temp storage
vec4Tmp2
)

Map object coordinates to window coordinates.

public static boolean

Returns:

true if successful, otherwise false (z is 1)
mapObjToWinCoords
(final float objx, final float objy, final float objz, final float[]
[projection] x [modelview] matrix, i.e. P x Mv
mat4PMv
,
final int[]
4 component viewport vector
viewport
,
final int viewport_offset, final float[]
3 component window coordinate, the result
win_pos
,
final int win_pos_offset, final float[]
4 component vector for temp storage
vec4Tmp1
,
final float[]
4 component vector for temp storage
vec4Tmp2
)

Map object coordinates to window coordinates.

public static boolean

Returns:

true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
mapWinToObjCoords
(final float winx, final float winy, final float winz, final float[]
4x4 modelview matrix
modelMatrix
,
final int modelMatrix_offset, final float[]
4x4 projection matrix
projMatrix
,
final int projMatrix_offset, final int[]
4 component viewport vector
viewport
,
final int viewport_offset, final float[]
3 component object coordinate, the result
obj_pos
,
final int obj_pos_offset, final float[]
16 component matrix for temp storage
mat4Tmp1
,
final float[]
16 component matrix for temp storage
mat4Tmp2
)

Map window coordinates to object coordinates.

public static boolean

Returns:

true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
mapWinToObjCoords
(final float winx, final float winy, final float winz, final float[]
inverse [projection] x [modelview] matrix, i.e. Inv(P x Mv)
mat4PMvI
,
final int[]
4 component viewport vector
viewport
,
final int viewport_offset, final float[]
3 component object coordinate, the result
obj_pos
,
final int obj_pos_offset, final float[]
4 component vector for temp storage
vec4Tmp1
,
final float[]
4 component vector for temp storage
vec4Tmp2
)

Map window coordinates to object coordinates.

public static boolean

Returns:

true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
mapWinToObjCoords
(final float winx, final float winy, final float winz1, final float winz2, final float[]
inverse [projection] x [modelview] matrix, i.e. Inv(P x Mv)
mat4PMvI
,
final int[]
4 component viewport vector
viewport
,
final int viewport_offset, final float[]
3 component object coordinate, the result for winz1
obj1_pos
,
final int obj1_pos_offset, final float[]
3 component object coordinate, the result for winz2
obj2_pos
,
final int obj2_pos_offset, final float[]
4 component vector for temp storage
vec4Tmp1
,
final float[]
4 component vector for temp storage
vec4Tmp2
)

Map two window coordinates to two object coordinates, distinguished by their z component.

public static boolean

Returns:

true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
mapWinToObjCoords
(final float winx, final float winy, final float winz, final float clipw, final float[]
4x4 modelview matrix
modelMatrix
,
final int modelMatrix_offset, final float[]
4x4 projection matrix
projMatrix
,
final int projMatrix_offset, final int[]
4 component viewport vector
viewport
,
final int viewport_offset, final float near, final float far, final float[]
4 component object coordinate, the result
obj_pos
,
final int obj_pos_offset, final float[]
16 component matrix for temp storage
mat4Tmp1
,
final float[]
16 component matrix for temp storage
mat4Tmp2
)

Map window coordinates to object coordinates.

public static boolean

Returns:

true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
mapWinToRay
(final float winx, final float winy, final float winz0, final float winz1, final float[]
4x4 modelview matrix
modelMatrix
,
final int modelMatrix_offset, final float[]
4x4 projection matrix
projMatrix
,
final int projMatrix_offset, final int[]
4 component viewport vector
viewport
,
final int viewport_offset, final Ray
storage for the resulting Ray
ray
,
final float[]
16 component matrix for temp storage
mat4Tmp1
,
final float[]
16 component matrix for temp storage
mat4Tmp2
,
final float[]
4 component vector for temp storage
vec4Tmp2
)

Map two window coordinates w/ shared X/Y and distinctive Z to a Ray.

public static float

Returns:

the matrix determinant
matrixDeterminant
(final float[]
4x4 matrix in column-major order, the source
m
,
final int
offset in given array m, i.e. start of the 4x4 matrix
m_offset
)

Returns the determinant of the given matrix

public static float

Returns:

the matrix determinant
matrixDeterminant
(final float[]
4x4 matrix in column-major order, the source
m
)

Returns the determinant of the given matrix

public static StringBuilder

Returns:

matrix row string representation
matrixRowToString
(StringBuilder
optional passed StringBuilder instance to be used
sb
,
final String
the format string of one floating point, i.e. "%10.5f", see java.util.Formatter
f
,
final FloatBuffer
mxn matrix (rows x columns)
a
,
final int
offset to a's current position
aOffset
,
final int rows, final int columns, final boolean
if true floats are layed out in row-major-order, otherwise column-major-order (OpenGL)
rowMajorOrder
,
final int
row number to print
row
)

Deprecated use on of the float[] variants
public static StringBuilder

Returns:

matrix row string representation
matrixRowToString
(StringBuilder
optional passed StringBuilder instance to be used
sb
,
final String
the format string of one floating point, i.e. "%10.5f", see java.util.Formatter
f
,
final float[]
mxn matrix (rows x columns)
a
,
final int
offset to a's current position
aOffset
,
final int rows, final int columns, final boolean
if true floats are layed out in row-major-order, otherwise column-major-order (OpenGL)
rowMajorOrder
,
final int
row number to print
row
)

public static StringBuilder

Returns:

matrix string representation
matrixToString
(StringBuilder
optional passed StringBuilder instance to be used
sb
,
final String
optional prefix for each row
rowPrefix
,
final String
the format string of one floating point, i.e. "%10.5f", see java.util.Formatter
f
,
final FloatBuffer
mxn matrix (rows x columns)
a
,
final int
offset to a's current position
aOffset
,
final int rows, final int columns, final boolean
if true floats are layed out in row-major-order, otherwise column-major-order (OpenGL)
rowMajorOrder
)

Deprecated use on of the float[] variants
public static StringBuilder

Returns:

matrix string representation
matrixToString
(StringBuilder
optional passed StringBuilder instance to be used
sb
,
final String
optional prefix for each row
rowPrefix
,
final String
the format string of one floating point, i.e. "%10.5f", see java.util.Formatter
f
,
final float[]
mxn matrix (rows x columns)
a
,
final int
offset to a's current position
aOffset
,
final int rows, final int columns, final boolean
if true floats are layed out in row-major-order, otherwise column-major-order (OpenGL)
rowMajorOrder
)

public static StringBuilder

Returns:

side by side representation
matrixToString
(StringBuilder
optional passed StringBuilder instance to be used
sb
,
final String
optional prefix for each row
rowPrefix
,
final String
the format string of one floating point, i.e. "%10.5f", see java.util.Formatter
f
,
final FloatBuffer
4x4 matrix in column major order (OpenGL)
a
,
final int
offset to a's current position
aOffset
,
final FloatBuffer
4x4 matrix in column major order (OpenGL)
b
,
final int
offset to a's current position
bOffset
,
final int rows, final int columns, final boolean
if true floats are layed out in row-major-order, otherwise column-major-order (OpenGL)
rowMajorOrder
)

Deprecated use on of the float[] variants
public static StringBuilder

Returns:

side by side representation
matrixToString
(StringBuilder
optional passed StringBuilder instance to be used
sb
,
final String
optional prefix for each row
rowPrefix
,
final String
the format string of one floating point, i.e. "%10.5f", see java.util.Formatter
f
,
final float[]
4x4 matrix in column major order (OpenGL)
a
,
final int
offset to a's current position
aOffset
,
final float[]
4x4 matrix in column major order (OpenGL)
b
,
final int
offset to a's current position
bOffset
,
final int rows, final int columns, final boolean
if true floats are layed out in row-major-order, otherwise column-major-order (OpenGL)
rowMajorOrder
)

public static float[]

Returns:

given result matrix d for chaining
multMatrix
(final float[]
4x4 matrix in column-major order
a
,
final int a_off, final float[]
4x4 matrix in column-major order
b
,
final int b_off, final float[]
result a*b in column-major order
d
,
final int d_off)

Multiply matrix: [d] = [a] x [b]

public static float[]

Returns:

given result matrix d for chaining
multMatrix
(final float[]
4x4 matrix in column-major order
a
,
final float[]
4x4 matrix in column-major order
b
,
final float[]
result a*b in column-major order
d
)

Multiply matrix: [d] = [a] x [b]

public static float[]

Returns:

given result matrix a for chaining
multMatrix
(final float[]
4x4 matrix in column-major order (also result)
a
,
final int a_off, final float[]
4x4 matrix in column-major order
b
,
final int b_off)

Multiply matrix: [a] = [a] x [b]

public static float[]

Returns:

given result matrix a for chaining
multMatrix
(final float[]
4x4 matrix in column-major order (also result)
a
,
final float[]
4x4 matrix in column-major order
b
)

Multiply matrix: [a] = [a] x [b]

public static void
multMatrix(final FloatBuffer
4x4 matrix in column-major order
a
,
final FloatBuffer
4x4 matrix in column-major order
b
,
final float[]
result a*b in column-major order
d
)

Deprecated use on of the float[] variants
Multiply matrix: [d] = [a] x [b]
public static void
multMatrix(final FloatBuffer
4x4 matrix in column-major order (also result)
a
,
final FloatBuffer
4x4 matrix in column-major order
b
)

Deprecated use on of the float[] variants
Multiply matrix: [a] = [a] x [b]
public static float[]

Returns:

given result vector v_out for chaining
multMatrixVec
(final float[]
4x4 matrix in column-major order
m_in
,
final int m_in_off, final float[]
4-component column-vector
v_in
,
final int v_in_off, final float[]
m_in * v_in
v_out
,
final int v_out_off)

public static float[]

Returns:

given result vector v_out for chaining
multMatrixVec
(final float[]
4x4 matrix in column-major order
m_in
,
final float[]
4-component column-vector
v_in
,
final float[]
m_in * v_in
v_out
)

public static void
multMatrixVec(final FloatBuffer
4x4 matrix in column-major order
m_in
,
final float[]
4-component column-vector
v_in
,
final float[]
m_in * v_in
v_out
)

Deprecated use on of the float[] variants
public static float
pow(final float a, final float b)

public static float
sin(final float a)

public static float
sqrt(final float a)

public static float
tan(final float a)

public static float[]

Returns:

given result matrix mres for chaining
transposeMatrix
(final float[]
4x4 matrix in column-major order, the source
msrc
,
final int
offset in given array msrc, i.e. start of the 4x4 matrix
msrc_offset
,
final float[]
4x4 matrix in column-major order, the result
mres
,
final int
offset in given array mres, i.e. start of the 4x4 matrix
mres_offset
)

Transpose the given matrix.

public static float[]

Returns:

given result matrix mres for chaining
transposeMatrix
(final float[]
4x4 matrix in column-major order, the source
msrc
,
final float[]
4x4 matrix in column-major order, the result
mres
)

Transpose the given matrix.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait