Polygon rotation is too fast compared to objects rotation

Started by
35 comments, last by manderin87 11 years, 4 months ago
While trying to check, i made the rotation manual.... the polygon is still rotating faster. Its not the framerate, its the way the polygon is rotating using the polygon rotation method above or the method used to rotate the sprite.
Advertisement
There is something wrong with the polygon rotation method... I watched the degrees subtract and the polygon was still rotating the other way.. as the degree increased it went left as the degree decreased it still went left, instead of right.
Please post both rotation methods and their calling context.

Additionally, what is responsible for calculating deltaTime? Is it the elapsed time since last frame?

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

The polygon rotation method is


public void rotate(float x0, float y0, double angle) {
Log.i("Polygon", "Degree: " + angle);

for(int i = 0; i < mPoints.size(); i++) {
Point point = mPoints.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.x = x;
point.y = y;
}
}


The sprite rotation is done through a libgdx spritebatch and I am certain its correct.


public void draw(SpriteBatch batch, float x, float y, float degree) {
batch.draw(mImage, x - width() / 2, y - height() / 2,
pivotX(), pivotY(),
width(), height(),
mScale, mScale,
degree,
0, 0,
(int) width(), (int) height(),
false, false);
}


The delta time comes from libgdx and is the time since last frame.


float deltaTime = Gdx.graphics.getDeltaTime();


I am almost certain its something in the polygon rotation code... I was testing it... it would rotate until a certain point and then go the other way.
Your update method:

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();
}
}
}
[/quote]

What does rotate() do? Because by your explanation, mBounding.rotate handles the collision object rotation, and the sprite for the object is rotated by the spritebatch call.

If the sprite is being rotated by a spritebatch call, you should be giving it the same degree value that mBounding.rotate receives. Is that the case?

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

They both recieve the same mDegree value.

Could it be something with the way i move the degree past 0?


if(mDegree > 360) {
mDegree = 0;
} else if(mDegree < 0) {
mDegree = 360;
}
Does the SpriteBatch draw method deffinitely take the angle in degrees and not radians?

Could you show us how SpriteBatch uses mDegree?

Is this the same SpriteBatch method as referred to here?
http://tylerforsythe.com/2011/11/xna-spritebatch-draw-and-icecream-use-a-rotation-value-in-radians/

On second thoughts I see that is a different SpriteBatch :(
the draw method i use is above, but spritebatch deffinitely uses degrees

its located here https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java
This method is better for fixing the degree but it didnt change the behavior that I am experiencing


if(mDegree >= 360) {
mDegree -= 360;
} else if(mDegree < 0) {
mDegree += 360;
}
Is this a funciton you've defined yourself "Utilities.toRadians()"? If so can you post the code?
Is there a reason why you aren't using "Math.toRadians()"?

This topic is closed to new replies.

Advertisement