SFML community forums

Help => Graphics => Topic started by: gws923 on June 12, 2012, 09:07:40 pm

Title: Apparent conflict between View and Mouse
Post by: gws923 on June 12, 2012, 09:07:40 pm
Hello all.  I'm currently working on a program that's sort of like a drag-and-drop level editor.  I'd like to be able to move the view around using WASD (which I have working), but I also have events that place objects in relation to the mouse's current position.

When I move the view at runtime, Mouse::getPosition() doesn't update to account for the fact that the view has moved.  In other words, if I move the view 3 steps to the left and then drop an object, it drops it 3 steps to the right of where my mouse is.

I'm not sure that posting any particular code will help, as it seems more of a logical problem than a coding conflict, but here is the code for both operations:
if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && keyDown == false)
            {
                mousePosition = sf::Mouse::getPosition(*App);

                if(!pointManager->IsPoint(*App) && pointManager->GetNumLoopPoints()%2 != 0)
                {
                    pointManager->AddPoint(new Point(mousePosition.x, mousePosition.y, "edge"));
                }
                keyDown = true;
            }

and this:
 if (Event.type == sf::Event::KeyPressed)
            {
                switch(Event.key.code)
                {
                    //move the camera with WASD
                    case sf::Keyboard::W:
                        view.move(0, -4);
                        App->setView(view);
                        break;
                    case sf::Keyboard::S:
                        view.move(0, 4);
                        App->setView(view);
                        break;

Any insights would be very much appreciated!
Title: Re: Apparent conflict between View and Mouse
Post by: gws923 on June 12, 2012, 09:39:11 pm
I have realized there is an easy answer for this.  I simply must keep track of the changes in an int or something and factor that in to my point clicks.  Sorry for the stupid question!
Title: Re: Apparent conflict between View and Mouse
Post by: Haikarainen on June 15, 2012, 03:49:22 pm
I have realized there is an easy answer for this.  I simply must keep track of the changes in an int or something and factor that in to my point clicks.  Sorry for the stupid question!

Look at the arguments getPosition takes.

Hint :
static Vector2i sf::Mouse::getPosition   (   const Window &    relativeTo   )
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Mouse.php#a93b4d2ebef728e77a0ec9d83c1e0b0c8 (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Mouse.php#a93b4d2ebef728e77a0ec9d83c1e0b0c8)

Another hint would be convertCoords
Title: Re: Apparent conflict between View and Mouse
Post by: eXpl0it3r on June 16, 2012, 01:15:19 am
Not sure if I got your problem right but did you zoom on the view (or defined it the wrong way and it gets displayed too big)?
Because then you'd need to factor in that zoom factor in the move function.  ;)