PDA

View Full Version : Projection Mathmatics



david_williams
12-16-2002, 10:55 AM
Hi,
I am having difficulty understanding exactly how perspective projection works in OpenGL. I have created a frustrum with the following parameters:

l = -5, r = 5, t = 4, b = -4, n = 5, f = 15

Using the OpenGL blue book, I determined this should give the Matrix:

1 0 0 0
0 1.25 0 0
0 0 -2 -15
0 0 -1 0

The vertex I am trying to project is (0.0,0.0,-10.0), and when I multiply ths vertex by the projection matrix the result is (0.0,0.0,5.0)

As I understood it, the result of multipliying a vertex inside the frustum by the projection matrix would be a vertex within the unit cube, which the above result is not.

However, what I have found is that if after the multiplication I devide each element of the resulting vertex but it's w co-ordinate (which comes out as 10 in the above example), then the result is in the unit cube.

Why do I need to do this final division, and why can it not be built into the matrix multiplicatrion? Or am I missing something?

Thanks in advance,

David

zeckensack
12-16-2002, 11:20 AM
Originally posted by david_williams:
Why do I need to do this final division, and why can it not be built into the matrix multiplicatrion? Or am I missing something?Because the division is what turns a frustum into a cube. Or can you imagine another way? http://www.opengl.org/discussion_boards/ubb/wink.gif

You can't build that division into the matrix because ... well ... you can't. w gets determined by the vector*matrix mult, so it can't be factored in beforhand. w is variant per vertex, if it were not, you indeed could plop it into the matrix. But that's not generally useful (then you could just as well use a 2d projection and don't bother).

OpenGL automatically divides all vertices by w. You don't have to do that yourself, you can just submit 4d vertices (with proper w of course).