Matrices can be your Friends. By Steve Baker What stops most novice graphics programmers from getting friendly with matrices is that they look like 16 utterly random numbers. However, a little mental picture that I have seems to help most people to make sense of what's going on. Most programmers are visual thinkers and don't take kindly to piles of abstract math. Take an OpenGL matrix: float m [ 16 ] ; Consider this as a 4x4 array with it's elements laid out into four columns like this: m[0] m[4] m[ 8] m[12] m[1] m[5] m[ 9] m[13] m[2] m[6] m[10] m[14] m[3] m[7] m[11] m[15] WARNING: Mathematicians like to see their matrices laid out on paper this way (with the array indices increasing down the columns instead of across the rows as a programmer would usually write them). Look CAREFULLY at the order of the matrix elements in the layout above! ...but we are OpenGL programmers - not mathematicians - right?! The reason OpenGL arrays are laid out in what some people would consider to be the opposite direction to mathematical convention is somewhat lost in the mists of time. However, it turns out to be a happy accident as we will see later. If you are dealing with a matrix which only deals with rigid bodies (ie no scale, shear, squash, etc) then the last row (array elements 3,7,11 and 15) are always 0,0,0 and 1 respectively and so long as they always maintain those values, we can safely forget about them for now. The first three elements of the rightmost column of the matrix is just the overall translation. If you imagine some kind of neat little compact object (like a teapot), then array elements 12,13 and 14 tell you where it is in the world. It doesn't matter what combinations of rotations and translations it took to produce the matrix, the rightmost column tells you where the object basically is. It is often fortunate that the OpenGL matrix array is laid out the way it is because it results in those three elements being consecutive in memory. OK, so now we are down to o...
First seen: 2025-10-13 11:23
Last seen: 2025-10-14 01:27