SFML community forums

General => General discussions => Topic started by: takatalvi on December 22, 2015, 04:14:06 pm

Title: sf::View as a minimap.
Post by: takatalvi 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!
Title: Re: sf::View as a minimap.
Post by: SpeCter 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.
Title: Re: sf::View as a minimap.
Post by: Hapax on December 22, 2015, 10:29:01 pm
(1.f / targetSize.x) * x
is equal to:
x / targetSize.x
 ;)
Title: Re: sf::View as a minimap.
Post by: takatalvi 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.