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 4 of 4

Thread: Calculating Model-View-Projection Matrix

  1. #1
    Intern Newbie
    Join Date
    Mar 2013
    Posts
    42

    Question Calculating Model-View-Projection Matrix

    Hey,

    i tried to calculate a model-view-projection matrix for my 330 OpenGL shaders, but the matrix won't work at all...
    I googled too, but i didn't find something. Just a small example with the GLM-Math library, but this doesn't help me.

    Here is how i calculated the mvp matrix (in LWJGL):
    Code :
    glGetFloat(GL_PROJECTION_MATRIX, projection);
    glGetFloat(GL_MODELVIEW_MATRIX, modelview);
     
    Matrix4f mvp = new Matrix4f();                             //Load mvp matrix as identity matrix.
    Matrix4f mm = new Matrix4f().load(modelview);       //Load the model view matrix from the FloatBuffer containing the model view matrix.
    Matrix4f pm = new Matrix4f().load(projection);        //Load the projection matrix from the FloatBuffer containing the projection matrix.
     
    mvp.multLocal(mm).multLocal(pm);

    At all my calculation looks like:
    Code :
    Read the projection matrix.
    Read the modelview matrix.
    Load a matrix as identity matrix.
     
    MVP = identity * projection * modelview.

    Hopefully someone can help me!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Code :
    MVP = identity * projection * modelview.


    This should be

    Code :
    MVP = projection * modelview * identity

    If you are using c++ have a look at GLM library

  3. #3
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by tonyo_au View Post
    Code :
    MVP = identity * projection * modelview.
    This should be
    Code :
    MVP = projection * modelview * identity
    There's no difference. Both are equal to just
    Code :
    MVP = projection * modelview

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Good point - since it is an identity matrix not an arbitrary matrix

Tags for this Thread

Posting Permissions

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