私の問題は、私の遠近法による投影が、本来の目的とは逆のことをしていることです。私のオブジェクトを遠くに「縮小」する代わりに、それはそれを拡大しています:
白い部分が最も近い三角形です。ご理解いただけると思います。
独自のパースペクティブプロジェクションを作成し、それを頂点シェーダーに送信します。私は次のopengl状態を使用しています:
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glDepthFunc(GL2ES2.GL_LEQUAL);
gl.glEnable(GL2ES2.GL_CULL_FACE);
gl.glCullFace(GL2ES2.GL_BACK);
gl.glFrontFace(GL2ES2.GL_CW);
私はperspectiveMatrix部分に次のコードを使用しています:
eye = {0,0,5};
viewMatrix = Calc.translate(identity_matrix, -eye[0], -eye[1], -eye[2]);
perspectiveMatrix = Calc.buildPerspProjMat(90, 1, 0.5f, 10);
model_view_projection = Calc.multiply(perspectiveMatrix, viewMatrix);
Calc.javaには次の機能があります。
public static float[] translate(float[] m,float x,float y,float z){
float[] t = { 1.0f, 0.0f, 0.0f, x,
0.0f, 1.0f, 0.0f, y,
0.0f, 0.0f, 1.0f, z,
0, 0, 0, 1.0f };
return multiply(t, m);
}
public static float[] buildPerspProjMat(float fov, float aspect, float znear, float zfar) {
float[] m = new float[16];
float ymax = (float) (znear * Math.tan(Math.toRadians(fov/2)));
float ymin = -ymax;
float xmax = ymax * aspect;
float xmin = ymin * aspect;
float width = xmax - xmin;
float height = ymax - ymin;
float depth = zfar - znear;
float q = -(zfar + znear) / depth;
float qn = -2 * (zfar * znear) / depth;
float w = 2 * znear / width;
w = w / aspect;
float h = 2 * znear / height;
m[0] = w;
m[1] = 0;
m[2] = 0;
m[3] = 0;
m[4] = 0;
m[5] = h;
m[6] = 0;
m[7] = 0;
m[8] = 0;
m[9] = 0;
m[10] = q;
m[11] = qn;
m[12] = 0;
m[13] = 0;
m[14] = -1;
m[15] = 0;
return m;
}