XNA Sprite Rotation Matrix - Moving Origin

Posted by Jon on Game Development See other posts from Game Development or by Jon
Published on 2011-11-29T18:37:55Z Indexed on 2011/11/30 2:08 UTC
Read the original article Hit count: 343

Filed under:
|
|

I am currently grouping sprites together, then applying a rotation transformation on draw:

private void UpdateMatrix(ref Vector2 origin, float radians)
{
     Vector3 matrixorigin = new Vector3(origin, 0);
     _rotationMatrix = Matrix.CreateTranslation(-matrixorigin) * Matrix.CreateRotationZ(radians) *  Matrix.CreateTranslation(matrixorigin);
}

Where the origin is the Centermost point of my group of sprites. I apply this transformation to each sprite in the group.

My problem is that when I adjust the point of origin, my entire sprite group will re-position itself on screen.

How could I differentiate the point of rotation used in the transformation, from the position of the sprite group? Is there a better way of creating this transformation matrix?

© Game Development or respective owner

Related posts about XNA

Related posts about sprites