Going from 3d vertex to 2d screen point

Started by
6 comments, last by senseiTU 16 years, 6 months ago
Hi, I am making a simple 3d engine (really simple). I have some vertices whose coordinates are in 3d space. How do I figure out where they should be drawn on the final 3d device coordinate sytem (our screen). I have a transformation matrix for the vertices, I'm just not sure how I combine that with the original vertex values to get a final 2d screen coordindate. Thanks
Advertisement
Object vertices are usually in object space, with the object centered around the origin.
To get the object at its proper position in world space, it's transformed by the Model matrix, and to get it to camera space, it's transformed by the View matrix.
From there, it needs to be projected using a Projection matrix, which usually is a perspective projection matrix or an orthogonal projection matrix.
After all those transformations, the object is in clip space, in normalized device coordinates. From there, there's just some scaling and offsetting to get viewport coordinates, which is the final 2D position for the fragment.

I would recommend getting and reading Real-Time Rendering by the way, it's a terrific guide to the pipeline and 3D graphics in general.

To make it is hell. To fail is divine.

Hi Zao,

I've implemented the model matrix. I don't understand the view matrix. For now, I'm ok with my camera sitting at the origin, looking down the -Z axis. If I don't plan on moving the camera, is there any need to implement the view matrix for now?

Thanks
Quote:Original post by markww
If I don't plan on moving the camera, is there any need to implement the view matrix for now?


OpenGL is doing just fine without one and uses the modelview matrix for both. View matrix is nothing but the inverse of the cameras model matrix, meaning *waves hand* there is no camera. It's just a handy concept to hide the whole "move the world the opposite way"-thing behind something more intuitive.
f@dzhttp://festini.device-zero.de
Ok, well I've put in the perspective matrix, model matrix, device matrix...

I just can't figure out how you take a vertex and pass it through the above completed matrix to get a 2d screen coordinate point for drawing...

Is there some standard formula for it?

Thanks
If using OpenGL check out the gluProject() function. If using DirectX check out the D3DXVec3Project() function.
Hi SiCrane,

I'm not using either, I'm just doing this from scratch. I can't seem to find any resource which shows you how to do it. I'm confident I have the vertex transformed with perspective and everything, just don't know how to do that last step of translating it into 2d screen coordinates,

Thanks
You first multiply the different matrices together.
Then, you multiply your Vertex with the Matrix, yielding a transformed vertex.

If youve done it right (i.e. set up the matrices right and calculated the different products right [watch out for the "right side" of multiplication as generally AxB != BxA]), you should then be able to draw the point on your 2D device using only the x and y value of your output vector.

As someone else stated above, you'd rather get a book or good website about the graphics pipeline.

greets :-)

This topic is closed to new replies.

Advertisement