[LibGDX]Get points of rotated rectangle?

Well, at least if you used AffineTransform you’d be using the right algorithm, and have something that still performs better than this! :wink: You could also look and see if there’s a utility in libGDX for applying matrices to a sequence of points.

Well, using halfHeight on y coordinates would be a start!

I think you’re missing the point. The rotation code rotates around 0,0. So, you need to effectively translate your entity so it’s mid-point is at 0,0, apply the rotation, then translate it back to where it was. Or just use something that handles all that for you until you understand what is going on.

Can you give an example on how to use AffineTransform with this issue?

Assuming you know the centre point of your entity, which should be x + halfWidth, y+ halfHeight. You also need an array of your 4 white points - ie. float[8] {x1,y1,x2,y2, etc.

It should be something like (untested!) -


float[] pts = ...
AffineTransform at = new AffineTransform();
at.rotate(Math.radians(angle), centreX, centreY);
at.transform(pts, 0, pts, 0, 4);

After which the pts array will contain the transformed points.

I’m slightly wary of why you are having to flip the y-axis in the code you posted. :-\