I am trying to rotate a Polygon around its own center point according to a given theta variable. It seems to work somewhat, but there are some big problems. It rotates, at an increasing speed which I do not understand. The Polygon itself also shrinks in size as it rotates until the points move into each other.
Here is the main rotating part of my code.
public void Rotate(double dTheta)
{
this.theta += dTheta;
for(int i = 0; i < body.npoints; i++)
{
body.xpoints[i] =
(int) (body.getBounds2D().getCenterX() + (body.xpoints[i] - body.getBounds2D().getCenterX()) *
Math.cos(theta) - (body.ypoints[i] - body.getBounds2D().getCenterY()) * Math.sin(theta));
body.ypoints[i] =
(int) (body.getBounds2D().getCenterY() + (body.xpoints[i] - body.getBounds2D().getCenterX()) *
Math.sin(theta) + (body.ypoints[i] - body.getBounds2D().getCenterY()) * Math.cos(theta));
}
}
The 'body' object is a Polygon that is drawn each frame at a rate of 60 FPS.
The theta variable increases by a factor of Math.PI / 180 when the user pressed the space key.
The rather large math operation I'm using was something I found on the web, it is supposed to rotate a point according to a radian angle and an anchor point.
The 'body' Polygon itself consists of the points (-16, 0), (16, -16), and (16, 16). The 'body' Polygon is initially placed at the location (100, 100) and does not translate from there aside from the rotation.
I would greatly appreciate any help on this subject, thank you in advance.