Link of Event Handlers to Connexion Device - Receive Events

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

Moderator: Moderators

Link of Event Handlers to Connexion Device - Receive Events

Postby rodrigo.seabra » Thu Jun 19, 2008 10:52 am

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

Postby rodrigo.seabra » Fri Jun 20, 2008 6:57 am

How I do to receive events of device???
rodrigo.seabra
 
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Postby ngomes » Fri Jun 20, 2008 8:13 am

Hi rodrigo.seabra,

Perhaps this The Code Project article can be useful for you.
Nuno Gomes
ngomes
Moderator
Moderator
 
Posts: 1656
Joined: Mon Nov 27, 2006 7:22 am
Location: EU

Postby rodrigo.seabra » Mon Jun 23, 2008 11:59 am

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.
rodrigo.seabra
 
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am


Return to Developer's Forum for Windows

Who is online

Users browsing this forum: spectral and 0 guests