http://www.evolutional.co.uk/irrlicht/I ... ick_01.zip
I apologise for the cross-post, I posted this in the wrong forum - if a mod could delete the original post it would be cool.
Basics
The Windows Multimedia library, winmm.lib, allows windows applications to access attached joysticks, using the message pump to convey actions. By altering the CIrrDeviceWin32 class and adding some extra IEventListener interface, Irrlicht 0.11 now receives basic joystick events from 2 joystick devices (with a max of 4 buttons each).
Changes
Here's a brief outline to the changed Event structure:-
New enumeration:
Code: Select all
//! Enumeration for all joystick input events
enum EJOYSTICK_INPUT_EVENT
{
//! Joystick button 1 was pressed down.
EJIE_BUTTON1_PRESSED_DOWN = 0,
//! Joystick button 1 was left up
EJIE_BUTTON1_LEFT_UP,
//! Joystick button 2 was pressed down.
EJIE_BUTTON2_PRESSED_DOWN,
//! Joystick button 2 was left up
EJIE_BUTTON2_LEFT_UP,
//! Joystick button 3 was pressed down.
EJIE_BUTTON3_PRESSED_DOWN,
//! Joystick button 3 was left up
EJIE_BUTTON3_LEFT_UP,
//! Joystick button 4 was pressed down.
EJIE_BUTTON4_PRESSED_DOWN,
//! Joystick button 4 was left up
EJIE_BUTTON4_LEFT_UP,
//! Joystick was moved
EJIE_JOYSTICK_MOVED,
};
Within the SEvent structure, there's a new struct:-
Code: Select all
struct
{
//! Joystick Device ID
u32 DeviceId;
//! X position of joystick
s32 X;
//! Y position of joystick
s32 Y;
//! type of joystick event
EJOYSTICK_INPUT_EVENT Event;
} JoystickInput;
Usage
Using it is pretty simple; within your normal Event handler function:-
Code: Select all
if ( event.EventType == irr::EET_JOYSTICK_INPUT_EVENT )
{
if (event.JoystickInput.Event == irr::EJIE_BUTTON1_PRESSED_DOWN)
{
std::cout << "Device: " << event.JoystickInput.DeviceId << " - Button 1 pressed\n";
return true;
}
if (event.JoystickInput.Event == irr::EJIE_BUTTON1_LEFT_UP)
{
std::cout << "Device: " << event.JoystickInput.DeviceId << " - Button 1 released\n";
return true;
}
if (event.JoystickInput.Event == irr::EJIE_BUTTON2_PRESSED_DOWN)
{
std::cout << "Device: " << event.JoystickInput.DeviceId << " - Button 2 pressed\n";
return true;
}
if (event.JoystickInput.Event == irr::EJIE_BUTTON2_LEFT_UP)
{
std::cout << "Device: " << event.JoystickInput.DeviceId << " - Button 2 released\n";
return true;
}
}
Unpack the Irrlicht source distribution and replace the following files with the ones from this patch:-
CIrrDeviceWin32.h
CIrrDeviceWin32.cpp
include/IEventReceiver.h (remember to replace your SDK version too!)
Compile the Irrlicht.dll as normal, linking with winmm.lib/winmm.a
Other things
So far there is NO capabilities information for the joysticks, so it's up to your own application to work out the calibrations and number of buttons present. I've also hardcoded the limit of 2 joysticks, but this can easily be raised if needed.
If you find this useful, let me know. If anyone wishes to offer any further advice or improvements to this (very simple) implementation, feel free to drop me a line. If I get round to it, I'll also attempt to add the same functionality to the Linux Device.
Download
http://www.evolutional.co.uk/irrlicht/I ... ick_01.zip
Enjoy!
- Oli