# 3d projection help?

I've been wanting to know how to do 3d projections.

Can someone explain how i can use this to find the position for x and y on the 2d plane that is 600 * 600 pixels.

• What do you mean by "get a position for x and y on a screen?" Are you asking how to get a point on the surface of 3D geometry, or how to project 3D geometry into 2D for rendering?
– jzx
Aug 26, 2015 at 6:13
• In other words, what would be the output you're looking for? A 3D coordinate? A color? Distance from the camera surface (depth)?
– jzx
Aug 26, 2015 at 6:15
• I meant the 2d plane that the 3d points are going to be projected onto. Aug 26, 2015 at 16:45

Assuming that you want to compute the position that an arbitrary 3D vertex (x,y,z,1) has on the view plane after the projection: You can use the given parameters to compute a projection matrix:

where f = cotangent(fovy * 0.5)

This is also the matrix that will be set by a call to gluPerspective. Then, you can multiply this matrix with your vertex to obtain the projected vertex position.

• In the vertex matrix would it contain [x,y,z,1] or just [x,y,z]? Aug 27, 2015 at 15:39
• Also what is fovy? Is it the distance to the 2d plane? Aug 27, 2015 at 15:39
• @Funshine For some mathematical reasons, the vertex must be a 4D point. You can just add "1" as the last component of the 3D point that you already have. And fovy is the "Field Of View", in Y-direction. Basically "the (vertical) opening angle" of the view frustum. Aug 27, 2015 at 15:43
• How do i find the value of fovy? Aug 27, 2015 at 15:48
• Would it be (tan^-1(D/(W/2)))*2 where D is the distance to the 2d plane and W is the width? Aug 27, 2015 at 16:01

Generally, you have to use a bunch of matrices. With the traditional OpenGL pipeline, you'd have to mutiply these matrices:

finalMatrix = modelMatrix
*
viewMatrix
*
projectionMatrix
*
viewport.windowMatrix;


To find the position of the vertex on your viewport, just multiply the vertex by the matrix:

onViewportVertex = in3dVertex * finalMatrix;


Of course, this implies that no shader modifies the vertex or the pixel.