High resolutions and high mouse coordinates on OSX? (Or another solution?)

I would like to get mouse movements with high resolution and high frame rate on OSX.

"High frame rate" = 60 frames per second or higher (preferably> 120)
"High resolution" = sub-pixel values

Problem
I have an opengl view that runs at the monitor refresh rate, so it is ~ 60 frames per second. I use the mouse to look around, so I hid the mouse cursor and I rely on the delta values ​​of the mouse.

The problem is that mouse events occur at too low frame rates, and the values ​​are snapped to integers (whole pixels). This causes an intermittent scan. Here's a visualization of mouse delta values ​​over time:

    mouse delta X
    ^                xx
  2 |      x    x x     x xx
    | x x x   x             xx x  x x
  0 |x-x-x--xx-x-x-xx--x-x----x-xx-x-----> frame
    |
-2  |
    v

() , , . x deltaX , deltaX , . , deltaX 0,000 , 1.000 , 0.000, 2.000, 0.000 , 3.000, 0.000 ..

, 2.000 , 0,000 , 3.000 . , . , .

, 1) ? 2) ?


:

- (void)mouseMoved:(NSEvent *)theEvent {
    CGFloat dx, dy;
    dx = [theEvent deltaX];
    dy = [theEvent deltaY];
    // ...
    actOnMouse(dx,dy);
}

, . dx float, (0.000, 1.000 ..). .

, , WindowServer, . , CGEventTrap:

eventMask = (1 << kCGEventMouseMoved);
eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap,
            0, eventMask, myCGEventCallback, NULL);
//...
myCGEventCallback(...){
    double dx = CGEventGetDoubleValueField(event, kCGMouseEventDeltaX);
    double dy = CGEventGetDoubleValueField(event, kCGMouseEventDeltaY);
}

n.000, , . 60 . .

, . , OSX - -, - "" , , , - .

, , IOKit. . . Apple , , : " , , , ".

, . .

<IOKit/hidsystem/IOLLEvent.h> 377 :

struct {    /* For mouse-down and mouse-up events */
    UInt8   subx;       /* sub-pixel position for x */
    UInt8   suby;       /* sub-pixel position for y */
    // ...
} mouse;

, ! . 73 <IOKit/hidsystem/IOLLParameter.h>

#define kIOHIDPointerResolutionKey      "HIDPointerResolution"

.

, , OSX , , , .


Erh, , ?

  • OSX? ( ?)
  • OSX? ( ?)
  • "" ? (.. .)
  • , NXEvents HIDParameters? ? ( ...)

( )

+5
4

( , , , , - , .)

? , , , . , , . http://www.flipcode.com/archives/Smooth_Mouse_Filtering.shtml.

( ), :


. , , . - ? , , . , .

, .

, , . , X, X - " ", .

10 , . 1/6 60FPS. , . 2 , ( ).

. . , , . 1.0. , ( ) . " " (... 0,2) . ( ) , () .

, 0,5, 100% - , 50% - , 25% - , 12,5% . , . , , , .

. 0 , . 1.0 , .

: . 10, , .

+5

, Mac OS X . 2x2 , (x + 0.5, y + 0.5).

Mac, 1x, , - 1 .

+1

If you need to access the delta information of the pointer device at a lower level than the event dispatch system, then you probably need to use the user-USB interfaces of the USB space .

+1
source

If you use mouse IOHIDDevice callbacks, you can use this to get a double value:

double doubleValue = IOHIDValueGetScaledValue(inIOHIDValueRef, kIOHIDTransactionDirectionTypeOutput);
+1
source

All Articles