I’ve been making the valiant attempt to grok the doom 3 source code. One of the things I’ve stumbled across is the matrix class used throughout the rest of the solution. It’s fairly simple code to follow, but there was a decision made that I haven’t been able to comprehend. They decided to mix Column and Major row majors for different sizes.
- The 3×3 Matrix is column major
- Every other matrix is row major (I think – haven’t checked them all)
Does anyone know why this decision might have been made? Since OpenGL is column major, I would think it would make sense to just use column major?
Like Oli Charlesworth already commented this might be a decision to improve caching behaviour. OpenGL’s matrices are column major because on the client side you’re more interested in the columns than the rows (the columns form the base of a coordinate system). If however the matrices are used for calculations like in physics or collision detection, a lot of operations will be row major. So this strongly depends on the kind of operations mostly performed on the matrix in question. The Doom3 engine makes heavy use of Plücker coordinates, so choosing the right memory layout has a very strong effect on overall performance and a simple switch between matrix majority may add/remove a significant number of operations involved.