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

Author Topic: Rotate using mouse without constraint of the window  (Read 1440 times)

0 Members and 1 Guest are viewing this topic.

imbetter911

  • Newbie
  • *
  • Posts: 5
    • View Profile
Rotate using mouse without constraint of the window
« on: April 21, 2012, 09:08:23 pm »
I have a program where the camera rotates around an origin and that part works fine. My problem is that whenever I move the mouse off the screen, It stops rotating and loses the mouse handle. Then moving the mouse back into the window, whether clicked or not, causes SFML to believe that it is clicked. I would like to know if there is any way to reset the mouse position or some form of mouse grabbing where it won't move the mouse around the window, but merely detect the difference in movement between frames and reset the pointer location.

Schizm

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Rotate using mouse without constraint of the window
« Reply #1 on: April 24, 2012, 12:40:07 am »
You need four variables: delta_x, delta_y, last_x and last_y;
The first two will contain mouse cursor position relative to last frame drawn, the last are used to store previous pointer position.

1. Set delta_x, delta_y to zero.
2. Receive mouse event.
3. delta_x = last_x-event.MouseMove.X; delta_y = last_y-event.MouseMove.Y;
4. last_x += delta_x; last_y += delta_y;
5. Process received values (delta_x and delta_y).
6. Use sf::Window::SetCursorPosition(window_center_x, window_center_y) to set cursor position to window's center.
7. Repeat from step 1.

The method described above is fairly simple and is used by most 3-D games, especially FPS ones.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10924
    • View Profile
    • development blog
    • Email
Re: Rotate using mouse without constraint of the window
« Reply #2 on: April 24, 2012, 01:00:36 am »
And I'd suggest to use SFML 2, which won't (or at least shouldn't) have any of the mouse problems.
Also since it's a RC it will soon the released and the old 1.6 will kind of be deapreciated...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything