SFML community forums

Help => Graphics => Topic started by: efeman on July 07, 2013, 11:24:17 pm

Title: Converting to standard Cartesian
Post by: efeman on July 07, 2013, 11:24:17 pm
I found some old posts similar to this, specifically http://en.sfml-dev.org/forums/index.php?topic=5990.0 (http://en.sfml-dev.org/forums/index.php?topic=5990.0) from late 2011/early 2012.

I'd like to flip the Y-axis back to use standard Cartesian. Is there a good way to do this without doing changes to every individual entity?
Title: Re: Converting to standard Cartesian
Post by: Jebbs on July 07, 2013, 11:59:45 pm
You could modify the view so that the origin is in the bottom left corner, and then multiply all y values by -1 before you draw.
Just make sure you change them back before the next update!
Title: Re: Converting to standard Cartesian
Post by: efeman on July 08, 2013, 01:22:33 am
See, extra "complexity" (if you can call it that) like that is what I'm hoping to avoid. My hope was to find some way to just apply it once during launch and have it apply everywhere.
Title: Re: Converting to standard Cartesian
Post by: Jebbs on July 08, 2013, 02:38:53 am
Even Laurent says in the other thread that he doesn't think it can be done globally. I'm pretty sure he's right about that.

Anything that draws this way is most likely going to have to be handled for each object.
Title: Re: Converting to standard Cartesian
Post by: efeman on July 10, 2013, 03:26:08 am
Bah, that's too bad. I'm surprised that this was the chosen coordinate system. Is there a reason for it that I'm not aware of? Standard Cartesian seems to make much more sense.

Thanks for the replies.
Title: Re: Converting to standard Cartesian
Post by: Jebbs on July 10, 2013, 05:03:11 am
It probably has to do with with a lot of different things, but early CRT's drew pixels Left to Right, and Top to Bottom, so people probably started creating systems based around that. And since that is they way they've always done it, it would be pretty tricky to change everything now.

I did come up with a different solution that might work, that is similar to my first suggestion. You could write a function that takes a SFML object and a RenderTarget as its parameters. This function would then multiply the y value of the object by -1, draw it, then change it back. Then you could get code that looks like this:

window.clear();
cartesianDraw(sprite, window);
window.display()

And with the view changed so that the origin is displayed in the bottom left, things should draw as you want them to.

Title: Re: Converting to standard Cartesian
Post by: efeman on July 10, 2013, 06:42:44 am
Yeah, that makes sense, and shouldn't be too bad to implement. Thanks.
Title: Re: Converting to standard Cartesian
Post by: Laurent on July 10, 2013, 07:55:29 am
Have you tried to set a view with a negative height? I don't remember if it still works, though :P

window.setView(0, 800, 600, -800);
Title: Re: Converting to standard Cartesian
Post by: Jebbs on July 10, 2013, 08:02:05 am
It draws everything upside down. :P
Title: Re: Converting to standard Cartesian
Post by: efeman on July 18, 2013, 05:01:50 am
Thanks again for the input. It still boggles my mind that this is the standard; I would have expected implementations to just come Cartesian baked in - that's what we're all taught to work with in mathematics, after all. Even OpenGL's coordinate system is Cartesian.

I don't mean to bash Laurent or any other API developers, so please don't misunderstand. I'm just surprised. Do most people that use these APIs just work with this coordinate system?
Title: Re: Converting to standard Cartesian
Post by: zsbzsb on July 18, 2013, 05:11:38 am
Thanks again for the input. It still boggles my mind that this is the standard; I would have expected implementations to just come Cartesian baked in - that's what we're all taught to work with in mathematics, after all. Even OpenGL's coordinate system is Cartesian.

I don't mean to bash Laurent or any other API developers, so please don't misunderstand. I'm just surprised. Do most people that use these APIs just work with this coordinate system?

Pretty much the coordinate system all over the place is this way (on computers from my experience). The top left being at 0, 0 is used a good deal like this. MS Windows desktop cords are like this (so I assume linux/macs to be the same), Photoshop-Gimp-MS Paint-most graphics editing programs, Box2D, SFML, Flash, HTML, and more places than I can think of off of my head use this coordinate system.