View Full Version : Anyone who has decomposited the MODELVIEW matrix? how?

tirengarfio

08-29-2006, 12:48 AM

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.

Maybe you want to see also this thread:

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

Any clue will be appreciated.

Zengar

08-29-2006, 07:38 AM

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

songho

08-29-2006, 08:21 AM

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[16];

float viewMatrix[16]

// initialize ModelView matrx

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

// 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

glLoadMatrixf(viewMatrix);

glMultMatrixf(modelMatrix);

// define any vertex in object coords

glBegin(GL_POINTS);

glVertex3f(x, y, z);

glEnd();

...

}You can split each translation, rotation, and scaling matrix in similar way; init matrix -> transform -> get matrix. But, glGetFloatv() may slower than your own matrix computation routine.

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.