bool mouseFlag = true;
//Continue to the WinProc function...
case WM_MOUSEMOVE:
{
if(mouseFlag)
{
cursorX = LOWORD(lParam);//Get the current X, Y mouse coord
cursorY = HIWORD(lParam);
cursorAX = (cursorX - cursorPX) / 2;//Calculate how far the mouse moved
cursorAY = (cursorY - cursorPY) / 2;
test->xRot += cursorAY;//Move the user's camera
test->yRot -= cursorAX;
test->zDir = test->yRot;
if(test->xRot >= 90)//Keep the user from bending backwards and looking through his legs
test->xRot = 90;
if(test->xRot <= -90)
test->xRot = -90;
cursorPX = cursorX;
cursorPY = cursorY;
}
break;
}
Okay, this section of code controls how the user looks around with the mouse. It works fine but there's a problem: if the mouse goes outside the window, the person stops looking.
So my solution to this problem is to put the mouse in the center of the window each time the program gets to the end of the loop. So I added this section of code at the end of the rendering loop:
mouseFlag = false;
SetCursorPos(320, 240);
mouseFlag = true;
But this only keeps you from looking around.
Does anyone see the problem with my code?