Confusion with values in modelview matrix.

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

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/

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

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.

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:

[ol]
[li] Write your own matrix multiplication function.
[/li][li] Use a matrix multiplication function from some other library.
[/li][li] Use the utility function gluProject()
[/li][/ol]
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.

Thanks for the reply GClements, that sorted out many things in my mind and also answeared my question.