Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

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:

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:

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:

updated to clarify question
Source Link
101010
  • 209
  • 3
  • 9

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. If 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:

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. If I first undo the scale, then this works fine (the object spins in place).

  I'm not keeping scale, orientation and translation separate and then computing the matrix every frame in this case. I'm mutating the matrix all the time.

  • 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:

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:

Source Link
101010
  • 209
  • 3
  • 9

How to spin a 2D quad in place using only matrices?

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. If I first undo the scale, then this works fine (the object spins in place).

I'm not keeping scale, orientation and translation separate and then computing the matrix every frame in this case. I'm mutating the matrix all the time.

  • 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: