Sign in to follow this  
george7378

Best way to do mouselook?

Recommended Posts

george7378    1441

Hi everyone,

 

I've tried to use the following code for allowing my mouse to move the camera look direction:

 

case WM_MOUSEMOVE: //Mouse movement for camera
GetCursorPos(&currMousePos);
mouseDeltaX = currMousePos.x - lastMousePos.x; mouseDeltaY = currMousePos.y - lastMousePos.y; //Find how much the mouse has moved
lastMousePos = currMousePos;
SetCursorPos(GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2); //Reset the cursor to the window centre
break;

 

This doesn't seem to work though. I think the reason is that the function SetCursorPos() also causes a WM_MOUSEMOVE message to be sent, which means that the net movement each time is zero. What's the best way to make a simple mouselook function in C++? All I need at the moment is to determine how much the mouse has moved from its last position every time it moves. I think when I get that sorted, I will be able to take it from there!

 

Thanks!

Share this post


Link to post
Share on other sites
george7378    1441

Thanks for the help - I actually just got round this problem by applying the mouse motion coordinates to my camera just before the SetCursorPos() is called. It seems to work, and the mouselook effect is pretty decent!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this