PDA

View Full Version : Reading mouse input


Macinkross
2004.01.25, 06:32 PM
Hey,

I've got a problem. I'm currently working on a shooter where the mouse needs to be polled constantly for mouselook. My current solution is to use CGGetLastMouseDelta() to record any mouse movement once per run of the main loop. However I've got a little problem. The mouse movement won't be registered if the mouse is moved slowly. I've also tried using the glutPassiveMotionFunc() and have the same problem. When the mouse is moved faster the movement is registered fine.

Anyone know a better way to grab mouse input, or what could possibly be wrong.

Thanks.

wadesworld
2004.01.25, 07:07 PM
What's wrong with using Carbon events and registering to receive mouse-moved events?

Wade

Fenris
2004.01.26, 06:54 AM
There is a call that will mend this. It's about mouse coercion - the system clumps many small mouse deltas into one, but you don't want that for a game. I can't remember the call right now, but search developer.apple.com for mouse coercion. I'll check when I get home.

Frank C.
2004.01.26, 11:44 AM
There is a call that will mend this. It's about mouse coercion...
I think you mean coalescing (as in SetMouseCoalescingEnabled). I've found it's best to just leave that alone (on). You really don't need every event, just the delta since the last frame, which can be read with CGGetLastMouseDelta, but Apple recommends using carbon events instead, i.e. GetEventParameter with kEventParamMouseDelta.

With coalescing off, you'll just end up adding all those mini-deltas yourself, to get the delta since the last frame, so you might as well have the system do some of that work for you.

What a lot of people fail to do, is turn off the system mouse scaling - this can result in horrid control in games (especially FPS) - Omni group has had code for this up for a long while: http://www.omnigroup.com/developer/gamedevelopment/gdc2001/

A lot of people also seem to miss the CGAssociateMouseAndMouseCursorPosition function, and end up re-centering the cursor manually every frame.

Fenris
2004.01.27, 07:40 PM
Hrm, yes. Coalescion. *Goes to hide*