C++ SDK for 3D Spacenavigator

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
jhasketan
Posts: 6
Joined: Mon Oct 05, 2020 6:13 am

C++ SDK for 3D Spacenavigator

Post by jhasketan »

Hi All,

Is there any C++ SDK to get position and orientation of a 3D Space navigator mouse?

We are writing a sample C++ program to control some emulation based on 3D movement.

I tried a lot from the 3DConnexion website but could not get one.

Thanks,
Jhasketan
ngomes
Moderator
Moderator
Posts: 3396
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Re: C++ SDK for 3D Spacenavigator

Post by ngomes »

Hi Jhasketan,
jhasketan wrote: Mon Oct 05, 2020 6:18 am I tried a lot from the 3DConnexion website but could not get one.
You should find the SDKs in the "developer area" in 3Dconnexion's web site. Go to "Support" and then click on the "Visit the Developer Area" link.
Nuno Gomes
jhasketan
Posts: 6
Joined: Mon Oct 05, 2020 6:13 am

Re: C++ SDK for 3D Spacenavigator

Post by jhasketan »

Thanks a lot for the reply @ngmes. I did not see "developer area" under support. I did see "Software Developer" but after clicking that it is asking me to fill up a form. In that form, it is asking me information about the website address of my application, the number of users of my application etc. This information I do not have as I am trying to use 3D Spacenavigator mouse for my custom desktop application. Am at the correct website? Following the URL :
https://3dconnexion.com/us/

Thanks,
Jhasketan
jhasketan
Posts: 6
Joined: Mon Oct 05, 2020 6:13 am

Re: C++ SDK for 3D Spacenavigator

Post by jhasketan »

jhasketan wrote: Wed Oct 07, 2020 6:14 am Thanks a lot for the reply @ngomes. I did not see "developer area" under support. I did see "Software Developer" but after clicking that it is asking me to fill up a form. In that form, it is asking me information about the website address of my application, the number of users of my application etc. This information I do not have as I am trying to use 3D Spacenavigator mouse for my custom desktop application. Am at the correct website? Following the URL :
https://3dconnexion.com/us/

Thanks,
Jhasketan
ngomes
Moderator
Moderator
Posts: 3396
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Re: C++ SDK for 3D Spacenavigator

Post by ngomes »

jhasketan wrote: Wed Oct 07, 2020 6:14 am https://3dconnexion.com/us/
That's the correct web site, alright.

Concerning the registration, just enter the information as it applies to your specific case. If you're using the SDK on personal basis, just state and enter zero or "not applicable" in the fields asking for the company details.
jhasketan
Posts: 6
Joined: Mon Oct 05, 2020 6:13 am

Re: C++ SDK for 3D Spacenavigator

Post by jhasketan »

Thanks a lot. I found it. Is there any sample program just to demonstrate how to get the current position and orientation of the "3D SpaceNavigator compact". I saw the sample but I did not find from where it is querying position and orientation from the driver.

Thanks,
Jhasketan
ngomes
Moderator
Moderator
Posts: 3396
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Re: C++ SDK for 3D Spacenavigator

Post by ngomes »

jhasketan wrote: Wed Oct 07, 2020 6:48 am Is there any sample program just to demonstrate how to get the current position and orientation of the "3D SpaceNavigator compact".
The SDK has samples that show how to interact with the driver API (an abstraction of a camera controller). Basically, the driver gets values (or "properties") from the application, process them and puts them back as needed. The application developer only has to implement the setter and getter properties and all the nitty gritty of 3D mouse manipulation is done by the driver.

Perhaps you already have an existing implementation? What do you mean by "position and orientation"?
jhasketan
Posts: 6
Joined: Mon Oct 05, 2020 6:13 am

Re: C++ SDK for 3D Spacenavigator

Post by jhasketan »

What I am trying to implement is move an object in the 3D space based on the 3D mouse movement. Following based on old SDK(32 bit). I am interested in TI_MOTION event which will. give me x,y,z,rx,try,rz from 3d space mouse.

I am trying to achieve the same with the latest SDK.

Thanks,
Jhasketan
----------------------------------------------- CPP CODE-----------------------------------------------------
#include <windows.h>
#include <iostream>

#include "spwmacro.h" /* Common macros used by SpaceWare functions. */
#include "si.h" /* Required for any SpaceWare support within an app.*/
#include "siapp.h" /* Required for siapp.lib symbols */

#pragma warning(disable:4700)

