I spent most of yesterday debugging because I couldn’t implement perspective projection. Anyway, I thought my issue was the fact that my matrix multiplication was incorrect, which I fixed (I then spent an hour this morning fixing orthographic projection). Now I’m having trouble getting perspective projection to work, which I’ve tried to debug but I’m not sure how to fix it.
Orthographic projection:
projection.overwrite(new float[] { 2f / width, 0f, 0f, 0f, 0f,
2f / height, 0f, 0f, 0f, 0f, -2f, 0f,
-((x * 2f + width) / width), -((y * 2f + height) / height),
-1f, 1f });
t = top, b = bottom, l = left, r = right
Debugging results (it works):
Perspective projection:
projection.overwrite(new float[] { (2f * zNear) / width, 0f, 0f, 0f,
0f, (2f * zNear) / height, 0f, 0f, (2f * x + width) / width,
(2f * y + height) / height, -(-zFar + zNear) / (zFar - zNear),
-1f, 0f, 0f, -(2f * zFar * zNear) / (zFar - zNear), 0f });
t = top, b = bottom, l = left, r = right, n = zNear, f = zFar
Debugging results - n = 1, f = 100 (nothing is displayed):
What could the problem be? I’m not really sure what I’m doing wrong. I’ve tried translating the Z coordinate and extending the far pane, but I see nothing. I’m clearing the depth buffer and I tried enabling depth testing. None of those things worked.
EDIT: I think it must be something to do with the Z coordinate, since when I translate it, the W coordinate changes but nothing is displayed.