Link of Event Handlers to Connexion Device - Receive Events

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

Moderator: Moderators

Post Reply
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Link of Event Handlers to Connexion Device - Receive Events

Post by rodrigo.seabra »

Hi, I have a doubt. In my application, I connected the SpaceNavigator, but I don't understand how to link the event handlers to connexion device. Someone could help me?

Code: Select all

#include "spacenavigator.h"

#define UnknownDevice 0

using namespace std;

CComPtr<IUnknown> _3DxDevice;
CComPtr<ISensor> g3DSensor;
CComPtr<IKeyboard> g3DKeyboard;
CComPtr<IAngleAxis> pRotation;
CComPtr<IVector3D> pTranslation;

SpaceNavigator::SpaceNavigator() {
	translation.set(0.0,0.0,0.0);
	rotation.set(0.0,0.0,0.0);
	initDevice();

	for(int i = 0; i < 6; i++) absoluteposition[i] = 0;
}

void SpaceNavigator::initDevice() {
	long type;
	HRESULT hr = :: CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
	if (!SUCCEEDED(hr)) { 
         cout << "Fail on device connexion!" << endl; 
         return; 
    } 

	hr = _3DxDevice.CoCreateInstance(__uuidof(Device));
	if (SUCCEEDED(hr)) {
		CComPtr<ISimpleDevice> _3DxSimpleDevice;
		hr = _3DxDevice.QueryInterface(&_3DxSimpleDevice);
		hr = _3DxSimpleDevice -> get_Type(&type); 
		if (type == UnknownDevice) cout << "Space Navigator not found!";
		if (SUCCEEDED(hr) && type != UnknownDevice) {
			g3DSensor = _3DxSimpleDevice -> Sensor;
            g3DKeyboard = _3DxSimpleDevice -> Keyboard;
			_3DxSimpleDevice -> Connect();
			cout << "SpaceNavigator found...";
		}
	}
}

void SpaceNavigator::updateDevice() {
	
	if (g3DSensor) {
		try {
			pRotation = g3DSensor -> Rotation;
			pTranslation = g3DSensor -> Translation;
			absoluteposition[0] += pTranslation -> X; absoluteposition[1] += pTranslation -> Y;
			absoluteposition[2] += pTranslation -> Z;
			cout << "Translação: " << absoluteposition[0] << " " << absoluteposition[1] << " " << absoluteposition[2] <<endl> X; absoluteposition[4] += pRotation -> Y;
			absoluteposition[5] += pRotation -> Z;
			cout << "Rotação: " << absoluteposition[3] << " " << absoluteposition[4] << " " << absoluteposition[5] << endl;

			
		}
		catch (_com_error &e) {
			cout << "Erro de comunicação..." << endl;
		}
	}
}
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

How I do to receive events of device???
ngomes
Moderator
Moderator
Posts: 3344
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

Hi rodrigo.seabra,

Perhaps this The Code Project article can be useful for you.
Nuno Gomes
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Hi ngomes,

I know how to operate the event handlers in general, however, for most it has tried, I could not do the correct use of methods hr = __hook (...) mentioned in the documentation of 3DxInput API.

Me seems that I need them to capture the events generated by the SpaceNavigator. Considering the two methods made available, I would like to know if anyone has any idea how could implement the event handlers in my case.

Thanks.
Post Reply