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

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

## 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 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 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 on other sites
Quote:
 Original post by KalidorWhat 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

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631785
• Total Posts
3002348
×