#0 

10-10-2009 18:09:51

aitina
Membre
Date d'inscription: 02-11-2006
Messages: 55

Bonjour tout le Monde.

J'ai acheté un gamepad (dans une grande surface)pour l'inclure dans une petite demo .

Auriez-vous un tutorial ou une explication ou encore mieux un listing sur le sujet?

Je vous remercie beaucoup.

Cordialement.

Hors ligne


#1 

10-10-2009 18:35:33

tmyke
Administrateur
Date d'inscription: 24-03-2008
Messages: 1025

Pour activer la partie Joy (gamepad je pense que c'est pareil, jamais testé)

Code c++ :


int iActivateJoysticks()
{
    core::array<SJoystickInfo> joystickInfo;
    if(globenv.device->activateJoysticks(joystickInfo))
    {
        std::cout << "Joystick support is enabled and " << joystickInfo.size() << " joystick(s) are present." << std::endl;

        if ( joystickInfo.size() == 0 ) return 0;

        for(u32 joystick = 0; joystick < joystickInfo.size(); ++joystick)
        {
            std::cout << "Joystick " << joystick << ":" << std::endl;
            std::cout << "\tName: '" << joystickInfo[joystick].Name.c_str() << "'" << std::endl;
            std::cout << "\tAxes: " << joystickInfo[joystick].Axes << std::endl;
            std::cout << "\tButtons: " << joystickInfo[joystick].Buttons << std::endl;

            std::cout << "\tHat is: ";

            switch(joystickInfo[joystick].PovHat)
            {
            case SJoystickInfo::POV_HAT_PRESENT:
                std::cout << "present" << std::endl;
                break;

            case SJoystickInfo::POV_HAT_ABSENT:
                std::cout << "absent" << std::endl;
                break;

            case SJoystickInfo::POV_HAT_UNKNOWN:
            default:
                std::cout << "unknown" << std::endl;
                break;
            }
        }
        return 1;
    }
    else
    {
        std::cout << "Joystick support is not enabled." << std::endl;
        return 0;
    }
}




ensuite je dirais que tu pourrais écrire un truc comme cela dans la fonction OnEvent:

Code c++ :


        if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT  && event.JoystickEvent.Joystick == 0)
        {
            JoystickState = event.JoystickEvent;
        }




puis pour récupérer des info, pour un joystick on pourrait écrire

Code c++ :


int iJoysticksAxis(int id)
{
    return (int)globenv.receiver.GetJoystickState().Axis[id];
}
int iJoysticksButtonStates()
{
    return (int)globenv.receiver.GetJoystickState().ButtonStates;
}
int iJoysticksPOV()
{
    return (int)globenv.receiver.GetJoystickState().POV;
}
int iJoysticksJoy()
{
    return (int)globenv.receiver.GetJoystickState().Joystick;
}



Pas trop dur de t'accomoder de ces codes pour un joypad, non ?

wink


Force et sagesse...

Hors ligne


Options Liens officiels Caractéristiques Statistiques Communauté
Corrections
irrlicht
irrklang
irredit
irrxml
xhtml 1.0
css 2.1
Propulsé par FluxBB
Traduit par FluxBB.fr
881 membres
1427 sujets
11117 messages
Dernier membre inscrit: Bidule
21 invités en ligne
Aucun membre connecté
RSS Feed