3D mouse support |
Astrophobia
|
Hello,
I would like to read events from an 3Dconnexion SpaceNavigator input device, but SDL does not seem to see it when using the SDL_Joystick functions (SDL_NumJoysticks, SDL_JoystickNameForIndex, etc...). Using a Xbox controller works just fine, so I don't think this is a problem of permission nor a missing subsystem initialization. I'm running SDL 2.0.3 on a Gentoo machine. Following Gentoo's Wiki page on SpaceNavigator, I managed to have the 3D mouse work with both Xorg as a mean to control the cursor and as real 6 DoF device using spacenavd (tested successfully with Blender and a few other simple programs from spacenavd), meaning my device can indeed be used. Thinking this might be a problem with spacenavd, I contacted them. They told me that SDL might not support 6 DoF devices and that libspnav should be used to read from their driver. This thread led me to believe SDL already supports 3Dconnexion devices. Is it not so? Why not? According to some project's new updates,
And indeed, using this Xorg configuration does seem to work: evtest gives me the readings I want, without having spacenavd running:
Now I'm confused... Shouldn't SDL see the device then? Is there perhaps some relation to the "JOYSTICK" flag mentionned here? If so, is there a way to enable said flag? I want my program to support as many 3D mouse models as possible, making the use of libspnav an issue, and I feel considering them as being SDL_Joysticks would make a very nice layer of abstraction. Has any of you used a 6 DoF device in their project? Is using specific libraries the generally accepted solution? |
|||||||||||||||
|
Astrophobia
|
I think I figured out what the JOYSTICK flag is. I was looking for it at the wrong place, expecting it to be a Xorg setting. Turns out it should be set before that, at udev level.
I now have an udev rule to ensures that the device gets
Tada! SDL can now see my device . But wait! There's still a (pretty big) problem:
That's not quite correct. Yes, there are 2 buttons (which SDL seems to read properly ), but there should be 6 axes. Instead, it reads 1 ball. The ball actually gives values from REL_X and REL_Y, which I see as a good sign, but only read positive values (thought I suspect this is just because that's what's expected from 'ball' inputs). From this thread, I believe that in my case (I have an USB device), spacenavd should indeed not be required. Honestly, I would have given up if not for the fact that evtest taunts me by reading from my device without any trouble. Well, at least I've learned more about Xorg and udev, so that's good. I'm currently looking into how to alter what SDL is reading when looking for the number of axes, buttons, hats and balls (just in case the axes values are there but not read). Any advice is welcome. |
|||||||||||||||
|
Astrophobia
|
So, after doing other things, I came back to this and solved it.
This is caused by the events being "relative" whereas SDL only considers "absolute" events for joysticks ("relative" are interpreted as 'Balls", as seen in my previous post). I'm surprised no one replied to this thread to tell me this. It would not be such a problem if either: - The SpaceNavigator reported itself as having "absolutes" axis. - SDL supported "Balls" with more than 2 axis. I'm developping a program that deals with the former (as some think the SpaceNavigator should report in "absolute" anyways). If you are suffering the same issue, you can find it on GitHub.[/url] |
|||||||||||
|