Android1.6でgluProject(), gluUnProject()を使う
gluProject()はワールド座標をスクリーン座標に変換,gluUnProject()はスクリーン座標をワールド座標上の直線に変換するGLU関数.この関数にはモデルビュー行列を引数として与える必要がある
調べたら,次のような関数呼び出しで取得できるらしいということがわかった
gl.glGetIntegerv(GL11.GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES, resultAsInt, 0);
でもこれ,エミュレータ上で動きはするんだけどHTC MagicとXperiaだと動かなかった.結果を格納するresultAsIntが初期状態のままだった
要するに動かないんだと.Androidが公式にサポートするのはOpenGL ES1.0だから,1.1の定数はサポート外のような感じらしい
結論:gluFrustumf, gluLookAtに相当する行列を自前で用意してgluProjectにぶちこむ
行列をつくるだけ
GC対策にオブジェクト使い回してるから汚くなってる
private void updateModelViewMatrix(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ) { F.set(centerX - eyeX, centerY -eyeY, centerZ - eyeZ); Vector3D.normalize(F); UP.set(upX, upY, upZ); Vector3D.normalize(UP); UP.set(F.cross(UP)); // as s Vector3D u = UP.cross(F); modelViewMatrix[0] = UP.x; modelViewMatrix[1] = u.x; modelViewMatrix[2] = -F.x; modelViewMatrix[3] = 0f; modelViewMatrix[4] = UP.y; modelViewMatrix[5] = u.y; modelViewMatrix[6] = -F.y; modelViewMatrix[7] = 0f; modelViewMatrix[8] = UP.z; modelViewMatrix[9] = u.z; modelViewMatrix[10] = -F.z; modelViewMatrix[11] = 0f; modelViewMatrix[12] = 0f; modelViewMatrix[13] = 0f; modelViewMatrix[14] = 0f; modelViewMatrix[15] = 1f; translateMatrix[12] = -eyeX; translateMatrix[13] = -eyeY; translateMatrix[14] = -eyeZ; Matrix4x4.mult(modelViewMatrix, modelViewMatrix, translateMatrix); } private void updateProjectionMatrix(float left, float right, float bottom, float top, float zNear, float zFar) { float topMinusBottom = top - bottom; float rightMinuxLeft = right - left; projectionMatrix[0] = (2 * zNear) / rightMinuxLeft; projectionMatrix[5] = (2 * zNear) / topMinusBottom; projectionMatrix[8] = (right + left) / rightMinuxLeft; projectionMatrix[9] = (top + bottom) / topMinusBottom; projectionMatrix[10] = - (zFar + zNear)/(zFar - zNear); projectionMatrix[14] = - (2 * zFar * zNear) / (zFar - zNear); }