Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SF::Rotation returning a value above 360 or below 0  (Read 3571 times)

0 Members and 1 Guest are viewing this topic.

natchos

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • Email
SF::Rotation returning a value above 360 or below 0
« on: November 10, 2012, 12:41:18 am »
So, the title says it all. Despite the description text of sf::transformables function sf::getrotation says:

get the orientation of the object

The rotation is always in the range [0, 360].
Returns:
Current rotation, in degrees

So is this untrue or not? To see the rotation I'm using
                                       
std::ostringstream ss;
ss.str("");
ss << player.getRotation();
VelocityText.setString(sf::String(ss.str()));
and then drawing VelocityText to the screen.

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #1 on: November 10, 2012, 12:52:00 am »
It's true. But it shouldn't be an issue.
So:

-1 == 360
-2 == 359

361 == 0
362 == 1
« Last Edit: November 10, 2012, 12:55:06 am by kaB00M »



natchos

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #2 on: November 10, 2012, 01:05:37 am »
It's true. But it shouldn't be an issue.
So:

-1 == 360
-2 == 359

361 == 0
362 == 1

It's not really an issue that can't be compensated for, still it would be nice if documentation corresponded with what the actual code does.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #3 on: November 10, 2012, 01:22:38 am »
-1 is equal to 359, 361 is equal to 1..
And it can't return anything not in [0,360], rotation gets clamped into that range. I just tried and the result is: rotating and setting rotation to anything between -600.f and 600.f with 0.1f jumps, doesn't cause returned rotation to not fit in range. Go read code and commits history at github, there was change that introduces that 4 months ago so if your sfml dlls are old, you will get values beyond these bounds.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #4 on: November 10, 2012, 09:35:35 am »
It would be nice if you could describe your actual problem. All I see in your first post is "is the documentation correct?", but you don't describe what you do, and what results you get. A complete and minimal code that reproduces the problem would be perfect. And yes, first make sure that your version is not too old.
Laurent Gomila - SFML developer

natchos

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #5 on: November 13, 2012, 03:00:06 pm »
It would be nice if you could describe your actual problem. All I see in your first post is "is the documentation correct?", but you don't describe what you do, and what results you get. A complete and minimal code that reproduces the problem would be perfect. And yes, first make sure that your version is not too old.

I am using the SFML 2.0 rc. I'm not quite sure how to check what exact version I have.
It isn't exactly a big problem it merely complicates my calculation during rotation of objects. What I merely meant it that a sprite which is rotated above 360 degrees or below 0 degrees will, when you call its getRotation function, return precisely that, a value above 360 or below 0.

Since the documentation explicitly states that the value returned by getRotation would be between 0 and 360, I merely wondered whether you should change that statement in the documentation as it is not (to my experience)correct.
(or include this code in the rotate/getRotation function)
       
if(this->getRotation() >= 360)
{
        this->rotate(-360);
}
else if(this->getRotation() < 0)
{
        this->rotate(360);
}

The problem itself is easily replicable, just create a sprite, rotate it and print its rotation(using the getRotation function).

EDIT: I just looked over the first post/thread name and saw how sloppy it looked. Very sorry for that.
« Last Edit: November 13, 2012, 03:10:14 pm by natchos »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #6 on: November 13, 2012, 03:23:34 pm »
The documentation is correct, the rotation should never be out of the range [0 .. 360].

That's why we need to see your code.

Quote
The problem itself is easily replicable, just create a sprite, rotate it and print its rotation(using the getRotation function).
So please provide the code. Even if it's short and simple, it's better if written once by you and simply copied by everyone else. And this way we are also sure that your code and our code is exactly the same. No stupid mistake.
Laurent Gomila - SFML developer

natchos

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #7 on: November 13, 2012, 03:40:13 pm »
The documentation is correct, the rotation should never be out of the range [0 .. 360].

That's why we need to see your code.

Quote
The problem itself is easily replicable, just create a sprite, rotate it and print its rotation(using the getRotation function).
So please provide the code. Even if it's short and simple, it's better if written once by you and simply copied by everyone else. And this way we are also sure that your code and our code is exactly the same. No stupid mistake.

Ok, here is a functioning example.
void main()
{
        sf::RenderWindow App(sf::VideoMode::VideoMode(320,480),"Test!",sf::Style::Default);
sf::Text VelocityText;
std::ostringstream ss;
sf::Sprite extraeye;
sf::Texture Eye;
Eye.loadFromFile("Graphics/eye.png");
extraeye.setTexture(Eye);
while(App.isOpen())
{
extraeye.setOrigin(extraeye.getLocalBounds().width/2,extraeye.getLocalBounds().height/2);
extraeye.rotate(10.f);
ss.str("");
ss << extraeye.getRotation();
VelocityText.setString(sf::String(ss.str()));
App.clear();
App.draw(extraeye);
App.draw(VelocityText);
App.display();
}
}

(You will have to use your own texture tho :P)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #8 on: November 13, 2012, 03:42:48 pm »
Might this be related to this commit?
There's probably no problem in the latest code @ git repository...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

natchos

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • Email
Re: SF::Rotation returning a value above 360 or below 0
« Reply #9 on: November 13, 2012, 03:48:55 pm »
Might this be related to this commit?
There's probably no problem in the latest code @ git repository...

I would indeed believe that it is, if such a code snippet is also in the rotate function (and since I think that rotate just calls setRotation inside I would think so). Sorry to have disturbed you.

 

anything