Jump to content

  • Log In with Google      Sign In   
  • Create Account

Best way to do mouselook?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 george7378   Members   -  Reputation: 1197

Like
0Likes
Like

Posted 03 March 2013 - 07:49 AM

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!



Sponsor:

#2 GuardianX   Crossbones+   -  Reputation: 1498

Like
1Likes
Like

Posted 03 March 2013 - 11:58 AM

You can use DirectInput to get relative mouse coordinates. Here is a good guide for this system http://www.rastertek.com/dx11tut13.html

#3 george7378   Members   -  Reputation: 1197

Like
0Likes
Like

Posted 03 March 2013 - 12:14 PM

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!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS