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

Author Topic: How to get Mouse-Position  (Read 11596 times)

0 Members and 1 Guest are viewing this topic.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
How to get Mouse-Position
« on: October 10, 2008, 07:13:25 pm »
Hi  i just wanted to know where the MousePosition is saved

was it event.mousemove.x and y?

are they realtive to display or absolute coords?

hmm how can i convert coord from mousposition to absolute position?

zac

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
How to get Mouse-Position
« Reply #1 on: October 10, 2008, 07:28:44 pm »
Can't you retrieve the position of your window?
Than simply add it, I'd suppose...

Hm... doesn't look like...
Why can you set the position via "SetPosition" but not get it?
Somehow, that doesn't make sense...
There should be ways to retrieve window positions on all platforms...

Maybe you can implement it specific to the platform your project has to run on or just seek another possibility...

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
How to get Mouse-Position
« Reply #2 on: October 10, 2008, 07:39:40 pm »
sorry , i meant

i want to get the mouseposition as floats or vector2f;
and i could need it as absolute position
i tried it out, mouse-position from event.mousemove is relative to the screen

Mouse.GetPosition()   -> how do u call this function?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to get Mouse-Position
« Reply #3 on: October 10, 2008, 07:45:51 pm »
Why do you want to do that ? SFML doesn't manage / know what happens out of the window, and so do the mouse coordinates. What happens there is OS-specific and it's up to you to implement it. I really can't see why you would need that.
Laurent Gomila - SFML developer

zac

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
How to get Mouse-Position
« Reply #4 on: October 10, 2008, 07:49:57 pm »
If you simply want to retrieve the mouse pointer for a given window, you should use the sf::Input-class.

Code: [Select]

//Given an instance of sf::RenderWindow (hereafter called app)
const Input& i = app.GetInput();
Vector2i mousePositionRelative(i.GetMouseX(),i.GetMouseY());
//Fills a Vector2i (2 integer values) with the mouse position which is returned as int

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
How to get Mouse-Position
« Reply #5 on: October 10, 2008, 07:50:06 pm »
hmm, i have a sprite taht can be moved via

_W_
ASD

then i have a view, its center is the sprite-position, so that my main char is always viewn;

so my sprites position can be more than window-width
i want the sprite to rotate when mouse is moved,

to get the vector Mouse-Pos -> SpritePos i would need absolute coords

or i need my sprites position as rtelative coords

at moment i casnnot try out , but is the piece of code missing?
Code: [Select]

sf::Vector2f MousePos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to get Mouse-Position
« Reply #6 on: October 10, 2008, 08:31:59 pm »
Ah, sorry I thought you were talking about absolute coordinates and not view coordinates.

Your piece of code should do the job ;)
Laurent Gomila - SFML developer

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
How to get Mouse-Position
« Reply #7 on: October 10, 2008, 08:35:37 pm »
oh what do i have to understand as absolute coords?
coords of windoes-desktop?

is there any difference between them and Event.MouseMove.X / Y when i have a fullscreenwindow?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to get Mouse-Position
« Reply #8 on: October 10, 2008, 08:38:47 pm »
Quote
oh what do i have to understand as absolute coords?
coords of windoes-desktop?

Yes (at least that's what I had in mind).

Quote
is there any difference between them and Event.MouseMove.X / Y when i have a fullscreenwindow?

No, but I didn't notice you were running in fullscreen mode ;)
Laurent Gomila - SFML developer