Unhide the Android OpenGL ES 2.0 API
Add a Matrix.setLookAtM method for computing a look-at viewing transform. Change GLU.lookAt to use Matrix.setLook.
This commit is contained in:
6645
api/current.xml
6645
api/current.xml
File diff suppressed because it is too large
Load Diff
@@ -2,16 +2,16 @@
|
||||
**
|
||||
** Copyright 2009, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package android.opengl;
|
||||
|
||||
/** OpenGL ES 2.0
|
||||
* @hide
|
||||
/** OpenGL ES 2.0. This class exposes the core OpenGL ES 2.0 APIs.
|
||||
* All the methods are static.
|
||||
*/
|
||||
public class GLES20 {
|
||||
public static final int GL_ACTIVE_TEXTURE = 0x84E0;
|
||||
@@ -49,7 +49,7 @@ public class GLES20 {
|
||||
public static final int GL_SRC_ALPHA_SATURATE = 0x0308;
|
||||
public static final int GL_FUNC_ADD = 0x8006;
|
||||
public static final int GL_BLEND_EQUATION = 0x8009;
|
||||
public static final int GL_BLEND_EQUATION_RGB = 0x8009; /* same as BLEND_EQUATION */
|
||||
public static final int GL_BLEND_EQUATION_RGB = 0x8009;
|
||||
public static final int GL_BLEND_EQUATION_ALPHA = 0x883D;
|
||||
public static final int GL_FUNC_SUBTRACT = 0x800A;
|
||||
public static final int GL_FUNC_REVERSE_SUBTRACT = 0x800B;
|
||||
@@ -328,7 +328,7 @@ public class GLES20 {
|
||||
|
||||
native private static void _nativeClassInit();
|
||||
static {
|
||||
_nativeClassInit();
|
||||
_nativeClassInit();
|
||||
}
|
||||
// C function void glActiveTexture ( GLenum texture )
|
||||
|
||||
@@ -980,7 +980,7 @@ public class GLES20 {
|
||||
);
|
||||
|
||||
// C function void glGetProgramInfoLog( GLuint program, GLsizei maxLength, GLsizei * length,
|
||||
// GLchar * infoLog);
|
||||
// GLchar * infoLog);
|
||||
|
||||
public static native String glGetProgramInfoLog(
|
||||
int program
|
||||
@@ -1020,7 +1020,7 @@ public class GLES20 {
|
||||
);
|
||||
|
||||
// C function void glGetShaderInfoLog( GLuint shader, GLsizei maxLength, GLsizei * length,
|
||||
// GLchar * infoLog);
|
||||
// GLchar * infoLog);
|
||||
|
||||
public static native String glGetShaderInfoLog(
|
||||
int shader
|
||||
|
||||
@@ -398,7 +398,6 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
|
||||
* {@link #setEGLConfigChooser(EGLConfigChooser)} has been called, then the supplied
|
||||
* EGLConfigChooser is responsible for choosing an OpenGL ES 2.0-compatible config.
|
||||
* @param version The EGLContext client version to choose. Use 2 for OpenGL ES 2.0
|
||||
* @hide
|
||||
*/
|
||||
public void setEGLContextClientVersion(int version) {
|
||||
checkRenderThreadState();
|
||||
|
||||
@@ -72,60 +72,12 @@ public class GLU {
|
||||
float centerX, float centerY, float centerZ, float upX, float upY,
|
||||
float upZ) {
|
||||
|
||||
// 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[] scratch = sScratch;
|
||||
synchronized(scratch) {
|
||||
scratch[0] = sx;
|
||||
scratch[1] = ux;
|
||||
scratch[2] = -fx;
|
||||
scratch[3] = 0.0f;
|
||||
|
||||
scratch[4] = sy;
|
||||
scratch[5] = uy;
|
||||
scratch[6] = -fy;
|
||||
scratch[7] = 0.0f;
|
||||
|
||||
scratch[8] = sz;
|
||||
scratch[9] = uz;
|
||||
scratch[10] = -fz;
|
||||
scratch[11] = 0.0f;
|
||||
|
||||
scratch[12] = 0.0f;
|
||||
scratch[13] = 0.0f;
|
||||
scratch[14] = 0.0f;
|
||||
scratch[15] = 1.0f;
|
||||
|
||||
Matrix.setLookAtM(scratch, 0, eyeX, eyeY, eyeZ, centerX, centerY, centerZ,
|
||||
upX, upY, upZ);
|
||||
gl.glMultMatrixf(scratch, 0);
|
||||
}
|
||||
gl.glTranslatef(-eyeX, -eyeY, -eyeZ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.opengl;
|
||||
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
/**
|
||||
* Matrix math utilities. These methods operate on OpenGL ES format
|
||||
* matrices and vectors stored in float arrays.
|
||||
@@ -582,4 +584,77 @@ public class Matrix {
|
||||
rm[rmOffset + 14] = 0.0f;
|
||||
rm[rmOffset + 15] = 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a viewing transformation in terms of an eye point, a center of
|
||||
* view, and an up vector.
|
||||
*
|
||||
* @param rm returns the result
|
||||
* @param rmOffset index into rm where the result matrix starts
|
||||
* @param eyeX eye point X
|
||||
* @param eyeY eye point Y
|
||||
* @param eyeZ eye point Z
|
||||
* @param centerX center of view X
|
||||
* @param centerY center of view Y
|
||||
* @param centerZ center of view Z
|
||||
* @param upX up vector X
|
||||
* @param upY up vector Y
|
||||
* @param upZ up vector Z
|
||||
*/
|
||||
public static void setLookAtM(float[] rm, int rmOffset,
|
||||
float eyeX, float eyeY, float eyeZ,
|
||||
float centerX, float centerY, float centerZ, float upX, float upY,
|
||||
float upZ) {
|
||||
|
||||
// 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;
|
||||
|
||||
rm[rmOffset + 0] = sx;
|
||||
rm[rmOffset + 1] = ux;
|
||||
rm[rmOffset + 2] = -fx;
|
||||
rm[rmOffset + 3] = 0.0f;
|
||||
|
||||
rm[rmOffset + 4] = sy;
|
||||
rm[rmOffset + 5] = uy;
|
||||
rm[rmOffset + 6] = -fy;
|
||||
rm[rmOffset + 7] = 0.0f;
|
||||
|
||||
rm[rmOffset + 8] = sz;
|
||||
rm[rmOffset + 9] = uz;
|
||||
rm[rmOffset + 10] = -fz;
|
||||
rm[rmOffset + 11] = 0.0f;
|
||||
|
||||
rm[rmOffset + 12] = 0.0f;
|
||||
rm[rmOffset + 13] = 0.0f;
|
||||
rm[rmOffset + 14] = 0.0f;
|
||||
rm[rmOffset + 15] = 1.0f;
|
||||
|
||||
translateM(rm, rmOffset, -eyeX, -eyeY, -eyeZ);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user