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

Author Topic: SFML mouse input mode.  (Read 2504 times)

0 Members and 1 Guest are viewing this topic.

wookie

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML mouse input mode.
« on: November 18, 2016, 12:00:03 am »
Hey everyone.
I've used SFML to write some simple games, get my head around 2D graphics and basic game development techniques for a while now, but I wanted more than just 3D so I started learning OpenGL.
In this OpenGL tutorial there is a library called GLFW being used for cross-platform window managment, input and etc.
It's a great library, but since SFML can be used with OpenGL and i know SFML much better well I wanted to see how it does compared to GLFW.

I have everything up and running, but the thing that bothers is the mouse.
The problem arises when I'm constructing the view matrix.
In GLFW there is a function to lock the mouse inside the window, so that i can't leave the window, but I can still move the mouse freely inside the world, I don't "hit" (mouse doesn't get blocked) borders of the window.
But in SFML the mouse simply leaves the window, goes as far as it can go and just stops. It drives me crazy, because it doesn't allow me to rotate freely inside the world.

Think of an FPS game where you can rotate only as much, as your screen allows you :D.
So, what is the way around this? How to lock mouse inside "world" with SFML? I really liked SFML and I wanted to use it for some kind of GUI in the game or something like that.

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: SFML mouse input mode.
« Reply #1 on: November 18, 2016, 12:07:47 am »

wookie

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML mouse input mode.
« Reply #2 on: November 18, 2016, 03:00:16 pm »
sf::Window::setMouseCursorGrabbed

It's not what I was looking for. I'm now limited by the size of game-window, I'm still not able to rotate 360 degrees, the mouse hits the window border and stops. Base case scanario I need an offset from previous mouse location, but the mouse is being blocked by window dimensions.

fallahn

  • Sr. Member
  • ****
  • Posts: 499
  • Buns.
    • View Profile
    • Trederia
Re: SFML mouse input mode.
« Reply #3 on: November 18, 2016, 03:26:29 pm »
In the past I've done something like:

init()
{
    setMousePos(screenCentre);
}

onMouseEvent()
{
    movement = mousePos - screenCentre;
    doStuff(movement);
    setMousePos(screenCentre);
}

 

basically you manually set the mouse to the centre of the screen each time you get a mouse move event, after having measured the distance between the mouse and the centre of the screen.

wookie

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML mouse input mode.
« Reply #4 on: November 18, 2016, 03:44:53 pm »
I had to adjust my Camera code a bit but other that it's perfect, extacly what I was looking for.
Thank you so much. [SOLVED]
« Last Edit: November 18, 2016, 03:52:51 pm by wookie »