In short, I have a textured 2D quad (a sprite). I would like to rotate/spin it about the z-axis (coming out of the screen) using nothing but matrices.
If I do the following to a transform with scale in it already, the object spins, but also follows a circular path around the origin. As a test, if I first undo the scale, then this works fine (the object spins in place). But I'm not normally keeping scale, orientation and translation separate and then computing the matrix every frame in this case. I'm mutating the matrix all the time. So this isn't workable. Can this be done without first undoing the scale?
self
is the current transformation matrix (4x4)pivot
is the "center" of the quad's AABB (recomputed immediately before this)eulerAngles is a vec3 containing {0.0, 0.0, z-angle}
/* translate to the origin */ translate(self, -pivot); /* rotate */ rotate(self, eulerAngles); /* go back */ translate(self, pivot);
(I'm using OpenGL, but that probably doesn't matter much here)
There are other related articles, but I didn't get to a solution. I'm linking for reference:
scale()
after an object was moved to the origin. (It means, between yourtranslate()
calls.) Why do you usescale()
as a first transformation? \$\endgroup\$ – HolyBlackCat Apr 4 '16 at 16:01