Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Confusion with values in modelview matrix.

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    7

    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

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    you completely misunderstand, what matrices represent and how they work on so many levels.

    try reading this:
    http://www.opengl-tutorial.org/begin...al-3-matrices/

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    7
    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

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    7
    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.

  6. #6
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by Barbarosa View Post
    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:

    1. Write your own matrix multiplication function.
    2. Use a matrix multiplication function from some other library.
    3. 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •