# Anyone who has decomposited the MODELVIEW matrix? how?

Hi!

i want to isolate the from the MODELVIEW matrix, first the MODEL and the VIEW matrix and then, from the MODEL matrix, isolate the ROTATION, the TRASLATION and the SCALING matrices.

http://www.gamedev.net/community/forums/topic.asp?topic_id=411748

Any clue will be appreciated.

You can determine rotation, translation and scaling from a matrix. Read some matrix FAQ, basically the translation will be the fourth-row vector, rotations are stored in first three rows (as axis) and the scaling factor can be isolated by computing the length of each axis. This what I guess, as my algebra classes lay a year ago :-/
Hovewer, this is not possible to decompose the MODELVIEW in MODEL and VIEW. This is a similar task of solving the equation of a + b = 100: there are unlimited solutions

In OpenGL, a vertex in object coords is transformed to the eye coords by multiplying GL_MODELVIEW_MATRIX:
Ve = Mv * Mm * Vo

Vo: Vertex in object coords
Mm: Model matrix, to transform object coords to world coords
Mv: View matrix, to transform world coords to eye coords
Ve: Vertex in eye coords

Note that GL_MODELVIEW_MATRIX is combined Model matrix and View matrix because there is no camera(view) in OpenGL. More precisely, the view is always at (0,0,0) and is looking along -Z axis. Therefore, to move a camera, move all objects reverse direction instead.

You may seperate Model and View matrix something like this:

``````void draw()
{
float modelMatrix;
float viewMatrix

// initialize ModelView matrx
glMatrixMode(GL_MODELVIEW);

// transform your camera here, glTranslate, glRotate, glScale
// This will transform a vertex from world coords to eye coords
...

// store view matrix only
glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);
glLoadIdentity(); // reset the matrix before any model tramsformations

// transform your vertices here, glTranslate, glRotate, glScale
// This transforms a vertex from object coords to world coords
...

// store Model matrix only
glGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix);

// reconstruct GL_MODELVIEW matrix before defining any vertex
// Mmv = Mv * Mm