Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a projection Matrix work?

Tags:

matrix

opengl

3d

I have to write a paper for my A-Levels about 3D-Programming. But I got a serious problem understanding the perspective projection Matrix and I need to fully explain the Matrix in detail. I've searched a lot of websites and youtube videos on this topic but very little even try to answer the question why the Matrix has these values at that place. Based on this http://www.songho.ca/opengl/gl_projectionmatrix.html I was able to find out how the w-row works, but I don't understand the other three.

I decided to use the "simpler" version for symmetric viewports only (right-handed Coord.):

![<code>r+l=0,</code>r-l=2r<code>(width);</code>t+b=0<code>,</code>t-b=2t<code>(height);</code>[n/r 0 0 0; 0 n/t 0 0; 0 0 -(f+n)/(f-n) -(2fn)/(f-n); 0  0 -1 0]`[1]

I am very thankful for every attempt to explain the first three rows to me!

like image 467
Mohammed Li Avatar asked Sep 04 '14 07:09

Mohammed Li


People also ask

What are projection matrices?

What are projection matrices? They are nothing more than 4x4 matrices, which are designed so that when you multiply a 3D point in camera space by one of these matrices, you end up with a new point which is the projected version of the original 3D point onto the canvas.

Can I use a projection matrix to transform a vector?

First projection matrices are used to transform vertices or 3D points, not vectors. Using a projection matrix to transform vector doesn't make any sense. These matrices are used to project vertices of 3D objects onto the screen in order to create images of these objects that follow the rules of perspective.

How do you find the projection matrix of MWF?

The MWF projection matrix is given by where gMW,j, j = 1, … D are implicitly defined. The matrix Bj is an ( N − j) × ( N − j + 1) blocking matrix, i.e., Bjhj = 0.

Why are projection matrices not used in ray tracing?

As we mentioned a few times already, in ray tracing, points don't need to be projected to the screen. Instead, rays emitted from the image plane are tested for intersections with the objects from the scene. Thus, projection matrices are not used in ray-tracing. What's Next?


1 Answers

The core reason for the matrix is to map the 3D coordinates to a 2D plane and have more distant objects be smaller.

For just this a much simpler matrix suffices (assuming your camera is at origin and looking at the Z axis):

1 0 0 0
0 1 0 0
0 0 0 0
0 0 1 0

After multiplying with this matrix and then renormalizing the w coordinate you have exactly that. Each x,y,z,1 point becomes x/z,y/z,0,1.

However there is no depth information (Z is 0 for all points) so a depth buffer/filter won't work. For that we can a a parameter to the matrix so the depth information remains available:

1 0 0 0
0 1 0 0
0 0 0 1
0 0 1 0

Now the resulting point contains the inverse depth in the Z coordinate. Each x,y,z,1 point becomes x/z,y/z,1/z,1.

The extra parameters are the result of mapping the coordinates into the (-1,-1,-1) - (1,1,1) device box (the bounding box where if you are outside of it the point won't get drawn) using a scale and a translate.

like image 159
ratchet freak Avatar answered Sep 25 '22 09:09

ratchet freak