我的正投影,等距摄像机视图存在问题,即使对象放置在视图中,我也会剪切远离场景中心0,0,0的对象。
在 onSurfaceChanged 方法中,我有:
GLES20.glViewport(0, 0, width, height);
final float ratio = (float) width / height;
final float left = -ratio;
final float right = ratio;
final float bottom = -1.0f;
final float top = 1.0f;
final float near = 1.0f;
final float far = 10.0f;
int useForOrtho = Math.min(width, height);
mProjectionMatrix = createOrthoProjectionMatrix(left, right, top, bottom, near, far);
Matrix.orthoM(mViewMatrix, 0,
-useForOrtho / 2,
useForOrtho / 2,
-useForOrtho / 2,
useForOrtho / 2, 0.01f, 100.0f);
Matrix.rotateM(mViewMatrix, 0, 45, 0.0f, 0.0f, 1.0f);
Matrix.rotateM(mViewMatrix, 0, 35, 1.0f, -1.0f, 0.0f);
以下是投影矩阵的功能:
public float[] createOrthoProjectionMatrix(float left, float right, float top, float bottom, float near, float far)
{
float[] m = new float[16];
m[0] = 2.0f / (right - left);
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = 2.0f / (top - bottom);
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = -2.0f / (far - near);
m[11] = 0.0f;
m[12] = -(right + left ) / (right - left );
m[13] = -(top + bottom) / (top - bottom);
m[14] = -(far + near ) / (far - near );
m[15] = 1.0f;
return m;
}
在哪里可以控制x,y,z远离0,0,0的距离,可以在不剪裁的情况下绘制对象?问题对象不会被放置在视线之内,但更像是当前的渲染体积 - 超出距离 - 有三角形被剪裁。