SFML community forums

General => General discussions => Topic started by: Laurent on October 29, 2012, 11:15:23 am

Title: A new name for RenderTarget::convertCoords
Post by: Laurent on October 29, 2012, 11:15:23 am
Hi :)

Recently, I realized that the inverse of convertCoords (i.e. converting from world units to target pixels) would really be useful, and was tricky to implement with the current API. So I thought about adding it.

But I need a new name, because "convertCoords" is not clear at all about what is converted, and what it is converted to. So I need two names: a clearer replacement for convertCoords, and the corresponding name for the inverse function.

And... I can't find something good enough, that's why I ask here :)
Title: Re: A new name for RenderTarget::convertCoords
Post by: Ceylo on October 29, 2012, 12:26:02 pm
Maybe this could help you. Here a Rect is a structure having both an origin and a size. But you could change it to an origin/point only. In the OS X API there are methods for this in the Window class:
Quote
Window::convertRectFromScreen(Rect) : Rect
Converts the rectangle from the screen coordinate system to the window’s coordinate system
Quote
Window::convertRectToScreen(Rect) : Rect
Converts the rectangle to the screen coordinate system from the window’s coordinate system.

There are also methods to do the same transformation but between widgets:
Quote
Widget::convertRectToWidget(Rect, Widget targetWidget) : Rect
Converts a rectangle from the receiver’s coordinate system to that of another widget.
Quote
Widget::convertRectFromWidget(Rect, Widget) : Rect
Converts a rectangle from the coordinate system of another widget to that of the receiver.

Note that I've modified the names a little bit, as it originally comes from an Objective-C documentation where Widgets are named Views.

Edit: after reading View Geometry: Transforming the Coordinate System (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaViewsGuide/Coordinates/Coordinates.html#//apple_ref/doc/uid/TP40002978-CH10-SW10) I guess the second part (conversion from widget to widget) is a little bit too advanced for SFML.
Title: Re: A new name for RenderTarget::convertCoords
Post by: Foaly on October 29, 2012, 12:35:08 pm
Ogre uses the rather long but discribtive name Ogre::Node::convertLocalToWorldPosition and Ogre::Node::convertWorldToLocalPosition.

See here: http://www.ogre3d.org/docs/api/html/classOgre_1_1Node.html#a57cd15b649fad2def94ba08e6ef230ed
Title: Re: A new name for RenderTarget::convertCoords
Post by: Laurent on October 29, 2012, 01:00:51 pm
Quote
Maybe this could help you
So... RenderTarget::convertPointToWorld? That could work.

Quote
Ogre uses the rather long but discribtive name Ogre::Node::convertLocalToWorldPosition
Here it's not from local to global, it's from global to render-target.
Title: Re: A new name for RenderTarget::convertCoords
Post by: Ceylo on October 29, 2012, 01:27:35 pm
Quote
Maybe this could help you
So... RenderTarget::convertPointToWorld? That could work.
Yup, looks fine to me.
Title: Re: A new name for RenderTarget::convertCoords
Post by: Hiura on October 29, 2012, 10:02:14 pm
«World» sounds odd here, don't you think ?

What about convertPointToBase ? Base is vague enough but unlike world it doesn't make be think of the game/app environment (especially if there's a World class). In fact, when I hear/read «world» I don't think at a coordinate system at all. On the other hand, «base» is (mathematically) directly bound to the coordinates.
Title: Re: A new name for RenderTarget::convertCoords
Post by: FRex on October 29, 2012, 10:36:48 pm
Maybe pixelsToUnits and unitsToPixels?
Title: Re: A new name for RenderTarget::convertCoords
Post by: Nexus on October 29, 2012, 10:53:35 pm
toTargetCoords
toTargetPixels


toWorldCoords
Title: Re: A new name for RenderTarget::convertCoords
Post by: Mario on October 29, 2012, 11:55:31 pm
I'd try to keep it short/simple:

sf::Point sf::View::transform(const &sf::Point);
sf::Point sf::View::inverse(const &sf::Point);
Title: Re: A new name for RenderTarget::convertCoords
Post by: Laurent on October 30, 2012, 08:05:35 am
The conversion needs both the RenderTarget and the View. So it must be a function of sf::RenderTarget (sf::View doesn't "know" sf::RenderTarget so I prefer this way).

And it's not clear that "inverse" is the inverse operation of "transform". And I prefer clear names rather than short names ;)
Title: Re: A new name for RenderTarget::convertCoords
Post by: Nexus on October 30, 2012, 07:26:11 pm
What about FRex' and my suggestions? If we know what doesn't please you, maybe we can come up with improvements :)
Title: Re: A new name for RenderTarget::convertCoords
Post by: Laurent on October 30, 2012, 07:49:07 pm
Sorry :)

Your suggestions are ok too, that's why I said nothing about them.
Title: Re: A new name for RenderTarget::convertCoords
Post by: Nexus on October 30, 2012, 08:55:09 pm
Okay, sorry for the misunderstanding. I never know if you have overlooked something if you don't comment it... But since it's a brainstorming thread, you're actually right ;)

Title: Re: A new name for RenderTarget::convertCoords
Post by: Laurent on November 05, 2012, 02:17:20 pm
I had almost forgotten this thread, sorry.

I don't like functions that begin directly with "to", because it feels like we're trying to convert the render-target itself to something.

The word "world" is very clear to me but this is because I worked a lot with engines with scenegraphs, and entities were always in the "world" or "scene". I don't know how this word would be interpreted by other users.

So... it could be:
convertCoordsToPixel
convertPixelToCoords

"Coords" is a little vague, maybe we could use "Unit" instead.
Title: Re: A new name for RenderTarget::convertCoords
Post by: Hiura on November 05, 2012, 02:28:01 pm
what's your position on 'base' (cf my previous post) ?
Title: Re: A new name for RenderTarget::convertCoords
Post by: Laurent on November 05, 2012, 03:11:45 pm
"Base" is really vague, I don't think it is explicit enough.
Title: Re: A new name for RenderTarget::convertCoords
Post by: Hiura on November 05, 2012, 03:14:03 pm
Yeah, you're probably right. Good names are hard to find ! ^^
Title: Re: A new name for RenderTarget::convertCoords
Post by: FRex on November 05, 2012, 07:14:53 pm
Quote
Maybe pixelsToUnits and unitsToPixels?
Quote
So... it could be:
convertCoordsToPixel
convertPixelToCoords

"Coords" is a little vague, maybe we could use "Unit" instead.
Yaaaaaaaaaay... ;D
Title: Re: A new name for RenderTarget::convertCoords
Post by: Plaid Phantom on December 16, 2012, 08:19:32 am
Just noticed this thread. The decision may have been made, but what about targetToGlobalCoords/globalCoordsToTarget? "global" should be obvious enough for a C++ programmer.
Title: Re: A new name for RenderTarget::convertCoords
Post by: Laurent on December 16, 2012, 09:57:59 am
Yep, it's already changed, no need to submit new ideas ;)