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

Author Topic: Get positional data from View in SFML 2.0  (Read 1795 times)

0 Members and 1 Guest are viewing this topic.

Rubenknex

  • Newbie
  • *
  • Posts: 21
    • View Profile
Get positional data from View in SFML 2.0
« on: May 06, 2011, 09:20:00 pm »
I just changed to SFML 2.0 and all went well until I couldn't find a way to retrieve data about the position of the current sf::View. I have a tile map and I only want to draw the tiles that are currently visible. The only way I thought of was to retrieve the data from the projection matrix but it seems kind of hacky :?.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Get positional data from View in SFML 2.0
« Reply #1 on: May 06, 2011, 09:30:24 pm »
With GetCenter() and GetSize() you can reconstruct the view rectangle.

If rotation is involved, things get more complicated since the rectangle is not aligned on axes anymore.
Laurent Gomila - SFML developer

Roswell_r

  • Newbie
  • *
  • Posts: 12
    • View Profile
Get positional data from View in SFML 2.0
« Reply #2 on: May 07, 2011, 02:07:16 am »
Correct me if im wrong but he could use the windows ConvertCoords function and convert 4 points on the screen based on the viewport and use those 4 points to create planes to determine which tiles are on screen or not.

Better yet write a function that takes a OBB from a sf::View and takes a position vector and returns whether the tile is inside the view.

Rubenknex

  • Newbie
  • *
  • Posts: 21
    • View Profile
Get positional data from View in SFML 2.0
« Reply #3 on: May 07, 2011, 10:08:47 am »
I had some problems with the GetCenter() function because the View logic changed in SFML 2.0, I corrected it and everything works fine again.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Get positional data from View in SFML 2.0
« Reply #4 on: May 07, 2011, 10:21:47 am »
Quote
Correct me if im wrong but he could use the windows ConvertCoords function and convert 4 points on the screen based on the viewport and use those 4 points to create planes to determine which tiles are on screen or not.

Yes, it should work.
Laurent Gomila - SFML developer