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

Author Topic: <SOLVED> sf::View keeps resetting its zoom factor.  (Read 3470 times)

0 Members and 1 Guest are viewing this topic.

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
<SOLVED> sf::View keeps resetting its zoom factor.
« on: November 29, 2012, 06:38:59 pm »
Hello friends.  I have a bit of a problem that I know must have a very simple answer, but I have been working on it for 2 days now with no avail.

I have created a "Camera" wrapper-class for sf::View.  It allows me to set a "target" and then the view will "glide" to it.  It also has a Zoom() method that will have it zoom in incremental steps toward a desired distance.

However, whenever a "glide" or "zoom" finishes, and the following block of code gets activated, it's resetting the zoom to the original factor, which displeases me greatly.

Any ideas?
(Note: There's some Box2d involved, so if something looks like it came out of nowhere, it probably has to do with that).
bool Camera::Update(sf::RenderWindow * rw)
{
if(!isGliding && !isFixed && !isZooming)      //normal camera function
    {
        //get the position of the current target
        if(!targetIsVec)
        {
            targetPos = zoToolbox::b22sfVec(_target->GetRootBody()->Getb2Body()->GetPosition());
            _targetAngle = -zoToolbox::b22sfAngle(_target->GetRootBody()->Getb2Body()->GetAngle());
        }
        else
            targetPos = _targetVec;

        //Update the view based on the target's current location.
        _view = rw->getView();                                               //i imagine the culprit must be one of these lines
        _view.setCenter(targetPos);
        _view.setRotation(_targetAngle);
        _view.setSize(rw->getSize().x, rw->getSize().y);
    }
 

Here's the code that actually handles zooming, which also appears in the Update() method. _zoomSteps is a number calculated elsewhere that tells the camera how many times it needs to zoom to get from where it started to where it needs to end up (basically makes a zoom happen over time instead of immediately).
if(isZooming)
    {
        if(_zoomSteps > 0)
        {
            std::cout << "zooming " << _zoomSteps << std::endl;
            _view.zoom(_zoomSpeed);
            _zoomSteps--;
        }
        else
        {
            std::cout << "zoom completed" << std::endl;
            _currentZoom = _view.getViewport();
            isZooming = false;
        }
    }
 

Any help would be greatly appreciated.  Thanks so much!
« Last Edit: November 29, 2012, 06:51:26 pm by gws923 »

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: sf::View keeps resetting its zoom factor.
« Reply #1 on: November 29, 2012, 06:50:06 pm »
Ok, well I just figured it out.  I suppose typing out my problem helped me greatly.  Ug.  Glad it's over, anyway.

The problem was this line:
_view.setSize(rw->getSize().x, rw->getSize().y);

It should have jumped out to me way sooner, but I need to keep track of the "current zoom factor" and set the view's size accordingly.  I changed the line to this:
_view.setSize(rw->getSize().x * _zoomFactor, rw->getSize().y * _zoomFactor);

 

anything