ThoSt
September 20th, 2005, 08:26 PM
hi,
I am writing a little DX9 app, and I am moving and rotate the camera by either mouse movement or key presses.
both methods work fine by themselves. However, if I try to move with the keys and rotate with the mouse at the same time, I get incorrect lParam values in the WM_MOUSEMOVE messagehandler.
here is the code for the keyboard messages:
case WM_KEYDOWN:
switch (wParam)
{
case 87: // W
cam.MoveForward(MOVE);
break;
case 65: // A
cam.MoveRight(-MOVE);
break;
case 83: // S
cam.MoveForward(-MOVE);
break;
case 68: // D
cam.MoveRight(MOVE);
break;
case 73: // I
cam.RotateDown(-ROT);
break;
case 74: // J
cam.RotateRight(-ROT);
break;
case 75: // K
cam.RotateDown(ROT);
break;
case 76: // L
cam.RotateRight(ROT);
break;
case 27:
Cleanup();
PostQuitMessage( 0 );
return 0;
default:
break;
}
here is the code for the mouse movement:
case WM_MOUSEMOVE:
if (MouseLDown == TRUE)
{
if (MouseRDown == FALSE)
{
p = MAKEPOINTS(lParam);
if (MouseMoved == FALSE)
{
MouseMoved = TRUE;
mouseYPos = p.y;
mouseXPos = p.x;
}
else
{
MouseMoved = FALSE;
cam.MoveForward((p.y - mouseYPos)*10);
cam.RotateRight((p.x - mouseXPos)/100);
}
}
else
{
p = MAKEPOINTS(lParam);
if (MouseMoved == FALSE)
{
MouseMoved = TRUE;
mouseYPos = p.y;
mouseXPos = p.x;
}
else
{
MouseMoved = FALSE;
cam.MoveUp((p.y - mouseYPos)*10);
cam.MoveRight((p.x - mouseXPos)*10);
}
}
}
else if (MouseRDown == TRUE)
{
p = MAKEPOINTS(lParam);
if (MouseMoved == FALSE)
{
MouseMoved = TRUE;
mouseYPos = p.y;
mouseXPos = p.x;
}
else
{
MouseMoved = FALSE;
cam.RotateDown((p.y - mouseYPos)/100);
cam.Roll((p.x - mouseXPos)/100);
}
}
break;
case WM_LBUTTONDOWN:
if (MouseLDown != TRUE)
MouseMoved = FALSE;
MouseLDown = TRUE;
SetCapture(hWnd);
break;
case WM_LBUTTONUP:
MouseMoved = FALSE;
MouseLDown = FALSE;
ReleaseCapture();
break;
case WM_RBUTTONDOWN:
if (MouseRDown != TRUE)
MouseMoved = FALSE;
MouseRDown = TRUE;
SetCapture(hWnd);
break;
case WM_RBUTTONUP:
MouseMoved = FALSE;
MouseRDown = FALSE;
ReleaseCapture();
break;
}
now if I press a key and move the mouse, my p.y coordinate is in the high 16.000's, no matter where the mouse actually is.
this causes the camera to wildly swing about.
what can I do to avoid this problem, and what is the cause of this? I do not exactly understand how windows handles the simultaneous press of a key (and keeping it pressed), while the mouse is moving.
any advice would be greatly appreciated.
I am writing a little DX9 app, and I am moving and rotate the camera by either mouse movement or key presses.
both methods work fine by themselves. However, if I try to move with the keys and rotate with the mouse at the same time, I get incorrect lParam values in the WM_MOUSEMOVE messagehandler.
here is the code for the keyboard messages:
case WM_KEYDOWN:
switch (wParam)
{
case 87: // W
cam.MoveForward(MOVE);
break;
case 65: // A
cam.MoveRight(-MOVE);
break;
case 83: // S
cam.MoveForward(-MOVE);
break;
case 68: // D
cam.MoveRight(MOVE);
break;
case 73: // I
cam.RotateDown(-ROT);
break;
case 74: // J
cam.RotateRight(-ROT);
break;
case 75: // K
cam.RotateDown(ROT);
break;
case 76: // L
cam.RotateRight(ROT);
break;
case 27:
Cleanup();
PostQuitMessage( 0 );
return 0;
default:
break;
}
here is the code for the mouse movement:
case WM_MOUSEMOVE:
if (MouseLDown == TRUE)
{
if (MouseRDown == FALSE)
{
p = MAKEPOINTS(lParam);
if (MouseMoved == FALSE)
{
MouseMoved = TRUE;
mouseYPos = p.y;
mouseXPos = p.x;
}
else
{
MouseMoved = FALSE;
cam.MoveForward((p.y - mouseYPos)*10);
cam.RotateRight((p.x - mouseXPos)/100);
}
}
else
{
p = MAKEPOINTS(lParam);
if (MouseMoved == FALSE)
{
MouseMoved = TRUE;
mouseYPos = p.y;
mouseXPos = p.x;
}
else
{
MouseMoved = FALSE;
cam.MoveUp((p.y - mouseYPos)*10);
cam.MoveRight((p.x - mouseXPos)*10);
}
}
}
else if (MouseRDown == TRUE)
{
p = MAKEPOINTS(lParam);
if (MouseMoved == FALSE)
{
MouseMoved = TRUE;
mouseYPos = p.y;
mouseXPos = p.x;
}
else
{
MouseMoved = FALSE;
cam.RotateDown((p.y - mouseYPos)/100);
cam.Roll((p.x - mouseXPos)/100);
}
}
break;
case WM_LBUTTONDOWN:
if (MouseLDown != TRUE)
MouseMoved = FALSE;
MouseLDown = TRUE;
SetCapture(hWnd);
break;
case WM_LBUTTONUP:
MouseMoved = FALSE;
MouseLDown = FALSE;
ReleaseCapture();
break;
case WM_RBUTTONDOWN:
if (MouseRDown != TRUE)
MouseMoved = FALSE;
MouseRDown = TRUE;
SetCapture(hWnd);
break;
case WM_RBUTTONUP:
MouseMoved = FALSE;
MouseRDown = FALSE;
ReleaseCapture();
break;
}
now if I press a key and move the mouse, my p.y coordinate is in the high 16.000's, no matter where the mouse actually is.
this causes the camera to wildly swing about.
what can I do to avoid this problem, and what is the cause of this? I do not exactly understand how windows handles the simultaneous press of a key (and keeping it pressed), while the mouse is moving.
any advice would be greatly appreciated.