Joystick Event Handler
Posted: Thu Dec 01, 2011 9:01 am
Hey there and thanks for checking by.
Though I´ve been recently busy with Unity,
I´ve to say that creating Games with Irrlicht is a lot more satisfying.
Atm I am trying to create a simple but working Joystick Handler,
I have searched the forum or wiki but I cant seem to find something working.
So I started to build my own on base of the Tutorial.
Joystick Class:
Main:
Loop:
Okay...basicly I am able to use my Analog Sticks and that works just fine.
But should I do to implement Joystick Buttons?
I found this
It would be nice if someone could add 1 simple Button_A to the Code above. <3
Thanks for your time,
Chris
Though I´ve been recently busy with Unity,
I´ve to say that creating Games with Irrlicht is a lot more satisfying.
Atm I am trying to create a simple but working Joystick Handler,
I have searched the forum or wiki but I cant seem to find something working.
So I started to build my own on base of the Tutorial.
Joystick Class:
Code: Select all
class Joystick : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT
&& event.JoystickEvent.Joystick == 0)
{
JoystickState = event.JoystickEvent;
}
return false;
}
const SEvent::SJoystickEvent & GetJoystickState(void) const
{
return JoystickState;
}
Joystick()
{
}
private:
SEvent::SJoystickEvent JoystickState;
};
Code: Select all
array<SJoystickInfo> joystickInfo; //create array to load info
if(device->activateJoysticks(joystickInfo)) //add active joysticks to my number
Code: Select all
bool movedWithJoystick = false; //to check if we are using joystick
if(joystickInfo.size() > 0) //if we are using joystick do:
{
f32 moveHorizontal = 0.f;
f32 moveVertical = 0.f;
const SEvent::SJoystickEvent & joystickData = receiver.GetJoystickState();
const f32 DEAD_ZONE = 0.05f; //to prevent
moveHorizontal =
(f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_X] / 32767.f;
if(fabs(moveHorizontal) < DEAD_ZONE)
moveHorizontal = 0.f;
moveVertical =
(f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_Y] / -32767.f;
if(fabs(moveVertical) < DEAD_ZONE)
moveVertical = 0.f;
const u16 povDegrees = joystickData.POV / 100;
if(povDegrees < 360)
{
if(povDegrees > 0 && povDegrees < 180)
moveHorizontal = 1.f;
else if(povDegrees > 180)
moveHorizontal = -1.f;
if(povDegrees > 90 && povDegrees < 270)
moveVertical = -1.f;
else if(povDegrees > 270 || povDegrees < 90)
moveVertical = +1.f;
}
}
But should I do to implement Joystick Buttons?
I found this
andu32 irr::SEvent::SJoystickEvent::ButtonStates
But I am not sure how to implement them with JoysticksIsButtonPressed()
It would be nice if someone could add 1 simple Button_A to the Code above. <3
Thanks for your time,
Chris