Skip to content

Instantly share code, notes, and snippets.

@wcmatthysen
Last active February 19, 2019 10:51
Show Gist options
  • Save wcmatthysen/ca7737651e5722c9885da52b1c6276af to your computer and use it in GitHub Desktop.
Save wcmatthysen/ca7737651e5722c9885da52b1c6276af to your computer and use it in GitHub Desktop.
libgdx: rotate a rectangle shape (manual math calculation).
Rectangle rectangle = (Rectangle)shape;
Vector2 center = new Vector2();
rectangle.getCenter(center);
float centerX = center.x - rectangle.x;
float centerY = center.y - rectangle.y - rectangle.height;
float cos = MathUtils.cosDeg(rotation);
float sin = MathUtils.sinDeg(rotation);
float x = centerX * cos + centerY * sin;
float y = -centerX * sin + centerY * cos;
center.x = x + rectangle.x;
center.y = y + rectangle.y + rectangle.height;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment