Loading opengl/java/android/opengl/GLU.java +88 −83 Original line number Diff line number Diff line Loading @@ -101,28 +101,30 @@ public class GLU { 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); 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; gl.glMultMatrixf(scratch, 0); } gl.glTranslatef(-eyeX, -eyeY, -eyeZ); } Loading Loading @@ -193,21 +195,23 @@ public class GLU { 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) { 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]; 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; } Loading @@ -215,12 +219,14 @@ public class GLU { float rw = 1.0f / w; win[winOffset] = view[viewOffset] + view[viewOffset + 2] * (v2[0] * rw + 1.0f) view[viewOffset] + view[viewOffset + 2] * (scratch[V2_OFFSET + 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; * (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; } Loading Loading @@ -255,34 +261,33 @@ public class GLU { 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) { 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)) { 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; } float[] v = new float[4]; v[0] = scratch[V_OFFSET + 0] = 2.0f * (winX - view[viewOffset + 0]) / view[viewOffset + 2] - 1.0f; v[1] = scratch[V_OFFSET + 1] = 2.0f * (winY - view[viewOffset + 1]) / view[viewOffset + 3] - 1.0f; v[2] = 2.0f * winZ - 1.0f; v[3] = 1.0f; scratch[V_OFFSET + 2] = 2.0f * winZ - 1.0f; scratch[V_OFFSET + 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]; Matrix.multiplyMV(obj, objOffset, scratch, INVPM_OFFSET, scratch, V_OFFSET); } return GL10.GL_TRUE; } private static final float[] sScratch = new float[32]; } Loading
opengl/java/android/opengl/GLU.java +88 −83 Original line number Diff line number Diff line Loading @@ -101,28 +101,30 @@ public class GLU { 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); 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; gl.glMultMatrixf(scratch, 0); } gl.glTranslatef(-eyeX, -eyeY, -eyeZ); } Loading Loading @@ -193,21 +195,23 @@ public class GLU { 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) { 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]; 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; } Loading @@ -215,12 +219,14 @@ public class GLU { float rw = 1.0f / w; win[winOffset] = view[viewOffset] + view[viewOffset + 2] * (v2[0] * rw + 1.0f) view[viewOffset] + view[viewOffset + 2] * (scratch[V2_OFFSET + 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; * (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; } Loading Loading @@ -255,34 +261,33 @@ public class GLU { 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) { 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)) { 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; } float[] v = new float[4]; v[0] = scratch[V_OFFSET + 0] = 2.0f * (winX - view[viewOffset + 0]) / view[viewOffset + 2] - 1.0f; v[1] = scratch[V_OFFSET + 1] = 2.0f * (winY - view[viewOffset + 1]) / view[viewOffset + 3] - 1.0f; v[2] = 2.0f * winZ - 1.0f; v[3] = 1.0f; scratch[V_OFFSET + 2] = 2.0f * winZ - 1.0f; scratch[V_OFFSET + 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]; Matrix.multiplyMV(obj, objOffset, scratch, INVPM_OFFSET, scratch, V_OFFSET); } return GL10.GL_TRUE; } private static final float[] sScratch = new float[32]; }