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

Author Topic: Window and View coords  (Read 2230 times)

0 Members and 1 Guest are viewing this topic.

Ammandril

  • Newbie
  • *
  • Posts: 4
    • View Profile
Window and View coords
« on: March 10, 2013, 02:37:46 pm »
Hi.
I've been trying to make my View Window-coord dependant somehow, but really have no idea how to do it.
So basically I'd like to not let the view move, for example:
To the left, if there's window pixel (x=0,y) in the view
To the top, if there's window pixel(x,y=0) in the view
And so on.
Does it have anything to do with the ConvertCoords function? Cause that's rather to be used with mouseclicks, or am I wrong?
Awaiting response,
Sincerely

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Window and View coords
« Reply #1 on: March 10, 2013, 05:55:31 pm »
Sorry but I don't understand what you want to do. What do you want to do differently, compared to the default behaviour?
Laurent Gomila - SFML developer

Ammandril

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Window and View coords
« Reply #2 on: March 10, 2013, 09:59:00 pm »
Sorry, as through I read it now it really seems unclear to me as well.

So let's start with this:

I have a window and a view, that shows, let's say, half of the window(both in X and Y axis).
And then I'd like to know if my view contains a specific point in the window. Basically I'd like to achieve having no negative coordinate values(-40, -60 etc.) in my view. I'm writing a tilemap engine so it'd be good if every and each of my map's top-left corner was in (0.f, 0.f), not any other coords.

Does it have something to do with ViewPort? Or maybe should I get the View's Rectangle(but would it then return the X and Y Positions Window-related?).

I know I'm not that good at explaining what I want to achieve, but hope it will suffice.
Thanks for Your patience.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Window and View coords
« Reply #3 on: March 10, 2013, 10:25:55 pm »
I still didn't get what you want to do, sorry. ;D

Anyways for a general overview on how sf::View works, you might find my tutorial quite helpful.

If you're using the latest SFML version (directly from GitHub), then the ConvertCoords function got renamed to mapCoordsToPixel and reversed function has been added mapPixelToCoords.
With the two functions you can easily convert between what pixels you see on the window and the logical coordinates you have within the world.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ammandril

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Window and View coords
« Reply #4 on: March 11, 2013, 05:13:28 pm »
Thanks, I think it'll do with the problem.