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

Author Topic: Radian helper functions  (Read 26786 times)

0 Members and 1 Guest are viewing this topic.

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Radian helper functions
« on: April 11, 2008, 01:58:02 pm »
I mentioned this in another thread, but I'll put it here as well.

Helper functions/function overloads for when a transformation uses angles in degrees that would accept a radian argument instead and do the conversion would be a nice feature.

I know it isn't difficult to write the helper functions separately, but it's an extra thing to remember, along with doing an extra function call or multiplication every time they are used. An overload (possibly with the postfix character R, so a Rotate(float degrees) method would also have a RotateR(float radians) variant) to do this with an inline class method would make the conversion simpler to remember, and make SFML more appealing as it doesn't enforce a particular convention upon library users regarding how they should use angles :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Radian helper functions
« Reply #1 on: April 11, 2008, 03:26:27 pm »
No no no... Really, I can't put 24 versions of each function just to match every possible convention / unit / whatever.

Degree - radian conversion is the simplest / cheapest thing to add on user side, why does everybody complain about it missing in SFML ? :|

PS : sorry I don't mean to be rude, I'd just like to understand why so many people focus on such a small thing rather than interesting improvements :)
Laurent Gomila - SFML developer

zarka

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Radian helper functions
« Reply #2 on: April 11, 2008, 04:46:02 pm »
becouse it's the small and simple things that are the easiest to have oppinions about ;)

and here is all the radians degree conversion anyone will ever need :)
Code: [Select]

#define RAD_TO_DEG 180/PI
#define DEG_TO_RAD PI/180
//Zzzarka

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Radian helper functions
« Reply #3 on: April 11, 2008, 04:52:11 pm »
The little things matter, is the main thing :)

The other reason I suggest it is because it gets really annoying as a library user to always have to remember to write the conversions (or dig them out of an archive or old project every time I start a new project) and to use them. Libraries are meant to abstract away from the small and annoying tasks, and you can't get smaller or more annoying than having to either change all your formulae or remember conversion functions and essentially be considered a second-class user of the library because you want to use a more mathematically correct unit. :)

Not to mention with it being a small thing that a lot of people complain about, wouldn't it be easier to put in helper functions for the most common units (i.e. radians) than to be constantly barraged about their absence? :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Radian helper functions
« Reply #4 on: April 11, 2008, 05:21:58 pm »
One thing I'm also concerned with, is not bloating the public interface of the classes with many functions basically doing the same thing, whereas this thing can be done on user side with one line of code if you need it.
Laurent Gomila - SFML developer

jamba

  • Newbie
  • *
  • Posts: 7
    • View Profile
Radian helper functions
« Reply #5 on: April 12, 2008, 02:09:04 am »
In 0x will you be able to define a suffix for literals to convert them? ie my_function(180degrees) or my_function(3.14radians). That would be great if you could, but maybe I'm just completely misunderstanding the proposals.  :lol

kolofsson

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Radian helper functions
« Reply #6 on: April 12, 2008, 01:10:19 pm »
I posted this suggestion a few days ago, but now I have to agree with Laurent. You can store all angles as radians and you only use the conversion when setting the sprite.angle.

Other story is the angle direction because it has to be reverted every time you want to use it in classic trigonometrical functions (like calculating vector components). But again, I CAN live without it.

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Radian helper functions
« Reply #7 on: April 14, 2008, 05:20:47 pm »
Yeah, I read and commented on your original post and that was pretty much my inspiration for raising this.

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Radian helper functions
« Reply #8 on: April 14, 2008, 09:56:53 pm »
Most compilers will be able to optimize this function call away (yeah, I hate preprocessor makros).
But I have to admit that I prefer radians myself.
Replacing degrees with radians would imho be a good solution.
So instead of Rotate(float degree), write Rotate(float radians). Thinking of cmath, etc. this is probably used more often.

 

anything