Mouse trap?

I am using GLUT and developing an FPS game. I need a way to capture the mouse so that the camera continues to move, because right now, when the mouse position exceeds the limits of the monitor, it is impossible to calculate the change in X or change Y. How can I “catch” a mouse with GLUT?

thank

+3
source share
1 answer

I would recommend using a ready-made engine instead, like OGRE 3D , but if you really want to invent a wheel, here's how ...

, , PC FPS- "" , , , .

, , ping-pong OpenGL ++ :

void resetPointer() {
    glutWarpPointer(TABLE_X/2, TABLE_Y/2);
    lastMousePos = TABLE_Y/2;
}

void mouseFunc(int sx, int sy) {
    if (!started) { return; }
    int vertMotion = lastMousePos - sy;
    lastMousePos = sy;
    player1.move(vertMotion);

    // Keep the pointer from leaving the window.
    if (fabs(TABLE_X/2 - sx) > 25 || fabs(TABLE_Y/2 - sy) > 25) {
        resetPointer();
    }
}

// This goes in with your "start new game" code if you want a menu
resetPointer();
glutSetCursor(GLUT_CURSOR_NONE);
glutPassiveMotionFunc(mouseFunc);

, .

+3

Source: https://habr.com/ru/post/1763262/


All Articles