Original Post
I am designing a game in android and I have a problem when updating a polygon that is used for collision detection. When the objects update method is called it rotates the object by .5 and then updates the polygon by rotating it by the same amount. The problem is on the screen the polygon is rotating faster than the object when drawn. The polygon is rotating so fast that it looks like a star, eventually it slows down and then speeds up again. It will not stay in step with the objects rotation.
This is the rotation code for the polygon.
This is the update method for the object
Trying to limit the time has no effect on the polygon and it continues to speed up and slow down.
Can anyone please identify the error or lead me in the right direction to fix this?
thanks
This is the rotation code for the polygon.
public void rotate(float x0, float y0, double angle) {
for(int i = 0; i < mOrigins.size(); i++) {
Point point = mOrigins.get(i);
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 npoint = mPoints.get(i);
npoint.x = x;
npoint.y = y;
mPoints.set(i, npoint);
}
}
This is the update method for the object
public void update(float deltaTime) {
mAccumulatedTime += deltaTime;
while(mAccumulatedTime > FIXED_FRAME_TIME) {
mAccumulatedTime -= FIXED_FRAME_TIME;
if(isActive()) {
rotate();
mBounding.rotate(mPosition.x, mPosition.y, mDegree);
drawBounding();
}
}
}
Trying to limit the time has no effect on the polygon and it continues to speed up and slow down.
Can anyone please identify the error or lead me in the right direction to fix this?
thanks