PDA

View Full Version : Confusion with values in modelview matrix.



Barbarosa
07-18-2013, 02:03 PM
Hello,

I have a cube and do some transformations. I need to know the coordinates of the vertices so i use the "glGetFloatv (GL_MODELVIEW_MATRIX, matrix1)" where "matrix1" is a matrix with 16 positions of type GLfloat. My problem is that in "matrix1" i only see 5 values changing (those in positions 5,6,9,10,12) while i think there should be more because all the vertices change positions. Here is the code:

void Render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
DrawCube();
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}

void DrawCube()
{
glPushMatrix();
glTranslatef( translatecube, 0.0, 0.0 );
glRotatef( rotationcube, 1.0, 0.0, 0.0 );
glGetFloatv (GL_MODELVIEW_MATRIX, matrix1);

glBegin(GL_POLYGON); //sides of cube
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glVertex3f(....);
glEnd();

glPopMatrix();
translatecube=translatecube+0.005;
rotationcube=rotationcube+0.03;
}

Could someone explain to me why this happens?

Thank you

Nowhere-01
07-18-2013, 02:23 PM
you completely misunderstand, what matrices represent and how they work on so many levels.

try reading this:
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

Barbarosa
07-18-2013, 04:04 PM
Sorry, i am using a cube but in my mind a had a square so i thought that every column of "matrix1" is a vertex. So how can i take a 4x8 matrix whose collums are the vertices that i want? And by the way the modelview matrix can only be 4x4?

Thank you for the tutorial

Alfonse Reinheart
07-18-2013, 04:35 PM
Please try reading what he linked you to. Matrices are not positions. You don't render a matrix; you render an object with a matrix. The matrix and the object to be rendered are separate concepts.

Barbarosa
07-19-2013, 03:08 AM
I have read this. Let me explain better what i need. Every shape can take the form of a matrix whose columns are the homogeneous coordinates of the shape's vertices. Now, we have a transformation matrix and the shape matrix. When we multiply them we take a new matrix whose columns are the homogeneous coordinates of the new shape's vertices. Correct me if i am wrong. What i need is this new matrix and so i thought it would be a 4x8 matrix.

GClements
07-19-2013, 04:42 AM
I have read this. Let me explain better what i need. Every shape can take the form of a matrix whose columns are the homogeneous coordinates of the shape's vertices. Now, we have a transformation matrix and the shape matrix. When we multiply them we take a new matrix whose columns are the homogeneous coordinates of the new shape's vertices. Correct me if i am wrong. What i need is this new matrix and so i thought it would be a 4x8 matrix.
You can view the transformation process that way, but OpenGL doesn't. Each vertex position is an independent column vector, i.e. you have 8 distinct 4x1 matrices.

If you want to use the transformed vertex positions in your application, the main options are:


Write your own matrix multiplication function.
Use a matrix multiplication function from some other library.
Use the utility function gluProject()

Option 3 should only be considered if the number of vertices is small, as it performs multiple transformations for each vertex (model-view, projection, viewport), whereas combining the transformations into a single matrix is more efficient.

Barbarosa
07-19-2013, 11:41 AM
Thanks for the reply GClements, that sorted out many things in my mind and also answeared my question.