Manually create a model-view matrix?

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 :slight_smile:


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 (PVM * v1 = v2) convention. Which is the same as row-major operator-on-the-right (v1 * MVP = v2).

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]

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 :slight_smile:

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