Original Post
EDIT: sorry, the title was a bit misleading, so i changed it
I'm writing a camera class, and have it all working, except for one issue. When i'm strafing or walking everything is ok, and using mouselook is ok too. But if i say walk and mouselook for a while, and let go of the arrow (or W) key, the camera keeps moving for a while (same for strafe etc), and mouselook still works at this stage.
I set a breakpoint on WM_KEYUP and that breaks a while after releasing the key. I'm guessing the camera rotation code is blocking things up, but can it really block the message loop?
I'm running on a slow machine, but i've looked at some stuff from game tutorials, and the message handling there is pretty much the same, and that code doesn't suffer from "stuck keys" like mine.
i've pasted how i handle keys etc below in the main loop
while(1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT) // If the message wasnt to quit
break;
TranslateMessage(&msg); // Find out what the message does
DispatchMessage(&msg); // Execute the message
}
key_handler ();
player_cam.set_view_by_mouse ();
glLoadIdentity();
gluLookAt (player_cam.m_position.m_x, player_cam.m_position.m_y, player_cam.m_position.m_z,
player_cam.m_forward.m_x, player_cam.m_forward.m_y, player_cam.m_forward.m_z,
player_cam.m_up.m_x, player_cam.m_up.m_y, player_cam.m_up.m_z);
//Do rendering here....
render_scene ();
}
key_handler looks like this:
if( (GetKeyState(VK_UP) & 0x80) || (GetKeyState('W') & 0x80) )
{
player_cam.move (0.1f);
}
if( (GetKeyState(VK_DOWN) & 0x80) || (GetKeyState('S') & 0x80) )
{
player_cam.move (-0.1f);
}
if( (GetKeyState(VK_LEFT) & 0x80) || (GetKeyState('A') & 0x80) )
{
player_cam.strafe (-0.1f);
}
if( (GetKeyState(VK_RIGHT) & 0x80) || (GetKeyState('D') & 0x80) )
{
player_cam.strafe (0.1f);
}
and my winProc looks like this
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(first_window.get_hwnd() != NULL)
{
//Plugin the window message handler
return (first_window.message_handler (uMsg, wParam, lParam));
}
else
{
first_window.set_hwnd(hWnd);
return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}
}
where first_window is a class that creates the window and sets up the OpenGL stuff... and has this message handler
LONG lRet = 0;
PAINTSTRUCT ps;
switch (uMsg)
{
case WM_SIZE: // If the window is resized
if(!m_fullscreen) // Do this is we are not in full screen
{
m_width = LOWORD(lParam);
m_height = HIWORD(lParam);
size_openGL_screen();// LoWord=Width, HiWord=Height
GetClientRect(m_hwnd, &m_rect); // Get the window rectangle
}
break;
case WM_PAINT: // If we need to repaint the scene
BeginPaint(m_hwnd, &ps); // Init the paint struct
EndPaint(m_hwnd, &ps); // EndPaint, Clean up
break;
case WM_DISPLAYCHANGE:
break;
switch (wParam)
{
case VK_ESCAPE: // If we hit the escape key
PostQuitMessage(0); // Send a QUIT message to the window
break;
case VK_F1:
set_fullscreen (!m_fullscreen);
break;
}
break;
case WM_CLOSE: // If the window is being closes
PostQuitMessage(0); // Send a QUIT Message to the window
break;
default: // Return by default
lRet = DefWindowProc (m_hwnd, uMsg, wParam, lParam);
break;
}
return lRet;
any help appreciated..
Thanks in advance
[edited by - jhavna on July 23, 2003 10:11:20 AM]
[edited by - jhavna on July 23, 2003 10:11:55 AM]
[edited by - jhavna on July 23, 2003 10:13:22 AM]
[edited by - jhavna on July 23, 2003 11:37:31 AM]