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

Author Topic: Angle signs in SFML  (Read 5423 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Angle signs in SFML
« on: March 26, 2011, 09:15:53 pm »
Hello,

I have written some functionality in combination with vectors and angles. The more I use them, the more I think the way how SFML handles angles is not consistent. Relative to the screen, sf::Drawable::Rotate() rotates in counter-clockwise direction. But since the Y axis points downwards, the mathematical correct rotation would be clockwise.

This is not only a matter of taste. The status quo complicates the correct computation of angles. In screen coordinates, a vector with polar angle 90° points downwards, but rotating a drawable by 90° makes it "point" upwards (given angle 0° corresponds right). This is a problem when interacting with other objects on the screen. For example, a particle emitter that has the direction of the mentioned vector, emits the particles in a "wrong" direction (compared to sf::Drawable). The angle of sf::Drawable is also inconsistent with sf::View. Rotating both the view and the drawable by 1° should have no effects, however the drawable appears rotated by 2°.

Generally, the user has to flip the sign of the rotation before drawing, as soon as he computes screen objects like projectiles which require more complex vector algebra. While this is certainly possible, it is counter-intuitive and probably confusing for beginners, once they delve into trigonometry.

Therefore, my proposal is to change the angle sign in the sf::Drawable methods. I know it's not an easy decision to modify such a thing, but you should take the opportunity of SFML 2 before it is released :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Angle signs in SFML
« Reply #1 on: March 26, 2011, 09:27:40 pm »
Quote
Rotating both the view and the drawable by 1° should have no effects, however the drawable appears rotated by 2°.

This behavior [the drawable being rotated 2°] seems correct to me.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Angle signs in SFML
« Reply #2 on: March 26, 2011, 10:36:44 pm »
Quote from: "JAssange"
This behavior [the drawable being rotated 2°] seems correct to me.
It is not.

Imagine a camera directed at an object. If you rotate both the camera and the object by 1° around their joint axis, the image doesn't change.

Other transformations in SFML do neutralize each other: Moving the drawable and the view by the same offset has no effects; zooming the view and scaling the drawable by the same factor yields the same size. The only consistent option for rotation is to behave analogously.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Angle signs in SFML
« Reply #3 on: March 26, 2011, 11:10:28 pm »
You're right. Thanks for pointing this out.

I can't work on this right now, so keep it warm and use the task tracker as soon as I make it available ;)
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Angle signs in SFML
« Reply #4 on: March 26, 2011, 11:34:54 pm »
Okay. I hope you don't release SFML 2 all of a sudden :D
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Angle signs in SFML
« Reply #5 on: March 27, 2011, 04:09:57 am »
Quote from: "Nexus"
Quote from: "JAssange"
This behavior [the drawable being rotated 2°] seems correct to me.
It is not.

Imagine a camera directed at an object. If you rotate both the camera and the object by 1° around their joint axis, the image doesn't change.

Other transformations in SFML do neutralize each other: Moving the drawable and the view by the same offset has no effects; zooming the view and scaling the drawable by the same factor yields the same size. The only consistent option for rotation is to behave analogously.

Oh I was thinking of the view as rotating the screen rather then rotating a camera, it makes sense now.