I would like to add support of a 3dconnexion SpaceMouse device in a cross-platform (Windows, Linux, Mac) 3D C++ application based on glfw library.
I downloaded 3DxWare_SDK_v4-0-2_r17624 from the device vendor, and looked at the simplest C++ sample: 3DxTraceNL. Unfortunately, it is really huge: its source code (.cpp+.h+.hpp) weights more than 200Kb, even if we do not add here 100+Kb of navlib
headers, which is the base of the application. The sample includes tons of code for Camera, Matrices, Transforms, Navigation models and so on, which I already have in my application and do not want to replace just to support new device.
What I basically look for is how to register for and receive SpaceMouse events in glfw framework. The processing of events I will will write by myself. Even if you could suggest a glfw-compatible solution for one particular platform, that would be great.
The solution I found is to use HIDAPI to communicate with SpaceMouse device (which is available on Windows, Linux and Mac) instead of 3DxWare_SDK.
One has to create an std::thread
that will in a loop
hid_enumerate
. vendor_id
argument is either 0x046d
for classical devices or 0x256f
for wireless devices.hid_open_path
.hid_read
or hid_read_timeout
.glfwPostEmptyEvent()
in case it is waiting in glfwWaitEvents()
.In GLFW event processing loop, check that new message is arrived somewhere near glfwPollEvents()
call.
The messages from SpaceMouse devices are rather simple and contain at most 13 bytes:
One can find a similar implementation in open-source MeshLib, see class SpaceMouseHandlerHidapi
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With