c++ - How to infer translate, shear, etc from manual matrix operations? -
while reading code ucmerced's tripath toolkit, came across these
float xmin, xmax, ymin, ymax; float mat[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; thelct->get_bounds ( xmin, xmax, ymin, ymax ); glmatrixmode ( gl_modelview ); glloadidentity (); float width = xmax-xmin; float height = ymax-ymin; mat[0]=mat[5]=mat[10]= 1.8f * (1 / (width > height ? width : height)); glmultmatrixf ( mat ); mat[0]=mat[5]=mat[10]= 1; mat[12]=-(xmin+w/2); mat[13]=-(ymin+h/2); glmultmatrixf ( mat );
in first transformation, first 3 diagonal 1
's in matrix multiplied factor. limited knowledge of identity matrix, appears scaling factor.
the second transformation, however, don't understand:
mat[12]=-(xmin+w/2); mat[13]=-(ymin+h/2); glmultmatrixf ( mat );
first of all, don't know means change indices 12
, 13
in such matrix. i'm trying figure out reading wikipedia page on transformations, guess don't have enough math-related domain knowledge make sense of it.
whereas opengl resources can find don't seem modify matrices in manner, rather use functions glscalef
.
how can relate manual matrix transformations such above scaling, shearing, translating, , rotating?
the first matrix, correctly guessed, uniform scale matrix. second matrix translation (along x , y axis). note (fixed function matrix stack of the) gl uses column major memory layout, translation part in m[12]
, m[13]
, m[14]
(see answer 9.005 in old gl faq). combined transformation not perspective projection (that require (m[3], m[7], m[11])
not null vector), orthogonal one.
for easy explanation of how these numbers can geometrically interpreted, might find this article useful.
Comments
Post a Comment