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

Author Topic: Converting to standard Cartesian  (Read 3904 times)

0 Members and 1 Guest are viewing this topic.

efeman

  • Newbie
  • *
  • Posts: 8
    • View Profile
Converting to standard Cartesian
« 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 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?

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Converting to standard Cartesian
« Reply #1 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!
« Last Edit: July 08, 2013, 12:10:01 am by Jebbs »
DSFML - SFML for the D Programming Language.

efeman

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Converting to standard Cartesian
« Reply #2 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.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Converting to standard Cartesian
« Reply #3 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.
DSFML - SFML for the D Programming Language.

efeman

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Converting to standard Cartesian
« Reply #4 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.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Converting to standard Cartesian
« Reply #5 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.

DSFML - SFML for the D Programming Language.

efeman

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Converting to standard Cartesian
« Reply #6 on: July 10, 2013, 06:42:44 am »
Yeah, that makes sense, and shouldn't be too bad to implement. Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Converting to standard Cartesian
« Reply #7 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);
Laurent Gomila - SFML developer

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Converting to standard Cartesian
« Reply #8 on: July 10, 2013, 08:02:05 am »
It draws everything upside down. :P
DSFML - SFML for the D Programming Language.

efeman

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Converting to standard Cartesian
« Reply #9 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?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Converting to standard Cartesian
« Reply #10 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.
« Last Edit: July 18, 2013, 05:15:47 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything