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

Author Topic: the coordinate system in SFML - Help needed!!  (Read 4964 times)

0 Members and 1 Guest are viewing this topic.

supdawg

  • Newbie
  • *
  • Posts: 33
    • View Profile
the coordinate system in SFML - Help needed!!
« on: February 06, 2013, 10:57:04 pm »
ok so i have a general question about the coordinate system in SFML 2.

i understand the basics (such as the inverted y-axis).

i have read the documentation.

so i have randomly used getLocalBounds() and getGlobalBounds() mainly for setting the origin of a Sprite at its center. Sometimes i experience weird behaviour and so i really want to know what exactly the two aforementioned functions do, and how they relate to the coordinate system.

i understand there are different types of coordinates (global and world coordinates i believe?). can someone briefly describe what exactly they are because i cant seem to understand how sprite position works in terms of coordinates and pixels and screen height/width.

if someone could clarify these few things i would feel much more at ease working with a window and positioning things.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: the coordinate system in SFML - Help needed!!
« Reply #1 on: February 07, 2013, 11:56:45 am »
getLocalBounds() returns the bounds without any transformation applied, where as getGlobalBounds() returns the bounding box with the transformation applied. E.g. if you rotate a sprite, the local bounds won't change, but the global bounds now is a axis aligned bounding box of the sprite.
Further more the position is usually at the top left corner of the sprite, unless you defined a different origin, all the transformation will happen around this corner.
Then there's the whole sf::View thing, which can be quite unintuitive in the beginning, that's why I've created a tutorial, which should give you some intuition on the topic.

There are also other topics surrounding your question, so feel free to search a bit further.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

supdawg

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: the coordinate system in SFML - Help needed!!
« Reply #2 on: February 11, 2013, 05:05:44 pm »
ok so normally what i do is set the origin to the center of the object and i usually use getLocalBounds() because i havent yet applied any transformations. is that the correct approach?

so what your saying is that if my sprite is rotated, then getGlobalBounds() will return a rotated rectangle of some sort?

and what are the different coordinate systems. that bit was confusing me too.

krzat

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: the coordinate system in SFML - Help needed!!
« Reply #3 on: February 11, 2013, 05:26:03 pm »
so what your saying is that if my sprite is rotated, then getGlobalBounds() will return a rotated rectangle of some sort?
It will return bounding rectangle:
SFML.Utils - useful extensions for SFML.Net