Sign in to follow this  

How do I transform a vertex from 3D to window coordinates without GLU?

This topic is 4134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I transform a vertex from 3D to window coordinates without GLU? I want to know how do you do this with matrixes As far as I understand multyplying a Vertex V(X,Y,Z,1) with the product of the modelview and perspective matrix gives a new vertice V'(X',Y',Z',W') which is in clip space, how do I go on transforming this in window coordinates, using matrix math? :)

Share this post


Link to post
Share on other sites
I believe that is as simple as dividing V' by W where V' = (X',Y',Z',W) is the clip space vector, this gives you a new vector V"(X'/W,Y'/W,Z'/W, 1) which is in screen/window space.

EDIT: I think you may need to multiply the X" and Y" values by the width and height of your window to get the window coordinates of the vertex (also depending on the direction your Y axis points you may have to flip the Y coordinate)

Share this post


Link to post
Share on other sites
Quote:
Original post by Nepherim
...
EDIT: I think you may need to multiply the X" and Y" values by the width and height of your window to get the window coordinates of the vertex (also depending on the direction your Y axis points you may have to flip the Y coordinate)
What you're thinking of is the "Viewport Transformation," but it is not a simple multiplication by the viewport's dimensions. The actual equation used is in section 2.11.1 of the OpenGL spec (pdf).

So the entire process from Object Space to Window Space is this...
 - Vertex (Object Coordinates)
- Premultiply by ModelView Matrix (Eye Coordinates)
- Premultiply by Projection Matrix (Clip Coordinates)
- Perspective Division (Normalized Device Coordinates)
- Viewport Transformation (Window Coordinates)

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
What you're thinking of is the "Viewport Transformation," but it is not a simple multiplication by the viewport's dimensions.

True as this is, I don't think Deliverance needs the full Viewport transformation. In order to find the screen coordinates, it is not necessary to determine the homogeneous w coordinate, so the necessary transform is a simple translate and scale:

Xs = (Xc + 1) * ScreenWidth / 2
Ys = (Yc + 1) * ScreenHeight / 2

where (Xs, Ys) are screen coordinates, (Xc, Yc) are clip coordinates.

If you want to turn this into a matrix operation, you may want to do it before your homogeneous divide so the constant terms can be expressed in terms of clip-w, though I doubt the performance difference is significant (unless you're writing a shader).

Regards
Admiral

Share this post


Link to post
Share on other sites

This topic is 4134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this