# Calculating Model-View-Projection Matrix

• 07-04-2013, 07:14 AM
Alphaomega86
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!
• 07-05-2013, 08:05 PM
tonyo_au
Code :

`MVP = identity * projection * modelview.`

This should be

Code :

`MVP = projection * modelview * identity`

If you are using c++ have a look at GLM library
• 07-05-2013, 08:19 PM
GClements
Quote:

Originally Posted by tonyo_au
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`
• 07-05-2013, 08:35 PM
tonyo_au
Good point - since it is an identity matrix not an arbitrary matrix:sorrow: