I want to use the SpaceNavigator with an osg application.
I read the 3Dpolling example and modified it to register the data in a text file.
I thought it would be easy to integrate the same code into the application but I have some problems.
Code: Select all
MyManipulator::MyManipulator(osg::Vec3 init_pos){
_thrown = false;
_generalScale = 1.0f;
_face = 0; //init face ref
_init_pos = init_pos;
HRESULT hr1=::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED );
HRESULT hr;
CComPtr<IUnknown> _3DxDevice;
// Create the device object
hr = _3DxDevice.CoCreateInstance(__uuidof(Device));
if (SUCCEEDED(hr))
{
CComPtr<ISimpleDevice> _3DxSimpleDevice;
hr = _3DxDevice.QueryInterface(&_3DxSimpleDevice);
if (SUCCEEDED(hr))
{
// Get the interfaces to the sensor and the keyboard;
g3DSensor = _3DxSimpleDevice->Sensor;
// Associate a configuration with this device
_3DxSimpleDevice->LoadPreferences(_T("Cube3DPolling"));
// Connect to the driver
_3DxSimpleDevice->Connect();
cout << "created" << endl;
}
}
the message "created" is displayed
Code: Select all
bool MyManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us){
if (ea.getHandled()) return false;
switch(ea.getEventType()) {
case(GUIEventAdapter::FRAME):
_frame(ea,us);
calc3DMovement();
if (calc3DMovement()) us.requestRedraw();
return false;
}
the calc3DMovement function is defined as following :
Code: Select all
bool MyManipulator::calc3DMovement( ){
//static DWORD s_dwLastDraw = 0;
if (g3DSensor)
{
try {
CComPtr<IAngleAxis> pRotation = g3DSensor->Rotation;
CComPtr<IVector3D> pTranslation = g3DSensor->Translation;
/* double timeFactor = 1.;*/
/*DWORD dwNow = ::GetTickCount();*/
/* if (s_dwLastDraw)
timeFactor = (double)(dwNow-s_dwLastDraw)/g3DSensor->Period;
s_dwLastDraw = dwNow;*/
pTranslation->Length /= ScaleTranslation*Sensitivity;
pRotation->Angle /= ScaleRotation*Sensitivity;
MathFrame FrameTransRot;
MathFrameTranslation(&FrameTransRot, pTranslation->X, pTranslation->Y, pTranslation->Z);
MathFrameRotation( &FrameTransRot, pRotation->X * pRotation->Angle,
pRotation->Y * pRotation->Angle,
pRotation->Z * pRotation->Angle );
MathFrameMultiplication( &FrameTransRot, &FrameCube, &FrameCube );
cout << "ok" <<pTranslation>X <<endl> NearPosition )
FrameCube.MathTranslation[2] = NearPosition;*/
}
catch (...)
{
// Some sort of exception handling
}
}
return true;
}
Thank you for you help[/quote]