PDA

View Full Version : space after perspective projection

A027298
08-20-2003, 05:24 AM
After perfoming the projection matrix, those vertices which where before in the eye's frustum are now in the unit cube. The vertices near the back plane are very near to the unit cube back side, the ones which are close to the near plane are very near to the unit cubes front plane. Is that right? If I program a small example like:

Matrix4x4 M;
M.identity();
M.perspective(60.0f, 1.0f, 1.0f, 20.0f);
M.lookat(10.0f, 10.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

Vector v1[100][100];
Vector v2[100][100];

for(int i = 0; i < 100; i++)
for(int j = 0; j < 100; j++) {
v1[i][j] = GTvector((gtFloat)i - 50.0f, 0.0f, (gtFloat)j - 50.0f);
v2[i][j] *= M;
}

...the z-values after projection in v2 are all very close together. No one is negative, they are all very close to the front plane of the unit cube. Where is the mistake? The corners of the unit cube where previously the corners of the frustum, they are on its right place, but everything inside is badly squeezed to the front plan of the unit cube. Can someone clarify that issue for me?

Thanks

[This message has been edited by A027298 (edited 08-20-2003).]

Bob
08-20-2003, 06:09 AM
Perhaps you forgot the perspective division, that is, when you divide the X, Y and Z, component by the W component?

A027298
08-20-2003, 04:35 PM
Originally posted by Bob:
Perhaps you forgot the perspective division, that is, when you divide the X, Y and Z, component by the W component?
No, the perspective division is performed. But now I know the reason: If the near plane of the eye's frustum is not cut by anything from a scene, for example the eye only looks down to a plane, the front plane of the unit cube can't be intersected as well.

zeckensack
08-21-2003, 02:17 AM
I'm having a hard time understanding what your issue is http://www.opengl.org/discussion_boards/ubb/confused.gif
What's going wrong?

Also, in your above code snippet, you never fill the v2 array. You essentially multiply junk memory with a matrix. You do seen to fetch vectors and write them to the v1 array, but the v2 array could be just anything.
Or did you simply not post the init code?

A027298
08-21-2003, 05:10 AM
Originally posted by zeckensack:
I'm having a hard time understanding what your issue is http://www.opengl.org/discussion_boards/ubb/confused.gif
What's going wrong?

Also, in your above code snippet, you never fill the v2 array. You essentially multiply junk memory with a matrix. You do seen to fetch vectors and write them to the v1 array, but the v2 array could be just anything.
Or did you simply not post the init code?
Actually its been solved. But it was not because the snippet above was wrong.

Assume the eye frustum is located on a plane, so that the near plane of that frustum gets intersected by the plane and the far plane gets intersected by that plane.

After applying the projection matrix, this plane goes from the front plane of the resulting unitcube to the back plane. That was the problem. In my case I had a different situation: That plane didn't cut the front plane of the unit cube. If I had more thought about that, then I would have realized that the front plane of the eye's frustum in my scene's worldspace wasn't cut by the scene's plane. So everything was and is ok. :-)