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

Author Topic: sf::Distance ?  (Read 4761 times)

0 Members and 1 Guest are viewing this topic.

LeeZolait

  • Newbie
  • *
  • Posts: 2
    • View Profile
sf::Distance ?
« on: December 08, 2015, 09:36:34 pm »
Hi everyone !  :)
I'm wondering if we can add a new class : Distance. Who manage meters feet kilometers etc..
Like the sf::Time class.

But, a simple Distance class, don't will be very useful for SFML users, it might be more interresting to use this class on Object.
For exemple the Radius of CircleShape istead of beiing a float, beeing a sf::Distance.
And scale the sf::View with this Distance class

What do you think about that ?  ::)
Sorry for my English.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: sf::Distance ?
« Reply #1 on: December 08, 2015, 09:40:38 pm »
May I just ask why this would be useful? It's extremely easy to convert between said units and anyway, what's wrong with just using your own arbitrary unit system, rather than a standard, arbitrary system which probably wouldn't fit everyone anyway?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: sf::Distance ?
« Reply #2 on: December 08, 2015, 10:45:56 pm »
I'm thinking, why not just create UDL's (User Defined Literals) for the various units?
http://en.cppreference.com/w/cpp/language/user_literal

Or maybe you had something else in mind?

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: sf::Distance ?
« Reply #3 on: December 09, 2015, 10:43:26 am »
I was recently thinking about something similar when looking at Box2D and integrating it into a SFML app. There is one step needed to do that, you need to convert your pixel sizes from the SFML objects to meters for the Box2D objects and vice versa. That's not a complicated thing to acomplish with converter functions, but something like sf::Distance would make this easier.

But I don't know if it is really a needed feature for a multimedia library like SFML, as the only use case I can think of is physics integration, which is clearly the scope of the client code, not SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Distance ?
« Reply #4 on: December 09, 2015, 10:54:06 am »
This is completely related to how your app interprets base units, it is impossible to provide an implementation that works for everyone. How many units do you end up with after calling circle.setRadius(sf::meters(0.1))?
Laurent Gomila - SFML developer

Yatan vesh

  • Newbie
  • *
  • Posts: 17
  • Get busy livin',or get busy dyin'
    • View Profile
Re: sf::Distance ?
« Reply #5 on: December 21, 2015, 07:17:10 pm »
Hmmm what you're askins can be achieved by using simple methods. There's no need to make a whole class on that

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: sf::Distance ?
« Reply #6 on: February 18, 2016, 06:07:58 pm »
This is completely related to how your app interprets base units, it is impossible to provide an implementation that works for everyone. How many units do you end up with after calling circle.setRadius(sf::meters(0.1))?

There can be function like sf::setDistanceScale(x), which determines what '1 meter' means. By default 1m should be 200px. (for compataibility with most apps using Box2D).

BTW I think all that stuff should be in 'distance' sub-namespace.

Hyden

  • Guest
Re: sf::Distance ?
« Reply #7 on: April 09, 2016, 06:31:37 pm »
On one computer screen the length of a centimetre might be 200 pixels, whilst on another it might be 400 pixels. The thread writer is suggesting that a sf::Distance function would be useful to applications that want to provide a to scale drawing of something. For example:

sf::RectangleShape box;

box.setSize(sf::Vector2f(sf::Distance::Centimetre * 2, sf::Distance::Centimetre * 2));
box.setPosition(sf::Vector2f(500, 500));
box.setFillColor(sf::Color::Red);

The above code would create a box that would be exactly 2 by 2 centimetres.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sf::Distance ?
« Reply #8 on: April 10, 2016, 12:29:37 pm »
The ability to convert "real world" distances to and from pixel counts might be a useful feature, but if so it should be part of the proposals for fetching monitor information and properly supporting multiple monitors, because it's the monitors that define what that conversion would be. It doesn't make any real sense to provide such conversions as constants in an sf::Distance class because they obviously can't be determined at compile time, and even after your program starts up they can vary depending on which monitor you're currently working with.

Hyden

  • Guest
Re: sf::Distance ?
« Reply #9 on: April 10, 2016, 03:00:53 pm »
The implementation of a sf::Distance function would pose difficulties. It would be unreasonable to suggest SFML support every single unit that exists.