I'm adapting some skeleton code to learn how OpenGL works and have in SphericalCameraManipulator.cpp which allows me to pan and tilt the camera while I hold down right mouse:

void SphericalCameraManipulator::handleMouseMotion(int x, int y)
{
    //Motion
    float xMotion = (float)x - previousMousePosition[0];
    float yMotion = (float)y - previousMousePosition[1];

    if(reset)
    {
        xMotion = yMotion = 0.0;
        reset = false;
    }

    this->previousMousePosition[0] = (float)x;
    this->previousMousePosition[1] = (float)y;

    //Right Button Action
    if(this->currentButton == GLUT_RIGHT_BUTTON && this->currentState == GLUT_DOWN)
    {
        this->pan  -= xMotion*this->panTiltMouseStep ;
        this->tilt += yMotion*this->panTiltMouseStep ;
    }

    //Enforce Ranges
    this->enforceRanges();
} 

I deleted the left mouse action as I don't want it to control the camera, and it now actions a command in the main code body.

//Left Button Action
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    {
        ...   //game action
    }

My problem is that when I click the left mouse, the press of the right mouse is cancelled, and I must release and repress the right mouse to continue controlling the camera.

Is there a way to prevent this from happening? It interrupts the flow of the game. I'm using GLUT

1 Answers

0
William On

Rabbid76's comment saying there is no mouse hold event set me on the right path.

I wrote a small function that simply recorded the last state of mouse button 2 (the 'camera look around' button):

void SphericalCameraManipulator::handleMouse(int button, int state)
{
    this->currentButton = button;
    this->currentState  = state;

    //to enable mouse look around
    if (this->currentButton == 2) //right mouse
        this->lastLookState = this->currentState;

    if(this->currentState == GLUT_UP)
    {
        reset = true;
    }
}

This mean even when the current state was regarding the left mouse button (game action) it was still possiblew to look around since a 'mouse two button up' event had not occured:

this->currentButton = 2;
this->currentState  = 1;