void GuiControl::toggleMouselook()
{
    if (_isMouselooking)
    {
        _isMouselooking = false;

        // Restore cursor to center
        g3d_resetcursor();
    } else {
        _isMouselooking = true;
    };
};
Exemplo n.º 2
0
    void injectMousePosition(float x, float y, bool immediate)
    {
        if (immediate)
        {
            float curr_x, curr_y;
            g3d_cursorpos(curr_x, curr_y);
            float xrel = x - curr_x;
            float yrel = y - curr_y;
            xrel *= max(screen->w, screen->h);
            yrel *= max(screen->w, screen->h);
//printf("curr: %f, %f\r\n", curr_x, curr_y);
//printf("next: %f, %f\r\n", x, y);
//printf("RELS: %f, %f       \r\n", xrel, yrel);
            if(!g3d_movecursor(0, 0))
            {
                mousemove(xrel, yrel);
                SDL_WarpMouse(screen->w / 2, screen->h / 2);
            }
            cursorx = x;
            cursory = y;
            return;
        }

/*
            float curr_x, curr_y;
            g3d_cursorpos(curr_x, curr_y);
            float xrel = x - curr_x;
            float yrel = y - curr_y;
            xrel *= 1000;
            yrel *= 1000;
printf("rels: %f, %f        %f,%f\r\n", xrel, yrel, x, curr_x);
            if(!g3d_movecursor(xrel, yrel))
                mousemove(xrel, yrel);
*/

        g3d_resetcursor(); // now at 0.5,0.5
        float curr_x, curr_y;
        float factor = 400;
        int iters = 0;
        do
        {
            g3d_cursorpos(curr_x, curr_y);
            //printf("A %d : (%f,%f) vs (%f,%f): %f,%f\r\n", iters, x, y, curr_x, curr_y, factor*(x - curr_x), factor*(y - curr_y));
            g3d_movecursor(factor*(x - curr_x), factor*(y - curr_y));
            iters++;
            //printf("B %d : (%f,%f) vs (%f,%f)\r\n", iters, x, y, curr_x, curr_y);
        } while (fabs(x-curr_x) + fabs(y-curr_y) > 0.005 && iters < 1000);
        assert(iters < 1000);
    }