Last active
February 19, 2019 10:51
-
-
Save wcmatthysen/ca7737651e5722c9885da52b1c6276af to your computer and use it in GitHub Desktop.
libgdx: rotate a rectangle shape (manual math calculation).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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