PDA

View Full Version : what does the matrix mean?



qxsl2000
09-02-2014, 12:10 PM
hi,guys. i've saw a code snippet from gpu gmes 2,chapter 21:"High Quality Antialiased Rasterization", and really confused by the following code related space transforming:



// Compute a standard projection matrix from a field of view, hither and
// yon plans and screen resolution. This does not include tile offsets.

Matrix4
compute_cam2ras (float fov, float hither, float yon, int resx, int resy)
{
// Set up a projection matrix from camera to screen space (incl. aspect)
float aspect = float (resx) / float (resy);
Matrix4 cam2scr = Matrix4::PerspectiveMatrix (fov, aspect, hither, yon);

// Set up a 2D matrix from screen space to NDC (halve and translate)
Matrix4 scr2ndc = //what's does the matrix mean? why it post-mulply after cam2scr matrix(in homogeneous clip space)?
Matrix4 (0.5, 0, 0, 0,
0, -0.5, 0, 0,
0, 0, 1, 0,
0.5, 0.5, 0, 1);

// Set up a 2D matrix from NDC to raster space (OpenGL projection matrix)
Matrix4 ndc2ras =
Matrix4 ((float)resx, 0, 0, 0,
0, (float)resy, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);


Matrix4 cam2ras = cam2scr * scr2ndc * ndc2ras;
return cam2ras;
}


that comments above the "Matrix4 scr2ndc" line says transforming from screen space (viewport?) to NDC. how could it be that because cam2scr matrix was in homogeneous clip space,why not be transforming from NDC to screen space, e.g (-1,1) map to (0,1). those matries were really fuzzy. maybe something i can't figure out it ,correct me . i'll appreciate. thank you very much.:)

BenFoppa
09-02-2014, 02:20 PM
This was really helpful for me: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

The order of multiplication I used was the opposite from the one described above, though still not entirely sure why. There IS a little trial-and-error involved, but having a good understanding of what the matrices are for is definitely step one! (right now, I maintain a separate translation, rotation, and FOV matrix just for my own sanity).

Also, the docs for the old OpenGL functions that made these matrices might be helpful (e.g. https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml and https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml).

A good test of knowledge is if you can create some of the simpler transformation matrices (e.g. translation matrix) without looking at any resources.

Disclaimer: I'm pretty damn new to OpenGL.

Edit: Sorry, my reply went a way general than your question - I'm not sure if it's actually helpful or not.

qxsl2000
09-02-2014, 09:00 PM
This was really helpful for me: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

The order of multiplication I used was the opposite from the one described above, though still not entirely sure why. There IS a little trial-and-error involved, but having a good understanding of what the matrices are for is definitely step one! (right now, I maintain a separate translation, rotation, and FOV matrix just for my own sanity).

Also, the docs for the old OpenGL functions that made these matrices might be helpful (e.g. https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml and https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml).

A good test of knowledge is if you can create some of the simpler transformation matrices (e.g. translation matrix) without looking at any resources.

Disclaimer: I'm pretty damn new to OpenGL.

Edit: Sorry, my reply went a way general than your question - I'm not sure if it's actually helpful or not.

hey,BenFoppa. your mentioned projection transforming of regular pipeline have done in Matrix4::PerspectiveMatrix except no viewport involving. hope some guys any hints for rest of those matries transforming !:tired:


EDIT:
btw, personally i would preferred to treat those two separated matries as viewport matrix ,but the assumption is in contradiction to that comments says.