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

Author Topic: What is SFML's recommended method for a mouse camera with 3D?  (Read 1075 times)

0 Members and 1 Guest are viewing this topic.

john01dav

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
What is SFML's recommended method for a mouse camera with 3D?
« on: November 15, 2017, 03:13:56 am »
Hello,

I recently came across SFML, and it seems like an awesome library, having things like built-in networking and a windowing API that isn't full of boilerplate. I have been using it to attempt to create an opengl-based 3D api that I can then use in my later projects, however, and I've run into one issue: mouse capturing. In this api I want to have the mouse be invisible and inside the window, such that the user can move the mouse to look around, as is common in many games such as most FPSes, Portal, and Minecraft. While looking on the Internet for a solution to this, I found this pull request and the advice to make the mouse invisible and move it to width/2, height/2 when it moves. Using just the pull request causes the mouse to stay within the window, but when it reaches the edge it stops moving thus making it impossible to tell where the user is moving the mouse. When I attempt to move it to setPosition every time sf::Event::MouseMoved is called, this produces extreme lag, with the application freezing for several seconds at a time if the mouse moves a lot in a short time frame (on Ubuntu Linux 17.10 x64). I managed to get something working where I only move the mouse if it gets near the edge of the but that seems very messy, and I am wondering if there is a better way.

Thank you.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: What is SFML's recommended method for a mouse camera with 3D?
« Reply #1 on: November 15, 2017, 06:33:19 am »
With high resolution mice, you can get a lot of MouseMoved events per frame. A simple solution is to reset the mouse position once per frame, not every time you get a MouseMoved event.
Laurent Gomila - SFML developer