Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Mac Os X and glutWarpPointer

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    7

    Mac Os X and glutWarpPointer

    Hi everybody!

    As I explained in my previous and first thread in this forum, I am currently working at a very basic "game engine" in OpenGL + C++, providing the drawing and tranformation of meshes, the movement of cameras and so on.
    Specifically, to build the interface with the user I am using GLUT, and I am using glutPassiveMotionFunc() and glutMotionFunc() to detect the movement of the mouse, that drives the rotation of the active Camera.
    In particular, this is the code I am using:

    Code :
    FirstMouseMovement = true;
     
    glutMotionFunc(onMouseMovement);
    glutPassiveMotionFunc(onMouseMovement);
     
     
    void onMouseMovement(int x, int y)
    {
        int Dx, Dy;
     
     
        //If it is the first movement of the mouse
        if(FirstMouseMovement)
        {
            //Just set the initial value of the mouse position
            StartingMousex = x;
            StartingMousey = y;
     
            glutWarpPointer(w/2, h/2);
     
            FirstMouseMovement = false;
        }
        //Otherwise
        else
        {
            //Get the variation of the position of the mouse
            Dx = x - StartingMousex;
            Dy = y - StartingMousey;
     
     
            //Consequently rotate the view
            Cameras[currentCamera]->RotateCameraX(delta * Dx);
            Cameras[currentCamera]->RotateCameraY(delta * Dy);
     
     
            //Reset the mouse position
            StartingMousex = x;
            StartingMousey = y;
     
            glutPostRedisplay();
        }
    }

    And it works perfectly fine and smooth except for the fact that, when the mouse pointer meets the boundaries of the window, it arrests its movement and therefore the rotation of the camera.
    Instead, I would like it to continue the rotation independently of the position of the mouse on the windows, like in a fps game.

    Googling around, I found out that the way to achieve this should be using the glutWarpPointer() function to displace the mouse back to the centre of the window everytime we move it.
    So, I modified the onMouseMovement() function as follows:


    Code :
    void onMouseMovement(int x, int y)
    {
        int Dx, Dy;
     
     
        //If it is the first movement of the mouse
        if(FirstMouseMovement)
        {
            //Just set the initial value of the mouse position
            glutWarpPointer(w/2, h/2);
     
            FirstMouseMovement = false;
        }
        //Otherwise
        else
        {
            //Get the variation of the position of the mouse
            Dx = x - w/2;
            Dy = y - h/2;
     
     
            //Consequently rotate the view
            Cameras[currentCamera]->RotateCameraX(delta * Dx);
            Cameras[currentCamera]->RotateCameraY(delta * Dy);
     
     
            //Reset the mouse position
            glutWarpPointer(w/2, h/2);
     
            glutPostRedisplay();
        }
    }

    However, this variation of the function produces a completely unsmooth and weird movement of the camera.
    I googled around, and it seems to be due to the fact that I am working on Mac Os X, that has some problems with glWarpPointer.

    Do you guys know any workaround to this problem?

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    7
    Anybody has an answeeeeer?

  3. #3
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    429
    Read carefully these (quickly found) articles:

    https://linux.die.net/man/3/glutwarppointer
    https://www.gamedev.net/forums/topic...to-work-right/
    https://www.opengl.org/discussion_bo...inter-question

    From a quick read of these articles, it seems that:

    1) glutWarpPointer expects relative positions, not absolute ones. You're giving absolute position, which then looks wrong
    2) glutWarpPointer will most probably generate mouse motion event, which will then call your mouse move function callback. Take this into account for your code design.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •