Hi there. X)
I've been learning matrices, and they're very interesting. There is one thing I can't seem to wrap my head around, and I haven't had much luck finding any examples or explanations. I was hoping someone could maybe point me in the right direction here.
I get that you can multiply in particular orders to combine translation, rotation, and scaling matrices and then apply this transformation to a vector. However, what has me scratching my head is how this gets implemented in an actual game. Especially regarding translation.
Up until now I've been working with particles and shapes, as code objects, where I store their position as X and Y properties. This doesn't work out so well with a matrix rotation. Some articles mention that you must translate back to the origin before doing a rotation. It seems it might get expensive to keep doing this. It's also not too clear on how this is achieved in code when dealing with game objects. The assumption I thought was that the transformation is supposed to provide you the results, and not so much that the results will repeatedly be used to construct the next transformation matrix.
I got to thinking and playing around with having the matrices behave as a local coordinate system for the object, assuming it's center or centroid is the origin. Then using it's X and Y properties as a global/world point for the rendering to use as an offset. So my translation ends up actually just the same as before I began using matrices, a method that adds and subtracts from the X and Y position of the object. It begins to feel kind of pointless to use matrices at all if I'm resorting to this.
Even using the matrices as local transformations, it seems after you do the first translation, the rotation is going to never again rotate around it's center point. At least until you move it back, then move it back again to where it was. Translation in this sense to me seems to be something that simply moves the pivot point of a vector.
I'm having a hard time seeing how these get applied in a way where you're not doing a lot of extra operations, or creating something that reduces code and increases readability.
What are the general practices of implementing transformation matrices in games when it comes to translating locally and in a world coordinate system?
I don't know if that was framed concisely enough, but if anyone has a suggestion or a resource, it would be much appreciated. ^_^