Jump to content
  • Advertisement
Sign in to follow this  
ehmdjii

what to do with the mouse pointer in an FPS camera?

This topic is 4579 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

hi, you all know the camera mode in an first person shooter. now i am currently having problems what to do with the mousepointer. if i dont do anything at all, it happens that the pointer goes outside the window and movement will stop. if i fix the mousepointer somewhere inside my window, i cant look around, since the difference doesnt work anymore: every frame i do: lookamount = mousepposition - lastmousposition thanks

Share this post


Link to post
Share on other sites
Advertisement
After the User moves the mouse, measure the difference it moved. Then put it back in the center of the screen.
Keep a running total of the difference each time it moves, so you can know where it 'should be' even though the real cursor keeps getting recentered.

Share this post


Link to post
Share on other sites
The problem is that, when you move it back, you get another mousemove message, which negates the first mousemove. The solution is to keep a flag for whether you are recursing in your message loop or not.

Or you can use the RAWINPUT stuff, which gives you raw mouse mickeys. You still need to set the pointer back to the center of the window, but you don't need to worry about the recursion.

Something like this (didn't compile it, so watch out for typos):


...
case WM_MOUSEMOVE:
if (!recursionFlag) {
deltaX = MOUSE_X(wParam) - 400;
deltaY = MOUSE_Y(wParam) - 300;
recursionFlag = true;
POINT pt = { 400, 300 };
::ClientToScreen(hWnd, &pt);
::SetCursorPos(pt);
recursionFlag = false;
}
break;
...

Share this post


Link to post
Share on other sites
Hi,

I think you want to grab the mouse input - which restricts it to your game window. There are various ways of doing it depending on your platform and any utility libraries you are using.

E.g. SDL_WM_GrabInput
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fWM_5fGrabInput

I guess see MSDN or try Google if you are not using SDL.

Cheers,
dhm

Share this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
The problem is that, when you move it back, you get another mousemove message, which negates the first mousemove.


This is going to be API specicifc... but
you could always disable the mouse interrupts before doing the recenter and reenable them afterwards.

I believe my solution, was to check if the absolute position of the cursor was the center of the screen after a move, in which case I ignored it. This works because the user cannot ever move the mouse To the center, only away from it; since the cursor starts out there every update. Thus the only moves that get ignored Must be the recentering ones.

Share this post


Link to post
Share on other sites
thanks everyone!

hplus: "The problem is that, when you move it back, you get another mousemove message, which negates the first mousemove."
that is exactly my problem, which results in the camera jumping back to its original view every other frame.

hplus, your solution sound most reasonable, although it didnt work. maybe because i use java and i set the cursor via java.awt.Robot.mouseMove().

haphazardlynamed, your solution seems to work, but the movement is quite stuttery. it feels like the camera is shaking a little bit.

Share this post


Link to post
Share on other sites
Quote:
Original post by ehmdjii
haphazardlynamed, your solution seems to work, but the movement is quite stuttery. it feels like the camera is shaking a little bit.


Is this for the disable interrupts method?
or for the ignore center moves method?

I remember that the first method can sometimes stutter, depending on if/how interrupts are queued, whether they get flushed during the disable/enable process, and other Specific factors...

The second method, I dont recall ever having problems with though...
So if you're getting problems with this one I'm not too sure at the moment...
Make sure that you only do a Recenter Cursor move when absoultely necesarry; I made a mistake when first doing this and recentered on Both cases UserMove and IgnoreMove, thus I was overloading the event stack with mousemotions and the thing got slow and jerky...

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!