Jump to content
  • Advertisement
Sign in to follow this  
VISQI

FPS Mouse movement problem

This topic is 2830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey guys
I am trying to track the changes of mouse movement to apply it to the Yaw and the Pitch. I think i've got the theory good, but my implementation is bad.
here is why i do:
- In the Window Procedure, set the cursor position to be in the middle through GetClientRect()
- In WM_MOUSEMOVE, i check the X and Y position through LOWORD and HIWORD, respectively
- Subtract the Offset from the center and apply those to the Yaw and the Pitch
- Return the cursor to the center of the program

Apparently my program is eating up CPU usage and not getting much rendered at all(this started happening after i tried to use the above implementation)
So...Where did i got wrong??

P.S:Here is the Window procedure if you want to take a look(I commented out the irrelevant code)


LRESULT CALLBACK MsgProc(HWND hwnd, UINT Msg, WPARAM wparam, LPARAM lparam)
{
RECT r;
GetClientRect(hwnd, &r);
int x = r.right / 2;
int y = r.bottom / 2;
SetCursorPos(x, y);

int OffsetX;
int OffsetY;
POINT Center;

switch(Msg)
{
/* case WM_KEYDOWN:
switch(wparam)
{
case 0x57://W
gKeys[0] = true;
break;
case 0x41://A
gKeys[1] = true;
break;
case 0x53://S
gKeys[2] = true;
break;
case 0x44://D
gKeys[3] = true;
break;
case VK_ESCAPE:
OutputDebugString("ESCAPE!!");
App::KillMe();
break;

case VK_LEFT:
gKeys[4] = true;
OutputDebugString("Left\n");
break;
case VK_RIGHT:
gKeys[5] = true;
OutputDebugString("Right\n");
break;
case VK_UP:
gKeys[6] = true;
OutputDebugString("Up\n");
break;
case VK_DOWN:
gKeys[7] = true;
OutputDebugString("Down\n");
break;
}
break;

case WM_KEYUP:
switch(wparam)
{
case 0x57://W
gKeys[0] = false;
break;
case 0x41://A
gKeys[1] = false;
break;
case 0x53://S
gKeys[2] = false;
break;
case 0x44://D
gKeys[3] = false;
break;

case VK_LEFT:
gKeys[4] = false;
break;
case VK_RIGHT:
gKeys[5] = false;
break;
case VK_UP:
gKeys[6] = false;
break;
case VK_DOWN:
gKeys[7] = false;
break;
}
break;*/

case WM_MOUSEMOVE:
OffsetX = GET_X_LPARAM(lparam);
OffsetY = GET_Y_LPARAM(lparam);
GetCursorPos(&Center);

gCamera->Yaw() = (float)(Center.x - OffsetX) / 100.0f;
gCamera->Pitch() = (float)(Center.y - OffsetY) / 100.0f;
SetCursorPos(x, y);
break;

/* case WM_DESTROY:
PostQuitMessage(0);
return 0;*/
}

return DefWindowProc(hwnd, Msg, wparam, lparam);
}

Share this post


Link to post
Share on other sites
Advertisement
You ought to try running this in your debugger. I believe SetCursorPos fires a WM_MOUSEMOVE event, so you're getting an infinite loop of events there.

Share this post


Link to post
Share on other sites
so what can i do??
i need to reset the cursor each frame, should i put SetCursorPos in the Update function rather than in the Win32 loop

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!