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

Author Topic: Can someone clearly explain the coordinate system.  (Read 11206 times)

0 Members and 1 Guest are viewing this topic.

nvangogh

  • Newbie
  • *
  • Posts: 21
    • View Profile
Can someone clearly explain the coordinate system.
« on: April 29, 2013, 06:36:03 pm »
VideoMode sets the size of the display which is measured by integers to represent pixels: So 1360x768 will set a display to have 1360 pixels in the x axis and 768 pixels in the y axis. That much is clear - the picture seems not clearly explained after that. The tutorials have not explained the co-ordinate system properly

According to the tutorial a sprite does not use this system for co-ordinates because a sprite may move by a distance that is less than an int. A sprite uses floating point values to represent it's co-ordinates. (Why it uses floating point types rather than double types is a mystery to me but that may not matter at the moment)

So if a call is made to sprite.GetPosition( ), what is returned is a vector2<float> with x  and y - set to the sprite's floating point co-ordinates. What Is a TransformToGlobal supposed to do exactly? This is not explained in the documentation at any length at all. I am not even sure that it is relevant in this context.

These are the two things I want to do at the moment:

1. I want to make sprites appear in a certain position - eg like centre of x axis - regardless of the VideoMode / resolution, regardless of if the display is in fullscreen or in a resized window. I cannot see how this is to be done from the tutorials.
2. I want to make sure that a sprite does not go off the screen. I can see the need to define parameters such like if(sprite position <= boundary position) - don't move further. But the problem in doing this comes back to the problem with the explanations in the tutorial about the co-ordinates. To make matters even more confused, i have read a post right here where someone suggested that a sprite can be kept on screen by using sfml views.

What I need is a clear explanation of the co-ordinate system please.

 

nvangogh

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Can someone clearly explain the coordinate system.
« Reply #1 on: April 29, 2013, 09:32:31 pm »
isnt nobody going to answer this?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Can someone clearly explain the coordinate system.
« Reply #2 on: April 29, 2013, 10:36:34 pm »
You sometimes have to be a bit more patient, then again it has somehow slipped by me... ;)

It seems you're still using SFML 1.6. SFML 2.0 just got released, so you should definitely switch.
The best explanation I can give you for now is written down in my sf::View tutorial, though it's not 100% uptodate with the 2.0 release, but everything up to one function is still accurate. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raphman

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Can someone clearly explain the coordinate system.
« Reply #3 on: April 30, 2013, 12:52:07 pm »
You sometimes have to be a bit more patient, then again it has somehow slipped by me... ;)

It seems you're still using SFML 1.6. SFML 2.0 just got released, so you should definitely switch.
The best explanation I can give you for now is written down in my sf::View tutorial, though it's not 100% uptodate with the 2.0 release, but everything up to one function is still accurate. :)

If he goes to 2.0 there's a sweet view tutorial here: http://www.sfml-dev.org/tutorials/2.0/graphics-view.php

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Can someone clearly explain the coordinate system.
« Reply #4 on: April 30, 2013, 12:57:12 pm »
If he goes to 2.0 there's a sweet view tutorial here: http://www.sfml-dev.org/tutorials/2.0/graphics-view.php
I call shameless copy!! :P

Yeah go with the official tutorial, now that it's out. I really have to look into them as well, so I know for what I can people simply point to the tutorial. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can someone clearly explain the coordinate system.
« Reply #5 on: April 30, 2013, 01:11:26 pm »
I think you miss the intermediate layer between the 2D world and the window: the view (sf::View) -- as pointed out by eXpl0it3r.

Global coordinates of sprites and other entites are mapped to your window's pixels by the current view. It's the view that defines the area which is visible in the window. So, to center a sprite (1.) or make it collide with the boundaries of the visible area (2.), you have to use the view's rectangle to do all your calculations. You should never use the window for that.

Quote
I call shameless copy!
Mine is better ah ah 8)
« Last Edit: April 30, 2013, 01:13:13 pm by Laurent »
Laurent Gomila - SFML developer

Raphman

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Can someone clearly explain the coordinate system.
« Reply #6 on: April 30, 2013, 01:14:53 pm »
Hrm, I'm going to have to start using views too now that I think about it, since I'm just drawing stuff straight to  the window. I kept getting caught up in my own mechanics to make sure the base stuff works as it should.

nvangogh

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Can someone clearly explain the coordinate system.
« Reply #7 on: April 30, 2013, 02:55:23 pm »
You sometimes have to be a bit more patient, then again it has somehow slipped by me... ;)

It seems you're still using SFML 1.6. SFML 2.0 just got released, so you should definitely switch.
The best explanation I can give you for now is written down in my sf::View tutorial, though it's not 100% uptodate with the 2.0 release, but everything up to one function is still accurate. :)

Yes, sorry i was getting a bit frustrated yesterday.
I know about 2.0, but stuck to 1.6 simply as I had printed off all of the tutorials some months ago. Also, I have been experimenting with some of the features and felt that if i went over to the upgrade it would set me back some. I know you are right though when you say i should switch - i'm just a bit lazy  :(

Edit:
I just build SFML 2.0 using cmake-gui - It was a very simple process that took 5 mins!  :-[
I am going to take your sound advice and use it from now on. 
« Last Edit: April 30, 2013, 03:51:52 pm by nvangogh »

nvangogh

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Can someone clearly explain the coordinate system.
« Reply #8 on: April 30, 2013, 03:02:01 pm »
I think you miss the intermediate layer between the 2D world and the window: the view (sf::View) -- as pointed out by eXpl0it3r.

Global coordinates of sprites and other entites are mapped to your window's pixels by the current view. It's the view that defines the area which is visible in the window. So, to center a sprite (1.) or make it collide with the boundaries of the visible area (2.), you have to use the view's rectangle to do all your calculations. You should never use the window for that.

Quote
I call shameless copy!
Mine is better ah ah 8)

Thank you Sir - I could not figure this out. I did not mean any disrespect at all to your tutorials as i know it could not have been possible for you to explain every feature in tiny detail. I am looking forward to the book for that. Your answer, coupled with the references other people have provided should be enough for me to get an understanding now. Thanks.

 

anything