Polygon is rotating too fast
- by Manderin87
I am going to be using a polygon collision detection method to test when objects collide. I am attempting to rotate a polygon to match the sprites rotation. However, the polygon is rotating too fast, much faster than the sprite is. I feel its a timing issue, but the sprite rotates like it is supposed to. Can anyone look at my code and tell me what could be causing this issue?
public void rotate(float x0, float y0, double angle) {
for(Point point : mPoints) {
float x = (float) (x0 + (point.x - x0)
* Math.cos(Utilities.toRadians(angle)) - (point.y - y0)
* Math.sin(Utilities.toRadians(angle)));
float y = (float) (y0 + (point.x - x0)
* Math.sin(Utilities.toRadians(angle)) + (point.y - y0)
* Math.cos(Utilities.toRadians(angle)));
point.x = x;
point.y = y;
}
}
This algorithm works when done singly, but once I plug it into the update method the rotation is too fast.
The Points used are:
P1 608, 368
P2 640, 464
P3 672, 400
Origin x0 is:
640
400
The angle goes from 0 to 360 as the sprite rotates. When the codes executes the triangle looks like a star because its moving so fast.
The rotation is done in the sprites update method. The rotation method just increases the sprites degree by .5 when it executes.
public void update() {
if(isActive()) {
rotate();
mBounding.rotate(mPosition.x, mPosition.y, mDegree);
}
}