vince

05-21-2004, 06:52 AM

To get a vertex position in screen coordinates, there are 3 operations to do:

1- multiply the vertex position by the modelview projection matrix.

2- do the perspective divide.

3- do the viewport transformation.

My question is what exactly is the perspective divide and what is the equation to perform it.

Thanks.

Tom Nuydens

05-21-2004, 07:04 AM

Just divide your coordinates by W.

After the modelview/projection transformation, your vertex is in "clip space". X, Y and Z are then in the range -W to W (anything outside this range is clipped). By dividing everything by W, your coordinates are now in the -1 to 1 range ("normalized device coordinates").

-- Tom

Brian Paul

05-21-2004, 07:42 AM

For more intuition of what "divide by W" does...

Look at the projection matrix produced by glFrustum. (see the GL spec). Note that the last row is (0, 0, -1, 0). The result of applying this matrix to an (x,y,z,1) coordinate is that the W component becomes -z, i.e. (x', y', z', -z).

So, when you "divide by W", you're really dividing by -z. Don't worry about the negation. The greater the magnitude of z, the further the coordinate is from the viewing position. Thus, dividing x' and y' by z makes further coordinates move closer to (0, 0). So distant objects appear smaller.

-Brian

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.