# GLFW mouselook under OSX

I'm continuing to port an OpenGL app from Visual Studio 2012 to XCode 5.

The only major issue I'm having is mouselook. It "doesn't work" under OSX (Mavericks).

Here's the (pseudocode):

Pre-update, executed at the start of the frame:

void Dispatcher::PreUpdate(GameTime &time)
{
m_currentKeyboardState = m_nextKeyboardState;
m_previousMousePosition = m_currentMousePosition;

GetMousePosition(m_currentMousePosition);
}


Post-update, executed, well, after input processing, at the end of the frame:

void Dispatcher::PostUpdate(GameTime &time)
{
m_previousKeyboardState = m_currentKeyboardState;

if (m_captureMouse)
RecenterMouse();
}


Method to recenter the mouse:

void Dispatcher::RecenterMouse()
{
glfwSetCursorPos(m_window, m_windowSize.x / 2.f, m_windowSize.y / 2.f);

GetMousePosition(m_currentMousePosition);

if (m_previousMousePosition != m_currentMousePosition)
cout << "Mouse: " << m_currentMousePosition.x << "," << m_currentMousePosition.y << endl;

m_previousMousePosition = m_currentMousePosition;
}


And, jut for completeness:

void Dispatcher::GetMouseMotion(Vector2 &movedBy)
{
if(m_captureMouse)
{
movedBy.x = (m_currentMousePosition.x - m_previousMousePosition.x);
movedBy.y = (m_currentMousePosition.y - m_previousMousePosition.y);
}
else
{
movedBy.x=movedBy.y=0;
}
}


If m_captureMouse is true, and m_previousMousePosition != m_currentMousePosition, the y delta is always 1, no matter how far I've moved the mouse. (Actually, using the trackpad, but should be indentical.)

This code works perfectly under Win7, but never returns anything other motion than (0,1) under OSX.

Suggestions? I've seen other questions regarding glfw and osx, but no solutions.

EDIT

It's worth noting if I turn off mouse capture (which basically does everything but recenter the mouse at the end of the frame), mouselook works correctly but, of course, the cursor is free to wander outside of the window, which doesn't really work for a first-person app.

• I've run into this problem before, and fixed it by changing setCursorInputMode from Hidden to Disabled. – Mokosha Aug 3 '14 at 20:28
• @Mokosha perfect! Thanks. If you change this to an answer, I'll accept. (I haven't found anything that was really a duplicate.) I wonder why this is different between OSX and Windows. – 3Dave Aug 3 '14 at 20:48

This is usually solved by changing glfwSetInputMode with GLFW_CURSOR from GLFW_CURSOR_HIDDEN to GLFW_CURSOR_DISABLED.
The behavior differences are due to the differences in OS APIs that GLFW uses and how they interact with the windowing system. In the documentation, it says that DISABLED should be used for 3D camera controls, and HIDDEN should be used when rendering a custom cursor.