Skip to content

Instantly share code, notes, and snippets.

@wcmatthysen
Last active February 19, 2019 10:51
Show Gist options
  • Save wcmatthysen/d75fa93a87eded3ead3813a3c0ccd010 to your computer and use it in GitHub Desktop.
Save wcmatthysen/d75fa93a87eded3ead3813a3c0ccd010 to your computer and use it in GitHub Desktop.
libgdx: rotate a rectangle shape (matrix math calculation).
Rectangle rectangle = (Rectangle)shape;
Vector2 center = new Vector2();
rectangle.getCenter(center);
Affine2 transform = new Affine2();
transform.translate(rectangle.x, rectangle.y + rectangle.height);
transform.rotate(-rotation);
transform.translate(-rectangle.x, -rectangle.y - rectangle.height);
transform.applyTo(center);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment