opengl - Why use a Matrix for 3D Projection? -


after searching calculations projection matrix (atleast in opengl),

matrix

why bother using matrix when have many empty values? count 9 entries marked 0, , 7 containing useful data. why not use similar 1d array, , store data in list-like shape? wouldn't save memory , time creating functions can manipulate matrices? i'm sure entire argument can used in other topics as-well, makes me think,

what specific reason using matrices in projecting 3d environments?

the projection of 3d point (x,y,z) 2d image coordinates (x,y) can calculated vector-matrix multiplication in homogeneous coordinates:

[ a_00  a_01  a_02  a_03 ]   [ x ]    [ x w ] [ a_10  a_11  a_12  a_13 ] * [ y ] =  [ y w ] [ a_20  a_21  a_22  a_23 ]   [ z ]    [ z w ] [ a_30  a_31  a_32  a_33 ]   [ 1 ]    [  w  ] 

with

[ x w ]   [ x a_00 + y a_01 + z a_02 + a_03 ] [ y w ]   [ x a_10 + y a_11 + z a_12 + a_13 ] [ z w ] = [ x a_20 + y a_21 + z a_22 + a_23 ] [  w  ]   [ x a_30 + y a_31 + z a_32 + a_33 ] 

and pixel coordinates (x,y) obtained dividing first , second rows fourth row. step conversion homogeneous cartesian coordinates.

the third row of opengl projection matrix set in way z becomes projected depth, such z values between n , f (near , far planes) mapped -1...1. used depth test/clipping. because fourth row [0 0 -1 0], conversion homogeneous cartesian coordinates corresponds division -z, results in perspective transformation (with inverted depth).

any other way of expressing projection involve same steps, namely linear transformation, followed division z perspective foreshortening. matrices usual representation in linear algebra these operations.

this not specific perspective projections, many 3d transformatios can expressed using 4x4 matrix, including rotations, translations, scalings, shearings, reflections, perspective projection, orthogonal projection, , others.

multiple transformations should applied after 1 can combined single 4x4 matrix matrix multiplication. example rotations around x, y , z axis, or mvp matrix. model-view-projection matrix, translates 3d point in local coordinate system of 1 object in 3d scene, final pixel coordinate on screen. on these combined matrices components can non-zero.

so advantage single operation, vector-matrix multiplication useable these cases, instead of several different operations. performed in efficient way on gpu hardware.


Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -