GLUpublic class GLU extends Object A set of GL utilities inspired by the OpenGL Utility Toolkit. |
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.
// See the OpenGL GLUT documentation for gluLookAt for a description
// of the algorithm. We implement it in a straightforward way:
float fx = centerX - eyeX;
float fy = centerY - eyeY;
float fz = centerZ - eyeZ;
// Normalize f
float rlf = 1.0f / Matrix.length(fx, fy, fz);
fx *= rlf;
fy *= rlf;
fz *= rlf;
// compute s = f x up (x means "cross product")
float sx = fy * upZ - fz * upY;
float sy = fz * upX - fx * upZ;
float sz = fx * upY - fy * upX;
// and normalize s
float rls = 1.0f / Matrix.length(sx, sy, sz);
sx *= rls;
sy *= rls;
sz *= rls;
// compute u = s x f
float ux = sy * fz - sz * fy;
float uy = sz * fx - sx * fz;
float uz = sx * fy - sy * fx;
float[] m = new float[16];
m[0] = sx;
m[1] = ux;
m[2] = -fx;
m[3] = 0.0f;
m[4] = sy;
m[5] = uy;
m[6] = -fy;
m[7] = 0.0f;
m[8] = sz;
m[9] = uz;
m[10] = -fz;
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
gl.glMultMatrixf(m, 0);
gl.glTranslatef(-eyeX, -eyeY, -eyeZ);
| 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[] m = new float[16];
Matrix.multiplyMM(m, 0, project, projectOffset, model, modelOffset);
float[] v = new float[4];
v[0] = objX;
v[1] = objY;
v[2] = objZ;
v[3] = 1.0f;
float[] v2 = new float[4];
Matrix.multiplyMV(v2, 0, m, 0, v, 0);
float w = v2[3];
if (w == 0.0f) {
return GL10.GL_FALSE;
}
float rw = 1.0f / w;
win[winOffset] =
view[viewOffset] + view[viewOffset + 2] * (v2[0] * rw + 1.0f)
* 0.5f;
win[winOffset + 1] =
view[viewOffset + 1] + view[viewOffset + 3]
* (v2[1] * rw + 1.0f) * 0.5f;
win[winOffset + 2] = (v2[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[] pm = new float[16];
Matrix.multiplyMM(pm, 0, project, projectOffset, model, modelOffset);
float[] invPM = new float[16];
if (!Matrix.invertM(invPM, 0, pm, 0)) {
return GL10.GL_FALSE;
}
float[] v = new float[4];
v[0] =
2.0f * (winX - view[viewOffset + 0]) / view[viewOffset + 2]
- 1.0f;
v[1] =
2.0f * (winY - view[viewOffset + 1]) / view[viewOffset + 3]
- 1.0f;
v[2] = 2.0f * winZ - 1.0f;
v[3] = 1.0f;
float[] v2 = new float[4];
Matrix.multiplyMV(v2, 0, invPM, 0, v, 0);
obj[objOffset] = v2[0];
obj[objOffset + 1] = v2[1];
obj[objOffset + 2] = v2[2];
return GL10.GL_TRUE;
|
|