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

Author Topic: sf::Angle not working?  (Read 2090 times)

0 Members and 1 Guest are viewing this topic.

PupperGump

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
sf::Angle not working?
« 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?

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: sf::Angle not working?
« Reply #1 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));

PupperGump

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: sf::Angle not working?
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::Angle not working?
« Reply #3 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
 
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

PupperGump

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: sf::Angle not working?
« Reply #4 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::Angle not working?
« Reply #5 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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything