GLUpublic class GLU extends Object A set of GL utilities inspired by the OpenGL Utility Toolkit. |
Fields Summary |
---|
private static final float[] | sScratch |
Methods Summary |
---|
public static java.lang.String | gluErrorString(int error)Return an error string from a GL or GLU error code.
switch (error) {
case GL10.GL_NO_ERROR:
return "no error";
case GL10.GL_INVALID_ENUM:
return "invalid enum";
case GL10.GL_INVALID_VALUE:
return "invalid value";
case GL10.GL_INVALID_OPERATION:
return "invalid operation";
case GL10.GL_STACK_OVERFLOW:
return "stack overflow";
case GL10.GL_STACK_UNDERFLOW:
return "stack underflow";
case GL10.GL_OUT_OF_MEMORY:
return "out of memory";
default:
return null;
}
| public static void | gluLookAt(javax.microedition.khronos.opengles.GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)Define a viewing transformation in terms of an eye point, a center of
view, and an up vector.
float[] scratch = sScratch;
synchronized(scratch) {
Matrix.setLookAtM(scratch, 0, eyeX, eyeY, eyeZ, centerX, centerY, centerZ,
upX, upY, upZ);
gl.glMultMatrixf(scratch, 0);
}
| public static void | gluOrtho2D(javax.microedition.khronos.opengles.GL10 gl, float left, float right, float bottom, float top)Set up a 2D orthographic projection matrix
gl.glOrthof(left, right, bottom, top, -1.0f, 1.0f);
| public static void | gluPerspective(javax.microedition.khronos.opengles.GL10 gl, float fovy, float aspect, float zNear, float zFar)Set up a perspective projection matrix
float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0));
float bottom = -top;
float left = bottom * aspect;
float right = top * aspect;
gl.glFrustumf(left, right, bottom, top, zNear, zFar);
| public static int | gluProject(float objX, float objY, float objZ, float[] model, int modelOffset, float[] project, int projectOffset, int[] view, int viewOffset, float[] win, int winOffset)Map object coordinates into window coordinates. gluProject transforms the
specified object coordinates into window coordinates using model, proj,
and view. The result is stored in win.
Note that you can use the OES_matrix_get extension, if present, to get
the current modelView and projection matrices.
float[] scratch = sScratch;
synchronized(scratch) {
final int M_OFFSET = 0; // 0..15
final int V_OFFSET = 16; // 16..19
final int V2_OFFSET = 20; // 20..23
Matrix.multiplyMM(scratch, M_OFFSET, project, projectOffset,
model, modelOffset);
scratch[V_OFFSET + 0] = objX;
scratch[V_OFFSET + 1] = objY;
scratch[V_OFFSET + 2] = objZ;
scratch[V_OFFSET + 3] = 1.0f;
Matrix.multiplyMV(scratch, V2_OFFSET,
scratch, M_OFFSET, scratch, V_OFFSET);
float w = scratch[V2_OFFSET + 3];
if (w == 0.0f) {
return GL10.GL_FALSE;
}
float rw = 1.0f / w;
win[winOffset] =
view[viewOffset] + view[viewOffset + 2]
* (scratch[V2_OFFSET + 0] * rw + 1.0f)
* 0.5f;
win[winOffset + 1] =
view[viewOffset + 1] + view[viewOffset + 3]
* (scratch[V2_OFFSET + 1] * rw + 1.0f) * 0.5f;
win[winOffset + 2] = (scratch[V2_OFFSET + 2] * rw + 1.0f) * 0.5f;
}
return GL10.GL_TRUE;
| public static int | gluUnProject(float winX, float winY, float winZ, float[] model, int modelOffset, float[] project, int projectOffset, int[] view, int viewOffset, float[] obj, int objOffset)Map window coordinates to object coordinates. gluUnProject maps the
specified window coordinates into object coordinates using model, proj,
and view. The result is stored in obj.
Note that you can use the OES_matrix_get extension, if present, to get
the current modelView and projection matrices.
float[] scratch = sScratch;
synchronized(scratch) {
final int PM_OFFSET = 0; // 0..15
final int INVPM_OFFSET = 16; // 16..31
final int V_OFFSET = 0; // 0..3 Reuses PM_OFFSET space
Matrix.multiplyMM(scratch, PM_OFFSET, project, projectOffset,
model, modelOffset);
if (!Matrix.invertM(scratch, INVPM_OFFSET, scratch, PM_OFFSET)) {
return GL10.GL_FALSE;
}
scratch[V_OFFSET + 0] =
2.0f * (winX - view[viewOffset + 0]) / view[viewOffset + 2]
- 1.0f;
scratch[V_OFFSET + 1] =
2.0f * (winY - view[viewOffset + 1]) / view[viewOffset + 3]
- 1.0f;
scratch[V_OFFSET + 2] = 2.0f * winZ - 1.0f;
scratch[V_OFFSET + 3] = 1.0f;
Matrix.multiplyMV(obj, objOffset, scratch, INVPM_OFFSET,
scratch, V_OFFSET);
}
return GL10.GL_TRUE;
|
|