I am looking at Ogre3D code and WildMagic code and I found that both deal with their core classes a bit differently. Since I am creating my own core, I was wondering which would be better practice and could potentially be better in terms of resources.
In WildMagic, there is a Matrix class which inherits from a Table class (not polymorphic). The table class can have N row and N cols and gets getters and setters for the columns and rows. The Matrix class then has functionality that only makes sense for a Matrix and it conveniently inherits from Table. A vector can then also inherit from Table in this case (although WildMagic does not do it). WildMagic also has a Transform object that stores local and derived transformations for a Node. So a Node will have two Transform objects that contain the necessary transformations (which include position, rotation, scale).
In Ogre3D on the other hand, the Matrix class does not derive from anything and Ogre3D's node has variables to store the local and derived positions: Vector localPos; Vector derPos; Matrix localRot; Matrix derRot; etc.
Now keep in mind these are core objects that will be used/updated/modified thousands of times per frame and it is quite hard to change them if you realize you have a performance bottleneck down the road when you have a full game relying on these core classes.
So now questions are:
wrapper for transformations while in the other case, the transformations are exposed directly. I guess the question can be rephrased to: Does a wrapper have a cost (considering it is an object that needs to be created and destroyed)?Very good, complicated questions with many, many answers. I'll try to address them as best I can, but at least in my opinion the overall answer is going to do more with what your needs are than what a single individual might do.
1) There is always a cost to inheritance, though it is very minute. There really isn't an easy answer to this question so I would probably read: http://www.hackcraft.net/cpp/templateInheritance/
2) Anything that has to be created or destroyed has a cost. Generally wrapping things makes them "safer" for a large number of people on a project, but otherwise I don't find it useful or worth it. Just like inheritance the cost of wrapping things is very small.
3) If every calculation matters, than don't wrap things if you don't have to. And at least for simple math classes just use templates for ease of use instead of inheritance.
Overall for basic data structures for matrices and vectors you aren't going to kill your program if its on PC or a console with either approach. A slow memory manager and memory allocations will kill your game a lot more than inheriting for your vector and matrix classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With