public final class PMVMatrix extends Object implements 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.
All matrices are backed up by a common primitive float-array for performance considerations
and are a sliced representation of it.
Note:
| Modifier and Type | Field and Description |
|---|---|
static int |
DIRTY_ALL
Bit value stating all is dirty
|
static int |
DIRTY_FRUSTUM
Bit value stating a dirty
frustum. |
static int |
DIRTY_INVERSE_MODELVIEW
Bit value stating a dirty
inverse modelview matrix (Mvi). |
static int |
DIRTY_INVERSE_TRANSPOSED_MODELVIEW
Bit value stating a dirty
inverse transposed modelview matrix (Mvit). |
static int |
MODIFIED_ALL
Bit value stating all is modified
|
static int |
MODIFIED_MODELVIEW
Bit value stating a modified
modelview matrix (Mv), since last update() call. |
static int |
MODIFIED_PROJECTION
Bit value stating a modified
projection matrix (P), since last update() call. |
static int |
MODIFIED_TEXTURE
Bit value stating a modified
texture matrix (T), since last update() call. |
GL_MATRIX_MODE, GL_MODELVIEW, GL_MODELVIEW_MATRIX, GL_PROJECTION, GL_PROJECTION_MATRIX, GL_TEXTURE_MATRIX| Constructor and Description |
|---|
PMVMatrix()
Creates an instance of PMVMatrix.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearAllUpdateRequests()
Clears all
update() requests of the Mvi and Mvit matrix and Frustum
after it has been enabled by one of the Mvi get, Mvit get
or Frustum get methods. |
int |
getDirtyBits()
Deprecated.
Function is exposed for debugging purposes only.
|
int |
getModifiedBits(boolean clear)
Returns the modified bits due to mutable operations..
|
int |
getRequestMask()
Deprecated.
Function is exposed for debugging purposes only.
|
void |
glFrustumf(float left,
float right,
float bottom,
float top,
float zNear,
float zFar)
Multiply the current matrix with the frustum matrix. |
void |
glGetFloatv(int matrixGetName,
float[] params,
int params_offset)
Copy the named matrix to the given storage at offset.
|
void |
glGetFloatv(int matrixGetName,
FloatBuffer params)
Copy the named matrix into the given storage.
|
Frustum |
glGetFrustum()
Returns the frustum, derived from projection * modelview
|
void |
glGetIntegerv(int pname,
int[] params,
int params_offset) |
void |
glGetIntegerv(int pname,
IntBuffer params)
glGetIntegerv
|
FloatBuffer |
glGetMatrixf() |
FloatBuffer |
glGetMatrixf(int matrixName) |
int |
glGetMatrixMode()
|
FloatBuffer |
glGetMviMatrixf()
Returns the inverse
modelview matrix (Mvi). |
FloatBuffer |
glGetMvitMatrixf()
Returns the inverse transposed
modelview matrix (Mvit). |
FloatBuffer |
glGetMvMatrixf()
Returns the
modelview matrix (Mv). |
FloatBuffer |
glGetPMatrixf()
Returns the
projection matrix (P). |
FloatBuffer |
glGetPMvMatrixf()
|
FloatBuffer |
glGetPMvMviMatrixf()
|
FloatBuffer |
glGetPMvMvitMatrixf()
|
FloatBuffer |
glGetTMatrixf()
Returns the
texture matrix (T). |
void |
glLoadIdentity()
Load the current matrix with the identity matrix
|
void |
glLoadMatrix(Quaternion quat)
Load the current matrix with the values of the given
Quaternion's rotation matrix representation. |
void |
glLoadMatrixf(float[] values,
int offset)
Load the current matrix w/ the provided one.
|
void |
glLoadMatrixf(FloatBuffer m)
Load the current matrix w/ the provided one.
|
void |
glMatrixMode(int matrixName)
Sets the current matrix mode.
|
void |
glMultMatrixf(float[] m,
int m_offset)
Multiply the current matrix: [c] = [c] x [m]
|
void |
glMultMatrixf(FloatBuffer m)
Multiply the current matrix: [c] = [c] x [m]
|
void |
glOrthof(float left,
float right,
float bottom,
float top,
float zNear,
float zFar)
Multiply the current matrix with the orthogonal matrix. |
void |
glPopMatrix()
Pop the current matrix from it's stack.
|
void |
glPushMatrix()
Push the current matrix to it's stack, while preserving it's values.
|
void |
glRotate(Quaternion quat)
Rotate the current matrix with the given
Quaternion's rotation matrix representation. |
void |
glRotatef(float ang_deg,
float x,
float y,
float z)
Rotate the current matrix.
|
void |
glScalef(float x,
float y,
float z)
Scale the current matrix.
|
void |
glTranslatef(float x,
float y,
float z)
Translate the current matrix.
|
void |
gluLookAt(float eyex,
float eyey,
float eyez,
float centerx,
float centery,
float centerz,
float upx,
float upy,
float upz)
|
void |
gluPerspective(float fovy_deg,
float aspect,
float zNear,
float zFar)
Multiply the current matrix with the perspective/frustum matrix. |
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.
|
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.
|
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.
|
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.
|
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 a
Ray. |
static boolean |
isMatrixGetName(int matrixGetName) |
static boolean |
isMatrixModeName(int matrixModeName) |
static int |
matrixGetName2MatrixModeName(int matrixGetName) |
static int |
matrixModeName2MatrixGetName(int matrixModeName) |
static StringBuilder |
matrixToString(StringBuilder sb,
String f,
FloatBuffer a) |
static StringBuilder |
matrixToString(StringBuilder sb,
String f,
FloatBuffer a,
FloatBuffer b) |
float[] |
multMvPMatrixf(float[] mat4MvP,
int mat4MvP_offset)
|
float[] |
multPMvMatrixf(float[] mat4PMv,
int mat4PMv_offset)
|
void |
reset()
Issues
glLoadIdentity() on all matrices,
i.e. |
String |
toString() |
StringBuilder |
toString(StringBuilder sb,
String f) |
boolean |
update()
Update the derived
inverse modelview (Mvi),
inverse transposed modelview (Mvit) matrices and Frustum
if they are dirty and they were requested
by one of the Mvi get, Mvit get
or Frustum get methods. |
public static final int MODIFIED_PROJECTION
projection matrix (P), since last update() call.public static final int MODIFIED_MODELVIEW
modelview matrix (Mv), since last update() call.public static final int MODIFIED_TEXTURE
texture matrix (T), since last update() call.public static final int MODIFIED_ALL
public static final int DIRTY_INVERSE_MODELVIEW
inverse modelview matrix (Mvi).public static final int DIRTY_INVERSE_TRANSPOSED_MODELVIEW
inverse transposed modelview matrix (Mvit).public static final int DIRTY_FRUSTUM
frustum.public static final int DIRTY_ALL
public PMVMatrix()
Implementation uses non-direct non-NIO Buffers with guaranteed backing array, which allows faster access in Java computation.
public static final boolean isMatrixModeName(int matrixModeName)
matrixModeName - One of GL_MODELVIEW, GL_PROJECTION or GL_TEXTUREpublic static final int matrixModeName2MatrixGetName(int matrixModeName)
matrixModeName - One of GL_MODELVIEW, GL_PROJECTION or GL_TEXTUREGL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX or GL_TEXTURE_MATRIXpublic static final boolean isMatrixGetName(int matrixGetName)
matrixGetName - One of GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX or GL_TEXTURE_MATRIXpublic static final int matrixGetName2MatrixModeName(int matrixGetName)
matrixGetName - One of GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX or GL_TEXTURE_MATRIXGL_MODELVIEW, GL_PROJECTION or GL_TEXTUREpublic static StringBuilder matrixToString(StringBuilder sb, String f, FloatBuffer a)
sb - optional passed StringBuilder instance to be usedf - the format string of one floating point, i.e. "%10.5f", see Formattera - 4x4 matrix in column major order (OpenGL)public static StringBuilder matrixToString(StringBuilder sb, String f, FloatBuffer a, FloatBuffer b)
sb - optional passed StringBuilder instance to be usedf - the format string of one floating point, i.e. "%10.5f", see Formattera - 4x4 matrix in column major order (OpenGL)b - 4x4 matrix in column major order (OpenGL)public final void reset()
glLoadIdentity() on all matrices,
i.e. GL_MODELVIEW, GL_PROJECTION or GL_TEXTURE
and resets all internal states.public final int glGetMatrixMode()
public final FloatBuffer glGetTMatrixf()
texture matrix (T).
public final FloatBuffer glGetPMatrixf()
projection matrix (P).
public final FloatBuffer glGetMvMatrixf()
modelview matrix (Mv).
public final FloatBuffer glGetMviMatrixf()
modelview 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.
update(),
clearAllUpdateRequests()public final FloatBuffer glGetMvitMatrixf()
modelview 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.
update(),
clearAllUpdateRequests()public final FloatBuffer glGetPMvMatrixf()
public final FloatBuffer glGetPMvMviMatrixf()
P, Mv and Mvi.
Method enables the Mvi matrix update, and performs it's update w/o clearing the modified bits.
See update() and matrix storage details.
update(),
clearAllUpdateRequests()public final FloatBuffer glGetPMvMvitMatrixf()
P, Mv, Mvi and Mvit.
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.
update(),
clearAllUpdateRequests()public final Frustum glGetFrustum()
public final FloatBuffer glGetMatrixf()
public final FloatBuffer glGetMatrixf(int matrixName)
matrixName - Either a matrix-get-name, i.e.
GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX or GL_TEXTURE_MATRIX,
or a matrix-mode-name, i.e.
GL_MODELVIEW, GL_PROJECTION or GL_TEXTUREpublic final float[] multPMvMatrixf(float[] mat4PMv,
int mat4PMv_offset)
mat4PMv - 4x4 matrix storage for resultmat4PMv_offset - public final float[] multMvPMatrixf(float[] mat4MvP,
int mat4MvP_offset)
mat4MvP - 4x4 matrix storage for resultmat4MvP_offset - public final void glMatrixMode(int matrixName)
GLMatrixFuncglMatrixMode in interface GLMatrixFuncmatrixName - GLMatrixFunc.GL_MODELVIEW, GLMatrixFunc.GL_PROJECTION or GL_TEXTURE.public final void glGetFloatv(int matrixGetName,
FloatBuffer params)
GLMatrixFuncglGetFloatv in interface GLMatrixFuncmatrixGetName - GLMatrixFunc.GL_MODELVIEW_MATRIX, GLMatrixFunc.GL_PROJECTION_MATRIX or GLMatrixFunc.GL_TEXTURE_MATRIXparams - the FloatBuffer's position remains unchanged,
which is the same behavior than the native JOGL GL implpublic final void glGetFloatv(int matrixGetName,
float[] params,
int params_offset)
GLMatrixFuncglGetFloatv in interface GLMatrixFuncmatrixGetName - GLMatrixFunc.GL_MODELVIEW_MATRIX, GLMatrixFunc.GL_PROJECTION_MATRIX or GLMatrixFunc.GL_TEXTURE_MATRIXparams - storageparams_offset - storage offsetpublic final void glGetIntegerv(int pname,
IntBuffer params)
GLMatrixFuncglGetIntegerv in interface GLMatrixFuncpname - GLMatrixFunc.GL_MATRIX_MODE to receive the current matrix modeparams - the FloatBuffer's position remains unchanged
which is the same behavior than the native JOGL GL implpublic final void glGetIntegerv(int pname,
int[] params,
int params_offset)
glGetIntegerv in interface GLMatrixFuncpublic final void glLoadMatrixf(float[] values,
int offset)
GLMatrixFuncglLoadMatrixf in interface GLMatrixFuncpublic final void glLoadMatrixf(FloatBuffer m)
GLMatrixFuncglLoadMatrixf in interface GLMatrixFuncpublic final void glLoadMatrix(Quaternion quat)
Quaternion's rotation matrix representation.public final void glPopMatrix()
GLMatrixFuncglPopMatrix in interface GLMatrixFuncGLMatrixFunc.glPushMatrix()public final void glPushMatrix()
GLMatrixFunc
There exist one stack per matrix mode, i.e. GLMatrixFunc.GL_MODELVIEW, GLMatrixFunc.GL_PROJECTION and GL_TEXTURE.
glPushMatrix in interface GLMatrixFuncpublic final void glLoadIdentity()
GLMatrixFuncglLoadIdentity in interface GLMatrixFuncpublic final void glMultMatrixf(FloatBuffer m)
GLMatrixFuncglMultMatrixf in interface GLMatrixFuncm - the FloatBuffer's position remains unchanged,
which is the same behavior than the native JOGL GL implpublic final void glMultMatrixf(float[] m,
int m_offset)
GLMatrixFuncglMultMatrixf in interface GLMatrixFuncpublic final void glTranslatef(float x,
float y,
float z)
GLMatrixFuncglTranslatef in interface GLMatrixFuncpublic final void glScalef(float x,
float y,
float z)
GLMatrixFuncglScalef in interface GLMatrixFuncpublic final void glRotatef(float ang_deg,
float x,
float y,
float z)
GLMatrixFuncglRotatef in interface GLMatrixFuncpublic final void glRotate(Quaternion quat)
Quaternion's rotation matrix representation.public final void glOrthof(float left,
float right,
float bottom,
float top,
float zNear,
float zFar)
GLMatrixFuncMultiply the current matrix with the orthogonal matrix.glOrthof in interface GLMatrixFuncpublic final void glFrustumf(float left,
float right,
float bottom,
float top,
float zNear,
float zFar)
GLMatrixFuncMultiply the current matrix with the frustum matrix.glFrustumf in interface GLMatrixFuncpublic final void gluPerspective(float fovy_deg,
float aspect,
float zNear,
float zFar)
Multiply the current matrix with the perspective/frustum matrix.fovy_deg - fov angle in degreesaspect - aspect ratio width / heightzNear - zFar - public final void gluLookAt(float eyex,
float eyey,
float eyez,
float centerx,
float centery,
float centerz,
float upx,
float upy,
float upz)
public final boolean gluProject(float objx,
float objy,
float objz,
int[] viewport,
int viewport_offset,
float[] win_pos,
int win_pos_offset)
Traditional gluProject implementation.
objx - objy - objz - viewport - 4 component viewport vectorviewport_offset - win_pos - 3 component window coordinate, the resultwin_pos_offset - public final boolean gluUnProject(float winx,
float winy,
float winz,
int[] viewport,
int viewport_offset,
float[] obj_pos,
int obj_pos_offset)
Traditional gluUnProject implementation.
winx - winy - winz - viewport - 4 component viewport vectorviewport_offset - obj_pos - 3 component object coordinate, the resultobj_pos_offset - 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)
Traditional gluUnProject4 implementation.
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 - public final void gluPickMatrix(float x,
float y,
float deltaX,
float deltaY,
int[] viewport,
int viewport_offset)
Traditional gluPickMatrix implementation.
See FloatUtil.makePick(..) for details.
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 - public final boolean gluUnProjectRay(float winx,
float winy,
float winz0,
float winz1,
int[] viewport,
int viewport_offset,
Ray ray)
Ray. The resulting Ray maybe used for picking
using a bounding box.
Notes for picking winz0 and winz1:
winx - winy - winz0 - winz1 - viewport - viewport_offset - ray - storage for the resulting Raypublic StringBuilder toString(StringBuilder sb, String f)
public final int getModifiedBits(boolean clear)
A modified bit is set, if the corresponding matrix had been modified by a mutable operation
since last update() or getModifiedBits(true) call.
clear - if true, clears the modified bits, otherwise leaves them untouched.MODIFIED_PROJECTION,
MODIFIED_MODELVIEW,
MODIFIED_TEXTUREpublic final int getDirtyBits()
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) or Frustum
has been requested by one of the Mvi get, Mvit get
or Frustum get methods.
public final int getRequestMask()
The request bit mask is set by one of the Mvi get, Mvit get
or Frustum get methods.
public final void clearAllUpdateRequests()
update() requests of the Mvi and Mvit matrix and Frustum
after it has been enabled by one of the Mvi get, Mvit get
or Frustum get methods.
Allows user to disable subsequent Mvi, Mvit and Frustum updates if no more required.
public final boolean update()
inverse modelview (Mvi),
inverse transposed modelview (Mvit) matrices and Frustum
if they are dirty and they were requested
by one of the Mvi get, Mvit get
or Frustum get methods.
The Mvi and Mvit matrices and Frustum are considered dirty, if their corresponding
Mv matrix has 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 get
or Frustum get etc 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.
Frustum were 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.getModifiedBits(boolean),
MODIFIED_PROJECTION,
MODIFIED_MODELVIEW,
MODIFIED_TEXTURE,
DIRTY_INVERSE_MODELVIEW,
DIRTY_INVERSE_TRANSPOSED_MODELVIEW,
DIRTY_FRUSTUM,
glGetMviMatrixf(),
glGetMvitMatrixf(),
glGetPMvMviMatrixf(),
glGetPMvMvitMatrixf(),
glGetFrustum(),
clearAllUpdateRequests()Copyright 2010 JogAmp Community.