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

Author Topic: sf::View as a minimap.  (Read 3967 times)

0 Members and 1 Guest are viewing this topic.

takatalvi

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
sf::View as a minimap.
« on: December 22, 2015, 04:14:06 pm »
I've recently started working on a new project that uses sf::View as a camera to a Scene. Then I started messing around with using a 2nd view as a mini map, but positioning and sizing the thing was a pain. I read through the Documentation, and the numerous tutorials all over the internet, and I haven't seen anyone do this yet, so here it is.

I do admit this is just a simple hack that I threw in, but it took me awhile to think to do it this way. Hopefully I can save someone else the trouble. I created a camera class that is a wrapper for sf::View. For positioning and/or sizing I made some helper functions with terrible names, but they work well enough for now.

Here is the declaration.
(click to show/hide)

And here is the simple implementation.
(click to show/hide)

I registered to the forums just for this, so I hope it helps someone!
« Last Edit: December 23, 2015, 01:56:58 pm by takatalvi »

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: sf::View as a minimap.
« Reply #1 on: December 22, 2015, 06:05:39 pm »
What about http://www.sfml-dev.org/tutorials/2.3/graphics-view.php?
There is a minimap example in there.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::View as a minimap.
« Reply #2 on: December 22, 2015, 10:29:01 pm »
(1.f / targetSize.x) * x
is equal to:
x / targetSize.x
 ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

takatalvi

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::View as a minimap.
« Reply #3 on: December 23, 2015, 01:50:59 pm »
What about http://www.sfml-dev.org/tutorials/2.3/graphics-view.php?
There is a minimap example in there.

That's just a demonstration, no actual code for accurately positioning a sf::View.

(1.f / targetSize.x) * x
is equal to:
x / targetSize.x
 ;)

Hurray for math! Thanks for that, I posted this after one of those "Wow this day was too long" kinda days.