View Full Version : Manually create a model-view matrix?

06-17-2009, 08:26 AM
How do I manually create a model-view matrix?
I'm making a 2d game, and would like to store matrices representing transformations for animation.

How can I create a matrix in the format which openGL "understands"?
Also, how would I then use it?

Cheers! Thanks in advance :)


Dark Photon
06-17-2009, 11:33 AM
How do I manually create a model-view matrix?
Need more detail. You can create it anyway you want! It's just a 4x4 matrix that transforms positions from object-space to eye-space. Most intro to graphics books cover this.

You can let OpenGL create it for you, one transform at a time. Just set glMatrixMode( GL_MODELVIEW ) and start ripping out transforms (glTranslate, glScale, etc.).

The only thing really OpenGL-specific about the matrix is that it follows the column-major operator-on-the-left (P*V*M * v1 = v2) convention. Which is the same as row-major operator-on-the-right (v1 * M*V*P = v2).

James A.
06-18-2009, 12:34 AM

Here is a nice explanation of what each part of the matrix does. The Red Book also goes through it quite well.

A format that OpenGL understands is a float m[16], column major, so the translation is in elements m[12~14]

06-18-2009, 01:57 AM
Thanks for the help both of you! My original question was not phrased very well, and what I actually meant was how does OpenGL store matrices? James A seems to have answered my question - an array of floats with 16 length :)

I understand now - thanks for the help again! :)