SFML community forums

Help => Graphics => Topic started by: PupperGump on January 22, 2023, 02:32:00 am

Title: sf::Angle not working?
Post by: PupperGump on January 22, 2023, 02:32:00 am
I'm trying to follow an sf::View tutorial by exploiter, but I can't use the rotate() method at all. (version 2.5.1 on Windows 10 x64)

Here's what I've tried so far:

   sf::Angle angle(180.f); // error
   sf::Angle angle2 = 180.f; // error
   sf::Angle angle3; // No method to change this thing's angle

   view.rotate(180.f); // error
   view.rotate(angle3); // works but can't change angle
   view.setRotation(180.f); // same thing

Can't we just use a float or something, or am I not supposed to use this method?
Title: Re: sf::Angle not working?
Post by: kojack on January 22, 2023, 06:08:08 am
Using a number like 180 directly doesn't let the angle class know if you are referring to degrees or radians. So it doesn't allow directly setting the value, you need to use one of the helper functions that build an angle for you:
sf::Angle angle = sf::degrees(180.0f);
sf::Angle angle2 = sf::radians(3.14f);

view.rotate(sf::degrees(180.0f));
Title: Re: sf::Angle not working?
Post by: PupperGump on January 22, 2023, 07:18:46 am
Oh ok. It's just that the Angle constructor is extremely unclear about what to give it and the only one it shows a parameter for is the private constructor that says "float degrees". The word "angle" always refers to degrees anyways so I don't know what the deal is.
Title: Re: sf::Angle not working?
Post by: eXpl0it3r on January 23, 2023, 12:10:31 am
Well you can't use a private constructor ;)

I think it becomes a bit clearer, once we have generated documentation available, since the provided example is relatively clear on the usage:

Quote
sf::Angle encapsulates an angle value in a flexible way.
It allows for defining an angle value either as a number
of degrees or radians. It also works the other way
around. You can read an angle value as either a number
of degrees or radians.

By using such a flexible interface, the API doesn't
impose any fixed type or unit for angle values and lets
the user choose their own preferred representation.

Angle values support the usual mathematical operations.
You can add or subtract two angles, multiply or divide
an angle by a number, compare two angles, etc.

sf::Angle a1  = sf::degrees(90);
float radians = a1.asRadians(); // 1.5708f

sf::Angle a2 = sf::radians(3.141592654f);
float degrees = a2.asDegrees(); // 180.0f

using namespace sf::Literals;
sf::Angle a3 = 10_deg;   // 10 degrees
sf::Angle a4 = 1.5_deg;  // 1.5 degrees
sf::Angle a5 = 1_rad;    // 1 radians
sf::Angle a6 = 3.14_rad; // 3.14 radians
 
Title: Re: sf::Angle not working?
Post by: PupperGump on January 23, 2023, 10:54:51 am
That explanation wasn't in the .hpp file. But I got it, next time I find a function that takes a class as a parameter, I'll search for whatever unmentioned functions return that class.
Title: Re: sf::Angle not working?
Post by: eXpl0it3r on January 23, 2023, 12:39:23 pm
It's at the bottom of the header file, but as said, it will become better discoverable, once we generate the documentation, like we do for released verisons