Original Post
case WM_MOUSEMOVE:
SetCapture(hWnd);
//This will keep the mouse captured to the window...
//...preventing an error where the user will stop aiming.
int cursorAX = (LOWORD(lParam) - cursorPX) / 2;//Calculate how far the mouse moved.
int cursorAY = (HIWORD(lParam) - cursorPY) / 2;
cursorPX = LOWORD(lParam);//Update the previous mouse location to the current one.
cursorPY = HIWORD(lParam);
if(LOWORD(lParam) < 100 || LOWORD(lParam) > 540)//If the mouse moves dangerously
{ //close to the edge of the window.
SetCursorPos(320, HIWORD(lParam)); //Re-position the cursor to the center of the window.
cursorPX = 320; //Make the previous mouse location the current one
} //so the user won't look back when the mouse is re-centered.
if(HIWORD(lParam) < 100 || HIWORD(lParam) > 380)
{
SetCursorPos(LOWORD(lParam), 240);
cursorPY = 240;
}
userDir += cursorAX;//Rotate the user's direction
lookUpDown += cursorAY;//<-----------------------
if(lookUpDown > 90)//Prevent the user from looking past 90 degrees
lookUpDown = 90;
if(lookUpDown < -90)
lookUpDown = -90;
if(userDir > 259)//Keep the degree range in the proper 0 - 360 range.
userDir -= 360;
if(userDir < 0)
userDir += 360;
glLoadIdentity();
glRotatef(lookUpDown, 1, 0, 0);
glRotatef(userDir, 0, 1, 0);
//Draw area around user