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

Author Topic: wrong mouse coordinates and yes i did search in google  (Read 3449 times)

0 Members and 1 Guest are viewing this topic.

Fantasy

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
wrong mouse coordinates and yes i did search in google
« on: January 29, 2012, 06:40:24 pm »
Hello guys
First of all I did go and search before i post this topic and i found a lot of posts about this topic but my problem is a bit wired.

My window is 800, 600 and when i print the mouse coordinates i get x from -500 to 1300 and Y from -200 to 800.

how can i make the lowest value for x 0 and biggest 800 and for y 0 and 600?

Code: [Select]
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>

#include <string>
#include <iostream>

#pragma comment(lib, "sfml-window-d.lib")  
#pragma comment(lib, "sfml-graphics-d.lib")  
#pragma comment(lib, "sfml-system-d.lib")  

int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "HI");

while(Window.IsOpen())
{

std::cout<<sf::Mouse::GetPosition(Window).x << " ";
std::cout<<sf::Mouse::GetPosition(Window).y << "\n";

Window.Clear();
Window.Display();
}
return 0;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
wrong mouse coordinates and yes i did search in google
« Reply #1 on: January 29, 2012, 06:50:39 pm »
Is (-500, -200) the top-left corner of your window, or the top-left corner of your screen?
Laurent Gomila - SFML developer

Fantasy

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
wrong mouse coordinates and yes i did search in google
« Reply #2 on: January 29, 2012, 06:55:47 pm »
Quote from: "Laurent"
Is (-500, -200) the top-left corner of your window, or the top-left corner of your screen?


top-left corner of my screen.

my screen is 1080, 1920. before when i just do this

Code: [Select]

std::cout<<sf::Mouse::GetPosition().x << " ";
std::cout<<sf::Mouse::GetPosition().y << "\n";


i was getting 0, 0 top corner of my screen and 1920, 1080 bottom right corner of my screen.

after i did this
Code: [Select]

std::cout<<sf::Mouse::GetPosition(Window).x << " ";
std::cout<<sf::Mouse::GetPosition(Window).y << "\n";


i get -500, -270 top corrner of my screen and 1300, 800 bottom right corner of my screen.

My window size is 800, 600. and screen size is 1920, 1080.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
wrong mouse coordinates and yes i did search in google
« Reply #3 on: January 29, 2012, 07:09:40 pm »
So what's wrong? You get coordinates relative to your window, everything's ok.
Laurent Gomila - SFML developer

Fantasy

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
wrong mouse coordinates and yes i did search in google
« Reply #4 on: January 29, 2012, 07:22:22 pm »
Quote from: "Laurent"
So what's wrong? You get coordinates relative to your window, everything's ok.


in sfml 1.6 when i move the mouse to the top left corner of my window i get 0, 0. Even if i move my mouse out of the window i still get 0,0.
However in sfml 2.0 when i move my mouse to the top left corner of my window i get 0,0 BUT when i keep moving the mouse to the top corner of my screen i get -500, -270. It should stop at 0, 0.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
wrong mouse coordinates and yes i did search in google
« Reply #5 on: January 29, 2012, 07:39:48 pm »
Quote
It should stop at 0, 0.

Why? The mouse is not at (0, 0) when it's in the corner of the screen. The new behaviour is more consistent.

If you don't want negative coordinates, just clamp them.

And please remove your image:
- it is too large, it forces to scroll to reach the forum buttons
- it is too heavy, it takes many seconds to display
Laurent Gomila - SFML developer

Fantasy

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
wrong mouse coordinates and yes i did search in google
« Reply #6 on: January 29, 2012, 07:44:02 pm »
Quote from: "Laurent"
Quote
It should stop at 0, 0.

Why? The mouse is not at (0, 0) when it's in the corner of the screen. The new behaviour is more consistent.

If you don't want negative coordinates, just clamp them.

And please remove your image:
- it is too large, it forces to scroll to reach the forum buttons
- it is too heavy, it takes many seconds to display


sorry about the images.
ok but how do i keep the mouse coordinates between 0,0 and 800,600 which is the window size?

how do i clamp them?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
wrong mouse coordinates and yes i did search in google
« Reply #7 on: January 29, 2012, 07:45:09 pm »
Code: [Select]
if (position.x < 0)
    position.x = 0;
etc.
Laurent Gomila - SFML developer

Fantasy

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
wrong mouse coordinates and yes i did search in google
« Reply #8 on: January 29, 2012, 07:54:53 pm »
Quote from: "Laurent"
Code: [Select]
if (position.x < 0)
    position.x = 0;
etc.


thanks that was helpful.

 

anything