Slick2d - How can I rotate a polygon or any other shape ?

I would like to know how can i rotate a 2d polygon. I know that a polygon is made of vertices, so to rotate the polygon, i have to adjust the coordinates of all the vertices. But what if my polygon has 500 points?? :o I need an easier way of rotating a shape instead of adjusting the x and y of all the points one by one :persecutioncomplex: I read the slick documentation and found out that there is a Transform class in slick, I reseached it but i did not understand how to use it ::slight_smile: . From many hours I am searching google and youtube but not getting any useful stuff. All they talk about is 3d.

That is how you rotate any shape. You rotate each vertices individually.


public rotateAround(Shape s, Point axis, double angle) {
    for (Point p : s) {
        rotateAround(p, axis, angle);
    }
}

Now look up “rotate point around point” maybe add “2D” to the query. Lots of solutions all over.

Rotating 500 points is not a big task. At least not in LibGDX’ polygon class. Shouldn’t affect performance much.
But having a polygon with 500 points sounds like a design flaw. Are you sure using a polygon is the best approach?

Here is an excellent tutorial about Transform(or Matrix as it sometimes called):
http://www.senocular.com/flash/tutorials/transformmatrix/

If you are going to render the polygon, and not perform any collision detection, using a transform is probably the best way.
Obtain the transform used -> rotate it with its function -> render the polygon -> rotate it back to its original state.

Edit: Try this:

Transform t = Transform.createRotateTransform(* your angle *);
polygon.setTransform(t):

This should rotate the polygon and is fast.