I've been struggling a bit trying to integrate a 3D Mouse (namely a Space Navigator) in my NI Labwindows CVI application.
Thus, in order to avoid other people reinventing the wheel, here's the way I managed to get it working. And it works perfectly for me, believe me
First, declare a callback for the 3D mouse in the classical CVI way:
Code: Select all
// 3DMouse Callback declaration
int CVICALLBACK SpaceNavigatorCB(int panelHandle, int message, unsigned int* wParam, unsigned int* lParam, void* callbackData);
After mouse initialization, get the Windows message number used by 3DxWare, and install a CVI callback to react to this message number. Then you can run the user interface:
Code: Select all
// Initialize 3D mouse
status = SbInit();
// Get 3DxWare message number
Mess3Dx = RegisterWindowMessage("SpaceWareMessage00");
// Install a specific callback for this message
InstallWinMsgCallback (mainPanel, Mess3Dx, SpaceNavigatorCB, VAL_MODE_INTERCEPT, NULL, &postHandle);
// Run application
RunUserInterface();
// Remove callback on quitting
RemoveWinMsgCallback(mainPanel, Mess3Dx);
Code: Select all
int CVICALLBACK SpaceNavigatorCB(int panel, int message, unsigned int* wParam, unsigned int* lParam, void* callbackData)
{
int num; /* number of button pressed */
SiSpwEvent Event; /* SpaceWare Event */
SiGetEventData EData; /* SpaceWare Event Data */
/* init Window platform specific data for a call to SiGetEvent */
SiGetEventWinInit(&EData, (UINT)message, (WPARAM)*wParam, (LPARAM)*lParam);
/* check whether msg was a 3D mouse event and process it */
if (SiGetEvent (devHdl, SI_AVERAGE_EVENTS, &EData, &Event) == SI_IS_EVENT) {
if (Event.type == SI_MOTION_EVENT)
SbMotionEvent(&Event); /* process 3D mouse motion event */
if (Event.type == SI_ZERO_EVENT)
SbZeroEvent(); /* process 3D mouse zero event */
if (Event.type == SI_BUTTON_EVENT) {
if ((num = SiButtonPressed (&Event)) != SI_NO_BUTTON)
SbButtonPressEvent(num); /* process 3D mouse button event */
if ((num = SiButtonReleased (&Event)) != SI_NO_BUTTON)
SbButtonReleaseEvent(num); /* process 3D mouse button event */
}
if (Event.type == SI_DEVICE_CHANGE_EVENT)
HandleDeviceChangeEvent(&Event);
}
return 0;
}
Here is the CVI port of the 3DxTest demo program:
(is there a way to attach a file to a post) ?
http://www.filefactory.com/file/cee4fd5 ... xMouse.rar
Feel free to test and comment...
François
P.S. In order to get it working, it was necessary to comment the "include <tchar>" line in spwdata.h.
There are no adverse effects until now, but is it safe, Jim ? Or are there workarounds ?