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

Author Topic: How to sync a position from one View to another?  (Read 2667 times)

0 Members and 2 Guests are viewing this topic.

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
How to sync a position from one View to another?
« on: August 08, 2011, 04:26:03 pm »
In my game, the player may zoom the view in and out. However, it is
possible, to zoom out far enough, that the unit's are'nt visible anymore
(they become too small).

Anyway, i want to have a dot on top of each unit, that does'nt change its
size when zooming. I created another view for that purpose, it is called
'overview'. When the default view changes its position, the overview gets the
new position as well:
Code: [Select]
overview.SetCenter (view.GetCenter ());
A zoom to the view is not applied to the overview.
The dot is created on the fly:
Code: [Select]
window->Draw (sf::Shape::Circle ((*unitIterator)->Position, 5.f, sf::Color::Green));

However, the dot is only on top of the unit, when the view is not zoomed.
When zooming out, the dot is not on top of the unit anymore. I kind of get
the idea, why this is so. But i have no idea, how to get the dot being on
top of the unit no matter what the zoom is.

Any suggestions?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to sync a position from one View to another?
« Reply #1 on: August 08, 2011, 04:36:04 pm »
Currently there's no easy way of converting coordinates between views. So I think that the easiest solution would be to forget about using a second view, and instead compute the correct circle size so that it is rendered on 5 pixels of the window. And then you can draw it at the entity's position without performing any conversion.

Code: [Select]
float circleWidth = (view.GetHalfSize().x * 2) / window.GetWidth() * 5;
// same for height

... should be enough
Laurent Gomila - SFML developer

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
How to sync a position from one View to another?
« Reply #2 on: August 08, 2011, 04:55:09 pm »
Thanks for your reply, i will try that.

However, i was hoping to get a solution for similar problem i'm having out of this.
When a unit is selected, i draw a rectangle around it. When zooming in
or out, the line becomes very thick or thin to not even visible any more or
that only one or two sides of the rectangle are visible, which looks very ugly.
I was going to try this with another view, but ran into the very same problems.

But i think i can deal with this with your suggestion and modifie the thickness
of the line according to the zoom level.

Anyway, are there future plans, to facilitate such tasks?

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
How to sync a position from one View to another?
« Reply #3 on: August 08, 2011, 05:05:06 pm »
ok, i did it. Looks very good. Thank you again.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to sync a position from one View to another?
« Reply #4 on: August 08, 2011, 06:23:24 pm »
I think it might be useful to provide more conversion functions. I'll think about it in the future.
Laurent Gomila - SFML developer

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
How to sync a position from one View to another?
« Reply #5 on: August 08, 2011, 08:03:36 pm »
ok, i did it. Looks very good. Thank you again.

 

anything