I've been tinkering with x11 code while using PlatformWindows.cpp as reference and finally got the mouse to stick to the center of the screen. Unfortunately when I move the mouse pointer the screen vibrates as it moves. As far as I can tell, the XWarpPointer function seems to be affecting the movement of the mouse. I'm not really sure how to explain it, but here's the code:
definition of the setMouseCaptured()
- Code: Select all
void Platform::setMouseCaptured(bool captured)
{
if(captured!=__mouseCaptured)
{
if(captured)
{
p.x=getDisplayWidth()/2;
p.y=getDisplayHeight()/2;
// Hide cursor - function goes here......
XWarpPointer(__display, None, __window, 0, 0, 0, 0, p.x, p.y);
}
else
{
XWarpPointer(__display, None, __window, 0, 0, 0, 0, p.x, p.y);
// Unhide cursor - function goes here...
}
__mouseCaptured=captured;
}
}
...and the relevant code in enterMessagePump()
- Code: Select all
case MotionNotify:
{
int x=evt.xmotion.x;
int y=evt.xmotion.y;
if(__mouseCaptured)
{
if(x==p.x && y==p.y)
break;
x-=p.x;
y-=p.y;
XWarpPointer(__display, None, __window, 0, 0, 0, 0, p.x, p.y);
}
if (!gameplay::Platform::mouseEventInternal(gameplay::Mouse::MOUSE_MOVE, x, y, 0))
{
if (evt.xmotion.state & Button1Mask)
{
gameplay::Platform::touchEventInternal(gameplay::Touch::TOUCH_MOVE, x, y, 0);
}
else if (evt.xmotion.state & Button3Mask)
{
// Update the pitch and roll by adding the scaled deltas.
__roll += (float)(x - lx) * ACCELEROMETER_X_FACTOR;
__pitch += -(float)(y - ly) * ACCELEROMETER_Y_FACTOR;
// Clamp the values to the valid range.
__roll = max(min(__roll, 90.0f), -90.0f);
__pitch = max(min(__pitch, 90.0f), -90.0f);
// Update the last X/Y values.
lx = x;//evt.xbutton.x;
ly = y;//evt.xbutton.y;
}
}
Like I said before, I've been using PlatformWindows.cpp as a reference so the code structure/organization is practically the same. Since I have no real knowledge regarding x11 or windows api, I'm not really sure what I'm missing. If someone could look at the code and test it out and give me some feedback I'd be really thankful.