As a stress test for the architectural design of the new input sub-system for the modeling core, I’ve started implementing various input metaphors and just finished the support for a 3DConnexion space mouse-type device. In general, it’s fairly simple and once you have registered for and obtained the SDK, it is a matter of an hour or so to get the base code running… in theory…
There are a few stumbling blocks when it comes to implementing this device and I write this down in hope to help others who try to do the same thing:
- First of all, note that the device sends change messages when you move the puck and not a recurring status message. What this means is that your application has to regularly check the current values of the device by itself and apply an appropriate translation/rotation. For example, if the puck is moved full ahead, the camera should be moved forward proportional to the elapsed time since the last frame that was rendered, regardless of the number of messages the device sends. E.g. let’s say full ahead is a velocity of 10 units per second, you render at 60hz and it took two frames to compute the new image, then the camera should move 2 * 1/60 * 10 = 1/3 modeling unit.
- The SDK documentation mentions the app bundle signature. I had no idea what that was and glossed over it. The result was that I got connect/disconnect events but no axes/button updates. The app bundle signature seems to be an outdated mechanism to identify OSX apps and the 3D Connexion driver uses it to figure out if your app is in the foreground and should thus receive updates. You absolute have to set a four-letter signature in your application’s info.plist file and have a matching code in the initialization function for the SDK, otherwise you won’t get axes/button update events.
- Which brings me to the next point: Your app only receives updates when it is in the foreground. Quite obvious once you know it, but it made debugging a bit more difficult because I pushed the puck forward and then tried to add a breakpoint in XCode. Unexpected by me, the values received then were all zero because the app had gone to the background when I clicked into XCode!
- Make sure the 3Dconnexion helper in your OSX user account’s login items list is enabled. I disabled it a couple of days ago (thinking it was the reason for an annoying popup that appeared every time I logged in) and again, you will only get connect/disconnect events and no axes/button updates. Strangely enough, one of the official demos that you can access via the settings panel seemed to work even with this deactivated but I might be mistaking…
- The extern declaration used to check for weak linkage did not work for me, I had to change it to extern OSErr InstallConnexionHandlers(ConnexionMessageHandlerProc, ConnexionAddedHandlerProc, ConnexionRemovedHandlerProc) __attribute__((weak_import))
So, after a lot of unnecessary errors, I finally managed to get it working today! Keeping in mind that there is sample code in the SDK and the final version in my code isn’t really much different from what is there (just ported it over from objective-C to C++11), this took way longer than it should have taken…
Leave a Reply