SFML community forums

Help => Graphics => Topic started by: Dummie on March 21, 2008, 10:53:48 pm

Title: Rotation and movement...
Post by: Dummie on March 21, 2008, 10:53:48 pm
Hey,

Currently I'm checking out the possibillities to rotate a sprite. It works very great, but I got a question. Why the degree get with every turn +/-360?
I was wondering very much when I made a debug output with GetRotation() and saw a very big or very small value instead of something like 127...

In addition to that I'd like to build something like this:
http://www.tonypa.pri.ee/tbw/tut20.html

Could somebody provide me a code example that calculate the values I have to pass to SetLeft() and SetTop() to get the same result as on the page I posted above?

Thanks in advance :) :) :)


PS: If I rotate the sprite do I have to call this code again?
Code: [Select]

Sprite.SetRotationCenter(Sprite.GetHeight() / 2, Sprite.GetWidth() / 2);

Or is it done by SFML already?
Title: Rotation and movement...
Post by: Kingdom of Fish on March 21, 2008, 11:23:30 pm
You only have to set the center once.
Title: Rotation and movement...
Post by: Dummie on March 23, 2008, 05:01:20 pm
Thank you :)

But I still haven't a answer to my other question :)

Thanks in advance
Title: Rotation and movement...
Post by: Laurent on March 24, 2008, 05:17:55 pm
Quote
Why the degree get with every turn +/-360?

Because there's no code to keep it in the range [0, 360] or [-180, 180] (or whatever you prefer). You can apply a modulo if you want to keep it in a specific range.

Maybe I'll have to do it on SFML side however, as accumulation with float numbers could cause a loss of precision.
Title: Rotation and movement...
Post by: Aszarsha on March 24, 2008, 05:20:10 pm
Quote from: "Laurent"
Maybe I'll have to do it on SFML side however, as accumulation with float numbers could cause a loss of precision.
It actually do, i've encoutered the problem a couple of times.
Title: Rotation and movement...
Post by: Laurent on March 24, 2008, 05:34:09 pm
Ok, rotations are now kept in the range [0, 360].