PDA

View Full Version : Calculating Model-View-Projection Matrix



Alphaomega86
07-04-2013, 07:14 AM
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):


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:


Read the projection matrix.
Read the modelview matrix.
Load a matrix as identity matrix.

MVP = identity * projection * modelview.


Hopefully someone can help me!

tonyo_au
07-05-2013, 08:05 PM
MVP = identity * projection * modelview.

This should be


MVP = projection * modelview * identity

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

GClements
07-05-2013, 08:19 PM
MVP = identity * projection * modelview.
This should be

MVP = projection * modelview * identity

There's no difference. Both are equal to just

MVP = projection * modelview

tonyo_au
07-05-2013, 08:35 PM
Good point - since it is an identity matrix not an arbitrary matrix:sorrow: