anthony

08-24-2004, 11:51 AM

I have a question about homogeneous coordinates in OpenGL. I'm sorry if this shouldn't be posted under "advanced", but it's hard for me to tell.

Is it true that the projection matrix defined by a call to glFrustum will only work for vertices of the form [x y z 1]^T ?

The reason it seems to me this must be so is that it seems to me the projection matrices defined by glFrustum would not project points correctly without w = 1. Roughly speaking (ignoring normalised device coordinates and any handedness changes) let's take an example. Consider the centre of projection at (0, 0, -1) and the viewplane along the Z=0 plane, the x coordinate of a point [x y z w]^T should be projected (into 2D) as x / (w * ((z / w) + 1)) = x / (z + w), whereas the projection matrices defined by glFrustum will set the w coordinate of such a point to -z, hence after the perspective divide the 2d coordinate will be (again roughly speaking) x / -z. What happened to the original w ?!?

Where am I wrong here?

If I am correct, does this mean that before applying the projection matrix to vertices a vertex [x y z w]^T is projected to [x y z 1]^T ? Then the projection matrix is applied, and clipping occurs to the "image space" cube in projective space against 7 clipping planes. And finally the perspective division is done.

The final thing confusing me is that in the OpenGL spec. it says OpenGL may not handle clip-coordinates with w < 0 correctly..how can this be right? Any point behind the viewer in 3D will be transformed to a 4D point with w < 0 after the projection matrix is applied. Or do I misunderstand what they mean by a clip-coordinate?

I'd be really grateful if someone could clear this up for me. Thanks for reading!

Is it true that the projection matrix defined by a call to glFrustum will only work for vertices of the form [x y z 1]^T ?

The reason it seems to me this must be so is that it seems to me the projection matrices defined by glFrustum would not project points correctly without w = 1. Roughly speaking (ignoring normalised device coordinates and any handedness changes) let's take an example. Consider the centre of projection at (0, 0, -1) and the viewplane along the Z=0 plane, the x coordinate of a point [x y z w]^T should be projected (into 2D) as x / (w * ((z / w) + 1)) = x / (z + w), whereas the projection matrices defined by glFrustum will set the w coordinate of such a point to -z, hence after the perspective divide the 2d coordinate will be (again roughly speaking) x / -z. What happened to the original w ?!?

Where am I wrong here?

If I am correct, does this mean that before applying the projection matrix to vertices a vertex [x y z w]^T is projected to [x y z 1]^T ? Then the projection matrix is applied, and clipping occurs to the "image space" cube in projective space against 7 clipping planes. And finally the perspective division is done.

The final thing confusing me is that in the OpenGL spec. it says OpenGL may not handle clip-coordinates with w < 0 correctly..how can this be right? Any point behind the viewer in 3D will be transformed to a 4D point with w < 0 after the projection matrix is applied. Or do I misunderstand what they mean by a clip-coordinate?

I'd be really grateful if someone could clear this up for me. Thanks for reading!