The book I’m reading uses DirectInput to return the difference in movements on the mouse. Having read the forums on here I’ve tried to use windows functions for my mouse input.
I've got a cube in the centre of the screen, i want the camera to rotate around the block as i move the mouse left and right. I've for this working using the following method.
POINT cursorPos;
GetCursorPos(&cursorPos);
ScreenToClient( m_hWnd, &cursorPos );
m_pInput->UpdateMouseInfo( cursorPos );
m_cameraHeight += m_pInput->MouseDY()*fDelta;
m_cameraRotationY += m_pInput->MouseDX()*fDelta;
//InputHandler.cpp
void CInputHandler::UpdateMouseInfo(POINT currentPos)
{
//Check for first time
if( m_lastMousePt.x == -1.0f && m_lastMousePt.y == -1.0f )
{
m_lastMousePt.x = currentPos.x;
m_lastMousePt.y = currentPos.y;
m_mouseDiff.x = 0.0f;
m_mouseDiff.y = 0.0f;
}
else
{
m_mouseDiff.x = m_lastMousePt.x - currentPos.x;
m_mouseDiff.y = m_lastMousePt.y - currentPos.y;
m_lastMousePt.x = currentPos.x;
} m_lastMousePt.y = currentPos.y;
}
Now i haven’t use the WM_MOUSEMOVE message as i want to return the movement difference between this frame and last. If i used the message then i make a big movement and suddenly stop. The difference is maintained even though my mouse has stopped moving.
So the above works fine, except that when i reach the edge of the screen, the movement is no longer there so stops the camera. I have tried moving the cursor back to the middle of the screen with
SetCursorPos()
but this change is detected by the input handler also (because i'm storing previous values) and results in a slow jerky movement. I'm sure my logic is flawed somewhere but i can't work it out. Any help appreciated.