So I have a scene graph that holds all my objects, and I have to use my own Matrix Classes for everything (Requirement, so not optional, school). I have all my math classes written but I am unsure how to to implement in code exactly the Matrix Stack.
I have a theoretical understanding of how it works. Basically my Scene is the identity matrix, then I have to take my camera matrix which I create using my Matrix 4 class, then from that I have to loop through the scene graph and glMultMatrix each level with its parent.
I think that is on the right track, but I have never coded this before and only studied the theory behind it.
Am I on the right track with this?
It should look this this.
Identity Matrix -> Camera Matrix ->
For Each Object
Reset back to Identity Matrix -> Camera Matrix – > Generate Matrix from Translate and Quaternion’s Multiply that with Identity Matrix -> Camera Matrix.
For Each Child
Generate Matrix from Translate and Quaternion’s Multiply that with the Parent’s Matrix
So Basically I have no glMatrixMode, just a Matrix Stack that exists because of my Scene Graph.
I hope this is on the right track.
No, the identity matrix is just a matrix, that multiplying with doesn’t change anything.
Not really. The idea of doing your own matrix math, is not to rely on OpenGL doing anything for you. That includes matrix multiplication. If you actually use OpenGL fixed function matrices, you’d use glLoadMatrix. But better go the modern way: Use shaders and supply the matrices as uniforms.
As a recap of how the transformation pipeline works, I refer you to https://stackoverflow.com/a/13223392/524368
Almost, you’re thinking a bit too complicated. The nice thing about doing your own matrix math is, that you’re quite free in which way you implement things.
Personally I’m a fan of in-place math operation. Using this paradigm, for each step in the matrix hierachy you’d take a copy of the lower level, and do your modifications on that one. Such a tree is nicely traversed. And for every drawing operation you just load the matrix at the branch/leaf in the transform hierachy tree, you’re currently traversing. And after drawing each thing, there’s no need for a reset, you just load the next thing, and maybe free the memory of intermediary results.