andandandand
andandandand

Reputation: 22270

OpenGL, GLUT: How can I tell if a gamepad key is active (pressed)?

I'm using a gamepad as input on a game and I want to move the camera with its key presses. This works, but the camera doesn't keep moving unless I release the gamepad key and press it again. How can I make the camera keep moving with the key pressed?

here is my gamepad func:

void  gamepad (unsigned int buttonMask, int x, int y, int z){

    //left
    if(x<-7){

        moveLeftSwitch=1;
        printf("left\n");

        camara.trasladar_left_right((-speedT*10));
    }

    if (x==-7){

       moveLeftSwitch=0;
    }
    //right
    if(x>-7){
         printf("right\n");

    }

    //up
    if(y<-7){
        printf("up\n"); 
        if(camara.trasladar_front_back(speedT)){

        }

    }

    //down
    if(y>-7){
        printf("down\n");
        camara.trasladar_front_back(-speedT);

    }


}

and the callbacks I used:

glutJoystickFunc(gamepad, 300);
glutForceJoystickFunc();

Upvotes: 2

Views: 2585

Answers (2)

Win_z
Win_z

Reputation: 11

Insert glutForceJoystickFunc(); in your timer func and the problem is solved.

Upvotes: 0

user181351
user181351

Reputation:

if(buttonMask & GLUT_JOYSTICK_BUTTON_A) {
    printf("button A is pressed ");
}
if(buttonMask & GLUT_JOYSTICK_BUTTON_B) {
    printf("button B is pressed ");
}
if(buttonMask & GLUT_JOYSTICK_BUTTON_C) {
    printf("button C is pressed ");
}
if(buttonMask & GLUT_JOYSTICK_BUTTON_D) {
    printf("button D is pressed ");
}

From here

Upvotes: 3

Related Questions