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

Author Topic: Apparent conflict between View and Mouse  (Read 1793 times)

0 Members and 1 Guest are viewing this topic.

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Apparent conflict between View and Mouse
« 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!

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: Apparent conflict between View and Mouse
« Reply #1 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!

Haikarainen

  • Guest
Re: Apparent conflict between View and Mouse
« Reply #2 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

Another hint would be convertCoords

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10832
    • View Profile
    • development blog
    • Email
Re: Apparent conflict between View and Mouse
« Reply #3 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.  ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/