Class PMVMatrix
- All Implemented Interfaces:
GLMatrixFunc
GLMatrixFunc.
Further more, PMVMatrix provides the inverse modelview matrix (Mvi) and
inverse transposed modelview matrix (Mvit).
Frustum is also provided by glGetFrustum().
To keep these derived values synchronized after mutable Mv operations like glRotatef(..)
in glMatrixMode(GL_MODELVIEW),
users have to call update() before using Mvi and Mvit.
All matrices are provided in column-major order,
as specified in the OpenGL fixed function pipeline, i.e. compatibility profile.
See FloatUtil.
PMVMatrix can supplement GL2ES2 applications w/ the
lack of the described matrix functionality.
Matrix storage details
All matrices are backed up by a common primitive float-array for performance considerations
and are a sliced representation of it.
Note:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBit value stating all is dirtystatic final intBit value stating a dirtyfrustum.static final intBit value stating a dirtyinverse modelview matrix (Mvi).static final intBit value stating a dirtyinverse transposed modelview matrix (Mvit).static final intBit value stating all is modifiedstatic final intBit value stating a modifiedmodelview matrix (Mv), since lastupdate()call.static final intBit value stating a modifiedprojection matrix (P), since lastupdate()call.static final intBit value stating a modifiedtexture matrix (T), since lastupdate()call.Fields inherited from interface com.jogamp.opengl.fixedfunc.GLMatrixFunc
GL_MATRIX_MODE, GL_MODELVIEW, GL_MODELVIEW_MATRIX, GL_PROJECTION, GL_PROJECTION_MATRIX, GL_TEXTURE_MATRIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidClears allupdate()requests of the Mvi and Mvit matrix and Frustum after it has been enabled by one of theMvi get,Mvit getorFrustum getmethods.final intDeprecated.Function is exposed for debugging purposes only.final intgetModifiedBits(boolean clear) Returns the modified bits due to mutable operations..final intDeprecated.Function is exposed for debugging purposes only.final voidglFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) Multiplythe current matrix with the frustum matrix.final voidglGetFloatv(int matrixGetName, float[] params, int params_offset) Copy the named matrix to the given storage at offset.final voidglGetFloatv(int matrixGetName, FloatBuffer params) Copy the named matrix into the given storage.final FrustumReturns the frustum, derived from projection * modelviewfinal voidglGetIntegerv(int pname, int[] params, int params_offset) final voidglGetIntegerv(int pname, IntBuffer params) glGetIntegervfinal FloatBufferfinal FloatBufferglGetMatrixf(int matrixName) final intfinal FloatBufferReturns the inversemodelview matrix(Mvi).final FloatBufferReturns the inverse transposedmodelview matrix(Mvit).final FloatBufferReturns themodelview matrix(Mv).final FloatBufferReturns theprojection matrix(P).final FloatBufferfinal FloatBufferfinal FloatBufferfinal FloatBufferReturns thetexture matrix(T).final voidLoad the current matrix with the identity matrixfinal voidglLoadMatrix(Quaternion quat) Load the current matrix with the values of the givenQuaternion's rotationmatrix representation.final voidglLoadMatrixf(float[] values, int offset) Load the current matrix w/ the provided one.final voidLoad the current matrix w/ the provided one.final voidglMatrixMode(int matrixName) Sets the current matrix mode.final voidglMultMatrixf(float[] m, int m_offset) Multiply the current matrix: [c] = [c] x [m]final voidMultiply the current matrix: [c] = [c] x [m]final voidglOrthof(float left, float right, float bottom, float top, float zNear, float zFar) Multiplythe current matrix with the orthogonal matrix.final voidPop the current matrix from it's stack.final voidPush the current matrix to it's stack, while preserving it's values.final voidglRotate(Quaternion quat) Rotate the current matrix with the givenQuaternion's rotationmatrix representation.final voidglRotatef(float ang_deg, float x, float y, float z) Rotate the current matrix.final voidglScalef(float x, float y, float z) Scale the current matrix.final voidglTranslatef(float x, float y, float z) Translate the current matrix.final voidgluLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz) final voidgluPerspective(float fovy_deg, float aspect, float zNear, float zFar) Multiplythecurrent matrixwith the perspective/frustum matrix.final voidgluPickMatrix(float x, float y, float deltaX, float deltaY, int[] viewport, int viewport_offset) Make given matrix the pick matrix based on given parameters.final booleangluProject(float objx, float objy, float objz, int[] viewport, int viewport_offset, float[] win_pos, int win_pos_offset) Map object coordinates to window coordinates.final booleangluUnProject(float winx, float winy, float winz, int[] viewport, int viewport_offset, float[] obj_pos, int obj_pos_offset) Map window coordinates to object coordinates.booleangluUnProject4(float winx, float winy, float winz, float clipw, int[] viewport, int viewport_offset, float near, float far, float[] obj_pos, int obj_pos_offset) Map window coordinates to object coordinates.final booleangluUnProjectRay(float winx, float winy, float winz0, float winz1, int[] viewport, int viewport_offset, Ray ray) Map two window coordinates w/ shared X/Y and distinctive Z to aRay.static final booleanisMatrixGetName(int matrixGetName) static final booleanisMatrixModeName(int matrixModeName) static final intmatrixGetName2MatrixModeName(int matrixGetName) static final intmatrixModeName2MatrixGetName(int matrixModeName) static StringBuildermatrixToString(StringBuilder sb, String f, FloatBuffer a) static StringBuildermatrixToString(StringBuilder sb, String f, FloatBuffer a, FloatBuffer b) final float[]multMvPMatrixf(float[] mat4MvP, int mat4MvP_offset) final float[]multPMvMatrixf(float[] mat4PMv, int mat4PMv_offset) final voidreset()IssuesglLoadIdentity()on all matrices, i.e.toString()toString(StringBuilder sb, String f) final booleanupdate()Update the derivedinverse modelview (Mvi),inverse transposed modelview (Mvit)matrices andFrustumif they are dirty and they were requested by one of theMvi get,Mvit getorFrustum getmethods.
-
Field Details
-
MODIFIED_PROJECTION
public static final int MODIFIED_PROJECTIONBit value stating a modifiedprojection matrix (P), since lastupdate()call.- See Also:
-
MODIFIED_MODELVIEW
public static final int MODIFIED_MODELVIEWBit value stating a modifiedmodelview matrix (Mv), since lastupdate()call.- See Also:
-
MODIFIED_TEXTURE
public static final int MODIFIED_TEXTUREBit value stating a modifiedtexture matrix (T), since lastupdate()call.- See Also:
-
MODIFIED_ALL
public static final int MODIFIED_ALLBit value stating all is modified- See Also:
-
DIRTY_INVERSE_MODELVIEW
public static final int DIRTY_INVERSE_MODELVIEWBit value stating a dirtyinverse modelview matrix (Mvi).- See Also:
-
DIRTY_INVERSE_TRANSPOSED_MODELVIEW
public static final int DIRTY_INVERSE_TRANSPOSED_MODELVIEWBit value stating a dirtyinverse transposed modelview matrix (Mvit).- See Also:
-
DIRTY_FRUSTUM
public static final int DIRTY_FRUSTUMBit value stating a dirtyfrustum.- See Also:
-
DIRTY_ALL
public static final int DIRTY_ALLBit value stating all is dirty- See Also:
-
-
Constructor Details
-
PMVMatrix
public PMVMatrix()Creates an instance of PMVMatrix.Implementation uses non-direct non-NIO Buffers with guaranteed backing array, which allows faster access in Java computation.
-
-
Method Details
-
isMatrixModeName
public static final boolean isMatrixModeName(int matrixModeName) - Parameters:
matrixModeName- One ofGL_MODELVIEW,GL_PROJECTIONorGL_TEXTURE- Returns:
- true if the given matrix-mode name is valid, otherwise false.
-
matrixModeName2MatrixGetName
public static final int matrixModeName2MatrixGetName(int matrixModeName) - Parameters:
matrixModeName- One ofGL_MODELVIEW,GL_PROJECTIONorGL_TEXTURE- Returns:
- The corresponding matrix-get name, one of
GL_MODELVIEW_MATRIX,GL_PROJECTION_MATRIXorGL_TEXTURE_MATRIX
-
isMatrixGetName
public static final boolean isMatrixGetName(int matrixGetName) - Parameters:
matrixGetName- One ofGL_MODELVIEW_MATRIX,GL_PROJECTION_MATRIXorGL_TEXTURE_MATRIX- Returns:
- true if the given matrix-get name is valid, otherwise false.
-
matrixGetName2MatrixModeName
public static final int matrixGetName2MatrixModeName(int matrixGetName) - Parameters:
matrixGetName- One ofGL_MODELVIEW_MATRIX,GL_PROJECTION_MATRIXorGL_TEXTURE_MATRIX- Returns:
- The corresponding matrix-mode name, one of
GL_MODELVIEW,GL_PROJECTIONorGL_TEXTURE
-
matrixToString
- Parameters:
sb- optional passed StringBuilder instance to be usedf- the format string of one floating point, i.e. "%10.5f", seeFormattera- 4x4 matrix in column major order (OpenGL)- Returns:
- matrix string representation
-
matrixToString
public static StringBuilder matrixToString(StringBuilder sb, String f, FloatBuffer a, FloatBuffer b) - Parameters:
sb- optional passed StringBuilder instance to be usedf- the format string of one floating point, i.e. "%10.5f", seeFormattera- 4x4 matrix in column major order (OpenGL)b- 4x4 matrix in column major order (OpenGL)- Returns:
- side by side representation
-
reset
public final void reset()IssuesglLoadIdentity()on all matrices, i.e.GL_MODELVIEW,GL_PROJECTIONorGL_TEXTUREand resets all internal states. -
glGetMatrixMode
public final int glGetMatrixMode() -
glGetTMatrixf
Returns thetexture matrix(T). -
glGetPMatrixf
Returns theprojection matrix(P). -
glGetMvMatrixf
Returns themodelview matrix(Mv). -
glGetMviMatrixf
Returns the inversemodelview matrix(Mvi).Method enables the Mvi matrix update, and performs it's update w/o clearing the modified bits.
See
update()and matrix storage details.- See Also:
-
glGetMvitMatrixf
Returns the inverse transposedmodelview matrix(Mvit).Method enables the Mvit matrix update, and performs it's update w/o clearing the modified bits.
See
update()and matrix storage details.- See Also:
-
glGetPMvMatrixf
-
glGetPMvMviMatrixf
Returns 3 matrices within one FloatBuffer:P,MvandMvi.Method enables the Mvi matrix update, and performs it's update w/o clearing the modified bits.
See
update()and matrix storage details.- See Also:
-
glGetPMvMvitMatrixf
Returns 4 matrices within one FloatBuffer:P,Mv,MviandMvit.Method enables the Mvi and Mvit matrix update, and performs it's update w/o clearing the modified bits.
See
update()and matrix storage details.- See Also:
-
glGetFrustum
Returns the frustum, derived from projection * modelview -
glGetMatrixf
-
glGetMatrixf
- Parameters:
matrixName- Either a matrix-get-name, i.e.GL_MODELVIEW_MATRIX,GL_PROJECTION_MATRIXorGL_TEXTURE_MATRIX, or a matrix-mode-name, i.e.GL_MODELVIEW,GL_PROJECTIONorGL_TEXTURE- Returns:
- the named matrix, not a copy!
-
multPMvMatrixf
public final float[] multPMvMatrixf(float[] mat4PMv, int mat4PMv_offset) - Parameters:
mat4PMv- 4x4 matrix storage for resultmat4PMv_offset-- Returns:
- given matrix for chaining
-
multMvPMatrixf
public final float[] multMvPMatrixf(float[] mat4MvP, int mat4MvP_offset) - Parameters:
mat4MvP- 4x4 matrix storage for resultmat4MvP_offset-- Returns:
- given matrix for chaining
-
glMatrixMode
public final void glMatrixMode(int matrixName) Description copied from interface:GLMatrixFuncSets the current matrix mode.- Specified by:
glMatrixModein interfaceGLMatrixFunc- Parameters:
matrixName-GLMatrixFunc.GL_MODELVIEW,GLMatrixFunc.GL_PROJECTIONorGL_TEXTURE.
-
glGetFloatv
Description copied from interface:GLMatrixFuncCopy the named matrix into the given storage.- Specified by:
glGetFloatvin interfaceGLMatrixFunc- Parameters:
matrixGetName-GLMatrixFunc.GL_MODELVIEW_MATRIX,GLMatrixFunc.GL_PROJECTION_MATRIXorGLMatrixFunc.GL_TEXTURE_MATRIXparams- the FloatBuffer's position remains unchanged, which is the same behavior than the native JOGL GL impl
-
glGetFloatv
public final void glGetFloatv(int matrixGetName, float[] params, int params_offset) Description copied from interface:GLMatrixFuncCopy the named matrix to the given storage at offset.- Specified by:
glGetFloatvin interfaceGLMatrixFunc- Parameters:
matrixGetName-GLMatrixFunc.GL_MODELVIEW_MATRIX,GLMatrixFunc.GL_PROJECTION_MATRIXorGLMatrixFunc.GL_TEXTURE_MATRIXparams- storageparams_offset- storage offset
-
glGetIntegerv
Description copied from interface:GLMatrixFuncglGetIntegerv- Specified by:
glGetIntegervin interfaceGLMatrixFunc- Parameters:
pname-GLMatrixFunc.GL_MATRIX_MODEto receive the current matrix modeparams- the FloatBuffer's position remains unchanged which is the same behavior than the native JOGL GL impl
-
glGetIntegerv
public final void glGetIntegerv(int pname, int[] params, int params_offset) - Specified by:
glGetIntegervin interfaceGLMatrixFunc
-
glLoadMatrixf
public final void glLoadMatrixf(float[] values, int offset) Description copied from interface:GLMatrixFuncLoad the current matrix w/ the provided one.- Specified by:
glLoadMatrixfin interfaceGLMatrixFunc
-
glLoadMatrixf
Description copied from interface:GLMatrixFuncLoad the current matrix w/ the provided one.- Specified by:
glLoadMatrixfin interfaceGLMatrixFunc
-
glLoadMatrix
Load the current matrix with the values of the givenQuaternion's rotationmatrix representation. -
glPopMatrix
public final void glPopMatrix()Description copied from interface:GLMatrixFuncPop the current matrix from it's stack.- Specified by:
glPopMatrixin interfaceGLMatrixFunc- See Also:
-
glPushMatrix
public final void glPushMatrix()Description copied from interface:GLMatrixFuncPush the current matrix to it's stack, while preserving it's values.There exist one stack per matrix mode, i.e.
GLMatrixFunc.GL_MODELVIEW,GLMatrixFunc.GL_PROJECTIONandGL_TEXTURE.- Specified by:
glPushMatrixin interfaceGLMatrixFunc
-
glLoadIdentity
public final void glLoadIdentity()Description copied from interface:GLMatrixFuncLoad the current matrix with the identity matrix- Specified by:
glLoadIdentityin interfaceGLMatrixFunc
-
glMultMatrixf
Description copied from interface:GLMatrixFuncMultiply the current matrix: [c] = [c] x [m]- Specified by:
glMultMatrixfin interfaceGLMatrixFunc- Parameters:
m- the FloatBuffer's position remains unchanged, which is the same behavior than the native JOGL GL impl
-
glMultMatrixf
public final void glMultMatrixf(float[] m, int m_offset) Description copied from interface:GLMatrixFuncMultiply the current matrix: [c] = [c] x [m]- Specified by:
glMultMatrixfin interfaceGLMatrixFunc
-
glTranslatef
public final void glTranslatef(float x, float y, float z) Description copied from interface:GLMatrixFuncTranslate the current matrix.- Specified by:
glTranslatefin interfaceGLMatrixFunc
-
glScalef
public final void glScalef(float x, float y, float z) Description copied from interface:GLMatrixFuncScale the current matrix.- Specified by:
glScalefin interfaceGLMatrixFunc
-
glRotatef
public final void glRotatef(float ang_deg, float x, float y, float z) Description copied from interface:GLMatrixFuncRotate the current matrix.- Specified by:
glRotatefin interfaceGLMatrixFunc
-
glRotate
Rotate the current matrix with the givenQuaternion's rotationmatrix representation. -
glOrthof
public final void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) Description copied from interface:GLMatrixFuncMultiplythe current matrix with the orthogonal matrix.- Specified by:
glOrthofin interfaceGLMatrixFunc
-
glFrustumf
public final void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) throws GLException Multiplythe current matrix with the frustum matrix.- Specified by:
glFrustumfin interfaceGLMatrixFunc- Throws:
GLException- ifzNear <= 0orzFar <= zNearorleft == right, orbottom == top.- See Also:
-
gluPerspective
public final void gluPerspective(float fovy_deg, float aspect, float zNear, float zFar) throws GLException Multiplythecurrent matrixwith the perspective/frustum matrix.- Parameters:
fovy_deg- fov angle in degreesaspect- aspect ratio width / heightzNear-zFar-- Throws:
GLException- ifzNear <= 0orzFar <= zNear- See Also:
-
gluLookAt
public final void gluLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz) -
gluProject
public final boolean gluProject(float objx, float objy, float objz, int[] viewport, int viewport_offset, float[] win_pos, int win_pos_offset) Map object coordinates to window coordinates.Traditional
gluProjectimplementation.- Parameters:
objx-objy-objz-viewport- 4 component viewport vectorviewport_offset-win_pos- 3 component window coordinate, the resultwin_pos_offset-- Returns:
- true if successful, otherwise false (z is 1)
-
gluUnProject
public final boolean gluUnProject(float winx, float winy, float winz, int[] viewport, int viewport_offset, float[] obj_pos, int obj_pos_offset) Map window coordinates to object coordinates.Traditional
gluUnProjectimplementation.- Parameters:
winx-winy-winz-viewport- 4 component viewport vectorviewport_offset-obj_pos- 3 component object coordinate, the resultobj_pos_offset-- Returns:
- true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
-
gluUnProject4
public boolean gluUnProject4(float winx, float winy, float winz, float clipw, int[] viewport, int viewport_offset, float near, float far, float[] obj_pos, int obj_pos_offset) Map window coordinates to object coordinates.Traditional
gluUnProject4implementation.- Parameters:
winx-winy-winz-clipw-modelMatrix- 4x4 modelview matrixmodelMatrix_offset-projMatrix- 4x4 projection matrixprojMatrix_offset-viewport- 4 component viewport vectorviewport_offset-near-far-obj_pos- 4 component object coordinate, the resultobj_pos_offset-- Returns:
- true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
-
gluPickMatrix
public final void gluPickMatrix(float x, float y, float deltaX, float deltaY, int[] viewport, int viewport_offset) Make given matrix the pick matrix based on given parameters.Traditional
gluPickMatriximplementation.See
FloatUtil.makePick(..)for details.- Parameters:
x- the center x-component of a picking region in window coordinatesy- the center y-component of a picking region in window coordinatesdeltaX- the width of the picking region in window coordinates.deltaY- the height of the picking region in window coordinates.viewport- 4 component viewport vectorviewport_offset-
-
gluUnProjectRay
public final boolean gluUnProjectRay(float winx, float winy, float winz0, float winz1, int[] viewport, int viewport_offset, Ray ray) Map two window coordinates w/ shared X/Y and distinctive Z to aRay. The resultingRaymaybe used for picking using abounding box.Notes for picking winz0 and winz1:
- Parameters:
winx-winy-winz0-winz1-viewport-viewport_offset-ray- storage for the resultingRay- Returns:
- true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
-
toString
-
toString
-
getModifiedBits
public final int getModifiedBits(boolean clear) Returns the modified bits due to mutable operations..A modified bit is set, if the corresponding matrix had been modified by a mutable operation since last
update()orgetModifiedBits(true)call.- Parameters:
clear- if true, clears the modified bits, otherwise leaves them untouched.- See Also:
-
getDirtyBits
public final int getDirtyBits()Deprecated.Function is exposed for debugging purposes only.Returns the dirty bits due to mutable operations.A dirty bit is set , if the corresponding matrix had been modified by a mutable operation since last
update()call. The latter clears the dirty state only if the dirty matrix (Mvi or Mvit) orFrustumhas been requested by one of theMvi get,Mvit getorFrustum getmethods. -
getRequestMask
public final int getRequestMask()Deprecated.Function is exposed for debugging purposes only.Returns the request bit mask, which uses bit values equal to the dirty mask.The request bit mask is set by one of the
Mvi get,Mvit getorFrustum getmethods. -
clearAllUpdateRequests
public final void clearAllUpdateRequests()Clears allupdate()requests of the Mvi and Mvit matrix and Frustum after it has been enabled by one of theMvi get,Mvit getorFrustum getmethods.Allows user to disable subsequent Mvi, Mvit and
Frustumupdates if no more required. -
update
public final boolean update()Update the derivedinverse modelview (Mvi),inverse transposed modelview (Mvit)matrices andFrustumif they are dirty and they were requested by one of theMvi get,Mvit getorFrustum getmethods.The Mvi and Mvit matrices and
Frustumare considered dirty, if their correspondingMv matrixhas been modified since their last update.Method should be called manually in case mutable operations has been called and caller operates on already fetched references, i.e. not calling
Mvi get,Mvit getorFrustum getetc anymore.This method clears the modified bits like
getModifiedBits(true), which are set by any mutable operation. The modified bits have no impact on this method, but the return value.- Returns:
- true if any matrix has been modified since last update call or
if the derived matrices Mvi and Mvit or
Frustumwere updated, otherwise false. In other words, method returns true if any matrix used by the caller must be updated, e.g. uniforms in a shader program. - See Also:
-