Fortunately not a reference to the Matrix within the Matrix movie or some such, I’ve been working on a metaprogrammed matrix math library similar to Blitz++ or MTL, though not so comprehensive.
Why write my own math library? Well, as this is for the book, I felt that using a third party library could complicate licensing issues, so I thought I might as well write my own, and if I’m going to write my own, then I have to learn something from it, which means that I took it as occasion to learn expression templates and metaprogramming more in depth. It’s taken far longer than I would have liked, but how much of that is attributed to complexity versus simple scheduling conflicts (such as work
) I can’t say.
The idea is to use the advantages of template metaprogramming to create an efficient, game friendly matrix library with a minimal amount of redundancy.
Game friendly means that it would support common inline notation (whereas MTL requires the use of the function mult to multiply matrices), common operations (dot product, cross product, transpose, inverse), and conversions (euler angles, axis/angle, quaternions, pluecker) only. No eigenvectors or determinants.
The benefit would be improved efficiency. By using metaprogramming techniques, you get generic code for any size matrix rather than redundant code for 1×3, 3×3, 4×4, etc. Also, you can put in generic optimizations as well, such as loop unrolling. Couple that with the compiler’s use of vector math instructions (which most support now) and you can get some pretty fast math code.
If you absolutely must, by using template specialization, you can selectively target optimizations where necessary.
I am finishing up the library with the essentials I need for my game, and then will be writing a paper on it for CodeProject.
If you think of other operations that should be included, let me know.