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.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityI'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.
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.
fovy
is the "Field Of View", in Y-direction. Basically "the (vertical) opening angle" of the view frustum.
\$\endgroup\$
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.