1
\$\begingroup\$

I'm using polygons for collision detection. Here is the code:

poly = new Polygon(verticies);
poly.setOrigin(100,100);
poly.setRotation(45);
renderer.setColor(Color.GREEN);
renderer.begin(ShapeType.Line);
renderer.identity();
renderer.translate(poly.getOriginX(), poly.getOriginY(), 0);
renderer.polygon(poly.getTransformedVertices());
renderer.translate(-poly.getOriginX(), -poly.getOriginY(), 0);
renderer.end();

Result, polygon is rotated, but it moves to the right. Here is the picture for 0, 30, 45, 60 , 90 degrees (from left to right). What am I doing wrong?

Polygon rotation

\$\endgroup\$
  • 1
    \$\begingroup\$ Try playing with setOrigin. It may just have an incorrect offset. \$\endgroup\$ – newton1212 Jun 24 '15 at 18:12
  • 1
    \$\begingroup\$ You need to rotate about the shape center and now you're rotating about (100; 100) point. \$\endgroup\$ – nikoliazekter Jun 24 '15 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.