#ifdef __cplusplus
extern "C" {
#endif

SiHdl devHdl; /* Handle to 3D Mouse Device */
SiOpenData oData;
WNDPROC wndProcOrig;

void ClearScreen() {
for(unsigned i=0; i<100; ++i) std::cout << std::endl;
}

int SbInit(HWND hwndC);
void SbMotionEvent(SiSpwEvent *pEvent);
void SbZeroEvent();
void SbButtonPressEvent(int buttonnumber);
void SbButtonReleaseEvent(int buttonnumber);
void HandleDeviceChangeEvent(SiSpwEvent *pEvent);


LRESULT CALLBACK MyWndCBProc(
HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam)
{
SiSpwEvent Event; /* SpaceWare Event */
SiGetEventData EData; /* SpaceWare Event Data */

/* initialize Window platform specific data for a call to SiGetEvent */
SiGetEventWinInit(&EData, wm, wParam, lParam);

/* check whether wm was a 3D mouse event and process it */
//if (SiGetEvent (devHdl, SI_AVERAGE_EVENTS, &EData, &Event) == SI_IS_EVENT)
SpwRetVal retval = SiGetEvent (devHdl, 0, &EData, &Event);

if (retval == SI_IS_EVENT)
{
if (Event.type == SI_MOTION_EVENT)
{
SbMotionEvent(&Event); /* process 3D mouse motion event */
}
else if (Event.type == SI_ZERO_EVENT)
{
SbZeroEvent(); /* process 3D mouse zero event */
}
else if (Event.type == SI_BUTTON_PRESS_EVENT)
{
SbButtonPressEvent(Event.u.hwButtonEvent.buttonNumber); /* process button press event */
}
else if (Event.type == SI_BUTTON_RELEASE_EVENT)
{
SbButtonReleaseEvent(Event.u.hwButtonEvent.buttonNumber); /* process button release event */
}
/* else if (Event.type == SI_DEVICE_CHANGE_EVENT)
{
//SbHandleDeviceChangeEvent(&Event); /* process 3D mouse device change event
}*/
}

return DefWindowProc(hwnd, wm, wParam, lParam);
}

int main() {

/* Retrieve console application main window using GetConsoleWindow() */
HWND windowHandle = GetConsoleWindow() ; /* Great!! This function cleverly "retrieves the window handle used by the console associated with the calling process", as msdn says */

/* Register a custom window class */
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = MyWndCBProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetModuleHandle(NULL);
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "MyWindowClassName";
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);

/* Create a hidden window owned by our process and parented to the console window */
HWND hWndChild = CreateWindow(wcex.lpszClassName, "MyWindowTitle", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, wcex.hInstance, NULL);

/* Initialise 3DxWare access / call to SbInit() */
SbInit(hWndChild);

/* Implement message loop */
int bRet;
MSG msg; /* incoming message to be evaluated */
while(bRet = GetMessage(&msg, NULL, 0, 0 ))
{
if (bRet == -1){
/* handle the error and possibly exit */
return 0;
}else{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}


int SbInit(HWND hwndC)
{
int res; /* result of SiOpen, to be returned */

/*init the SpaceWare input library */
if (SiInitialize() == SPW_DLL_LOAD_ERROR) {
std::cout << "Error: Could not load SiAppDll dll files" << std::endl;
} else {
//std::cout << "SiInitialize() done " << std::endl;
}

SiOpenWinInit (&oData, hwndC); /* init Win. platform specific data */

/* open data, which will check for device type and return the device handle to be used by this function */
if ( (devHdl = SiOpen("AppSpaceMouse.exe", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData)) == NULL) {
std::cout << "SiOpen error:" << std::endl;
SiTerminate(); /* called to shut down the SpaceWare input library */
std::cout << "SiTerminate()" << std::endl;
res = 0; /* could not open device */
return res;
}

SiDeviceName pname;
SiGetDeviceName (devHdl, &pname);
//std::cout << "devicename = " << pname.name << std::endl;

SiSetUiMode(devHdl, SI_UI_ALL_CONTROLS); /* Config SoftButton Win Display */
SiGrabDevice(devHdl, SPW_TRUE); /* PREVENTS OTHER APPLICATIONS FROM RECEIVING 3D CONNEXION DATA !!! */
res = 1; /* opened device succesfully */
return res;
}

void SbMotionEvent(SiSpwEvent *pEvent) {
std:: cout << "TX=" << pEvent->u.spwData.mData[SI_TX] << " TY=" << pEvent->u.spwData.mData[SI_TY] << " TZ=" << pEvent->u.spwData.mData[SI_TZ] << " RX=" << pEvent->u.spwData.mData[SI_RX] << " RY=" << pEvent->u.spwData.mData[SI_RY] << " RZ=" << pEvent->u.spwData.mData[SI_RZ] << std::endl;
}

void SbZeroEvent() {
std::cout << "zeroevent: " << std::endl;
}
void SbButtonPressEvent(int buttonnumber) {
std::cout << "Buttonnumber : " << buttonnumber << std::endl;
}
void SbButtonReleaseEvent(int buttonnumber) {
std::cout << "Buttonnumber : " << buttonnumber << std::endl;
}
void HandleDeviceChangeEvent(SiSpwEvent *pEvent) {
std::cout << "HandleDeviceChangeEvent : " << std::endl;

}
#ifdef __cplusplus
}
#endif
-----------------------------------------------------------------------------------------------------------------
jhasketan
Posts: 6
Joined: Mon Oct 05, 2020 6:13 am

Re: C++ SDK for 3D Spacenavigator

Post by jhasketan »

jhasketan wrote: Wed Oct 07, 2020 7:26 am What I am trying to implement is move an object in the 3D space based on the 3D mouse movement. Following code is based on old SDK(32 bit). I am interested in TI_MOTION event which will. give me x,y,z,rx,try,rz from 3d space mouse.

I am trying to achieve the same with the latest SDK.

Thanks,
Jhasketan
----------------------------------------------- CPP CODE-----------------------------------------------------
#include <windows.h>
#include <iostream>

#include "spwmacro.h" /* Common macros used by SpaceWare functions. */
#include "si.h" /* Required for any SpaceWare support within an app.*/
#include "siapp.h" /* Required for siapp.lib symbols */

#pragma warning(disable:4700)

#ifdef __cplusplus
extern "C" {
#endif

SiHdl devHdl; /* Handle to 3D Mouse Device */
SiOpenData oData;
WNDPROC wndProcOrig;

void ClearScreen() {
for(unsigned i=0; i<100; ++i) std::cout << std::endl;
}

int SbInit(HWND hwndC);
void SbMotionEvent(SiSpwEvent *pEvent);
void SbZeroEvent();
void SbButtonPressEvent(int buttonnumber);
void SbButtonReleaseEvent(int buttonnumber);
void HandleDeviceChangeEvent(SiSpwEvent *pEvent);


LRESULT CALLBACK MyWndCBProc(
HWND hwnd, UINT wm, WPARAM wParam, LPARAM lParam)
{
SiSpwEvent Event; /* SpaceWare Event */
SiGetEventData EData; /* SpaceWare Event Data */

/* initialize Window platform specific data for a call to SiGetEvent */
SiGetEventWinInit(&EData, wm, wParam, lParam);

/* check whether wm was a 3D mouse event and process it */
//if (SiGetEvent (devHdl, SI_AVERAGE_EVENTS, &EData, &Event) == SI_IS_EVENT)
SpwRetVal retval = SiGetEvent (devHdl, 0, &EData, &Event);

if (retval == SI_IS_EVENT)
{
if (Event.type == SI_MOTION_EVENT)
{
SbMotionEvent(&Event); /* process 3D mouse motion event */
}
else if (Event.type == SI_ZERO_EVENT)
{
SbZeroEvent(); /* process 3D mouse zero event */
}
else if (Event.type == SI_BUTTON_PRESS_EVENT)
{
SbButtonPressEvent(Event.u.hwButtonEvent.buttonNumber); /* process button press event */
}
else if (Event.type == SI_BUTTON_RELEASE_EVENT)
{
SbButtonReleaseEvent(Event.u.hwButtonEvent.buttonNumber); /* process button release event */
}
/* else if (Event.type == SI_DEVICE_CHANGE_EVENT)
{
//SbHandleDeviceChangeEvent(&Event); /* process 3D mouse device change event
}*/
}

return DefWindowProc(hwnd, wm, wParam, lParam);
}

int main() {

/* Retrieve console application main window using GetConsoleWindow() */
HWND windowHandle = GetConsoleWindow() ; /* Great!! This function cleverly "retrieves the window handle used by the console associated with the calling process", as msdn says */

/* Register a custom window class */
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = MyWndCBProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetModuleHandle(NULL);
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "MyWindowClassName";
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);

/* Create a hidden window owned by our process and parented to the console window */
HWND hWndChild = CreateWindow(wcex.lpszClassName, "MyWindowTitle", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, wcex.hInstance, NULL);

/* Initialise 3DxWare access / call to SbInit() */
SbInit(hWndChild);

/* Implement message loop */
int bRet;
MSG msg; /* incoming message to be evaluated */
while(bRet = GetMessage(&msg, NULL, 0, 0 ))
{
if (bRet == -1){
/* handle the error and possibly exit */
return 0;
}else{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}


int SbInit(HWND hwndC)
{
int res; /* result of SiOpen, to be returned */

/*init the SpaceWare input library */
if (SiInitialize() == SPW_DLL_LOAD_ERROR) {
std::cout << "Error: Could not load SiAppDll dll files" << std::endl;
} else {
//std::cout << "SiInitialize() done " << std::endl;
}

SiOpenWinInit (&oData, hwndC); /* init Win. platform specific data */

/* open data, which will check for device type and return the device handle to be used by this function */
if ( (devHdl = SiOpen("AppSpaceMouse.exe", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData)) == NULL) {
std::cout << "SiOpen error:" << std::endl;
SiTerminate(); /* called to shut down the SpaceWare input library */
std::cout << "SiTerminate()" << std::endl;
res = 0; /* could not open device */
return res;
}

SiDeviceName pname;
SiGetDeviceName (devHdl, &pname);
//std::cout << "devicename = " << pname.name << std::endl;

SiSetUiMode(devHdl, SI_UI_ALL_CONTROLS); /* Config SoftButton Win Display */
SiGrabDevice(devHdl, SPW_TRUE); /* PREVENTS OTHER APPLICATIONS FROM RECEIVING 3D CONNEXION DATA !!! */
res = 1; /* opened device succesfully */
return res;
}

void SbMotionEvent(SiSpwEvent *pEvent) {
std:: cout << "TX=" << pEvent->u.spwData.mData[SI_TX] << " TY=" << pEvent->u.spwData.mData[SI_TY] << " TZ=" << pEvent->u.spwData.mData[SI_TZ] << " RX=" << pEvent->u.spwData.mData[SI_RX] << " RY=" << pEvent->u.spwData.mData[SI_RY] << " RZ=" << pEvent->u.spwData.mData[SI_RZ] << std::endl;
}

void SbZeroEvent() {
std::cout << "zeroevent: " << std::endl;
}
void SbButtonPressEvent(int buttonnumber) {
std::cout << "Buttonnumber : " << buttonnumber << std::endl;
}
void SbButtonReleaseEvent(int buttonnumber) {
std::cout << "Buttonnumber : " << buttonnumber << std::endl;
}
void HandleDeviceChangeEvent(SiSpwEvent *pEvent) {
std::cout << "HandleDeviceChangeEvent : " << std::endl;

}
#ifdef __cplusplus
}
#endif
-----------------------------------------------------------------------------------------------------------------
ngomes
Moderator
Moderator
Posts: 3396
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Re: C++ SDK for 3D Spacenavigator

Post by ngomes »

jhasketan wrote: Wed Oct 07, 2020 7:26 am I am trying to achieve the same with the latest SDK.
In other words, you're looking for a wrapper around the new API so that it looks and behaves as the old one. This isn't something we have and, considering the work and risk involved, it's does not seem like a feasible proposition.

The new API is a breaking change: porting the application to the new API will require a new implementation.
frist
Posts: 5
Joined: Tue Oct 20, 2020 5:37 am

Re: C++ SDK for 3D Spacenavigator

Post by frist »

Hi,
is the old version 3.x SDK available somewhere? I also have a old application and just noticed that I did not archive the SDK.

See you
Flo
ngomes
Moderator
Moderator
Posts: 3396
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Re: C++ SDK for 3D Spacenavigator

Post by ngomes »

Hi frist,
frist wrote: Tue Oct 20, 2020 5:49 am is the old version 3.x SDK available somewhere?
Send a request to the API Support team. The contact details are available here (login required). They should be able to help out.
frist
Posts: 5
Joined: Tue Oct 20, 2020 5:37 am

Re: C++ SDK for 3D Spacenavigator

Post by frist »

Hi ngomes,
I did and received a download link for the latest version 3 DSK. Thanks.

CU
flo
Post Reply