opengl - how to get inverse of modelview matrix? -
i transformed vector multiplying model view matrix.
glgetdoublev( gl_modelview_matrix, cam ); newx=cam[0]*tx+cam[1]*ty+cam[2]*tz+cam[3]; newy=cam[4]*tx+cam[5]*ty+cam[6]*tz+cam[7]; newz=cam[8]*tx+cam[9]*ty+cam[10]*tz+cam[11];
how inverse of model view matrix reverse transformation?
what have in posted code isn't correct way of applying modelview matrix. opengl uses column major order matrices. calculation need this:
newx=cam[0]*tx+cam[4]*ty+cam[8]*tz+cam[12]; newy=cam[1]*tx+cam[5]*ty+cam[9]*tz+cam[13]; newz=cam[2]*tx+cam[6]*ty+cam[10]*tz+cam[14];
for inverted matrix, can use generic matrix inversion algorithm, @datenwolf suggested. if can make assumptions matrix, there easier , more efficient methods. typical case know transformation matrix composed of rotations, translations, , scaling. in case, can pick matrix apart these components, invert each, , reassemble them inverted matrix. since rotations, translations , scaling trivial invert, can done simple math.
Comments
Post a Comment