0
\$\begingroup\$

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:

\$\endgroup\$
4
  • \$\begingroup\$ I don't think there is a way to achieve that. What is the reason why you would like to not store separate data for scale, rotation and translation, and recompute the transformation matrix every frame? \$\endgroup\$
    – Vaillancourt
    Apr 4, 2016 at 14:36
  • \$\begingroup\$ Is keeping everything in SQT format the best way to do Transformation matrices? (S: Scale, Q: Quaternion for Orientation, and T: Translation) \$\endgroup\$
    – 101010
    Apr 4, 2016 at 15:37
  • \$\begingroup\$ Yes, it is. You have finer control on the order of operations, and you reduce the errors that would accumulate over time due to floating point calculations. \$\endgroup\$
    – Vaillancourt
    Apr 4, 2016 at 15:41
  • \$\begingroup\$ Normally you would call scale() after an object was moved to the origin. (It means, between your translate() calls.) Why do you use scale() as a first transformation? \$\endgroup\$ Apr 4, 2016 at 16:01

0

You must log in to answer this question.

Browse other questions tagged .