space Navigator and openScenceGraph application

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

Moderator: Moderators

mony84
Posts: 7
Joined: Mon May 19, 2008 8:10 am

space Navigator and openScenceGraph application

Post by mony84 »

hello,
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;
}

My problem is that I have the same value displayed each time the Frame event occurs.


Thank you for you help[/quote]
mony84
Posts: 7
Joined: Mon May 19, 2008 8:10 am

Post by mony84 »

I made a mistake when I copied the code of the 3rd fucntion :
the right code :

Code: Select all



bool MyManipulator::calc3DMovement( ){

//static DWORD s_dwLastDraw = 0;

  
   if (g3DSensor)
	   
   {
      try {

	     CComPtr<IAngleAxis> pRotation = g3DSensor->Rotation;
         CComPtr<IVector3D> pTranslation = g3DSensor->Translation;
		 cout <<g3DSensor>GetPeriod ( ) <<endl>Length /= ScaleTranslation;
            pRotation->Angle /= ScaleRotation;

            MathFrame FrameTransRot;    
			MathFrameTranslation(&FrameTransRot, pTranslation->X, pTranslation->Y, pTranslation->Z);
			MathFrameRotation( &FrameTransRot, 
			
			pRotation->X * pRotation->Angle, //	the real values of pitch, yaw, roll
            pRotation->Y * pRotation->Angle,
            pRotation->Z * pRotation->Angle );

         cout <<pTranslation>X << endl;
			
			MathFrameMultiplication( &FrameTransRot, &FrameCube/, &FrameCube );
			

         
	  }
      catch (...)
      {
         // Some sort of exception handling
      }
   }
   return true;
}

I still have the same value '0' displayed
ngomes
Moderator
Moderator
Posts: 3347
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

hi mony84,

You need to ensure that the thread where you create the object has a message loop. There are other topics in this Forum that address that problem.

This is a limitation on the current API. We will remove it in a later revision (public schedule not yet available).
Nuno Gomes
mony84
Posts: 7
Joined: Mon May 19, 2008 8:10 am

Post by mony84 »

thank you for your reply,

"message loop" : do you mean messages we add as output to view some parameter values?

if yes, I put for example

Code: Select all

cout << FrameTransRot.MathRotation[1][3]<<endl;
I tried with many other parameters and I get the same result : always "0" was diplayed.

If I misunderstood your message, could you please explain it to me?
ngomes
Moderator
Moderator
Posts: 3347
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

See here.

You need to create your 3DxInput objects in a thread that can create windows.
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Hi mony,

Currently, I'm also trying to develop an application with the OpenSceneGraph and the Space Navigator. I believe that I have the same problem you, as though to read the coordinates of the device, the thread that I created for this purpose is monopolizing the execution of the application.

The 3D application does not appear on the screen while the loop of thread is running. You achieved some progress? If so, we could switch codes in an attempt to solve our problem.

Maybe be interesting switched our emails to facilitate the exchange of our codes, what you think of the idea?

Thanks.
mony84
Posts: 7
Joined: Mon May 19, 2008 8:10 am

Post by mony84 »

Hi,

The problem is that we have to attach the SpaceNavigator to a window.

I tried to find how to attach the device to the viewer (osgViewer::Viewer) but I didn't succeed.

In the osg mailing list, I find a post where they suggest to use the vrpn and the osgvrpn libraries. I try to understand how it works but the problem is that there are few tutorials.

I prefer using the forum, so the experts may help us.

good luck
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Ok! Anyway, if you solve your problem I would like to see your code ... maybe I can adapt it to my case ...

Thanks and good luck for you too.
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Only a doubt...

I included the line "#import "progid:TDxInput.Device" embedded_idl no_namespace" in my stdafx.h header file, however, when I try to use the methods of the 3DxInput API, the compiler don
ngomes
Moderator
Moderator
Posts: 3347
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

rodrigo.seabra wrote:Anyone have any suggestion?
Did you try building one of the C++ samples?
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Yes, I tried. However, when I tried to compile the AtlCube3D example the compiler shows a message:

1>Compiling...
1>AtlCube3d.cpp
1>c:\doutorado\spacenavigator\exemplos\atlcube3d\src\atlcube3d.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug\AtlCube3d.pch': No such file or directory

What's happen?
ngomes
Moderator
Moderator
Posts: 3347
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

rodrigo.seabra wrote:fatal error C1083: Cannot open precompiled header file: 'Debug\AtlCube3d.pch': No such file or directory
You need to clean and rebuild the project.
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

I did this, however...

1>Compiling...
1>stdafx.cpp
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlbase.h(513) : warning C4996: '_vsnprintf': This function or variable may be unsafe. Consider using _vsnprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.
1> c:\programas\microsoft visual studio 8\vc\include\stdio.h(339) : see declaration of '_vsnprintf'
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlbase.h(537) : warning C4996: '_vsnprintf': This function or variable may be unsafe. Consider using _vsnprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.
1> c:\programas\microsoft visual studio 8\vc\include\stdio.h(339) : see declaration of '_vsnprintf'
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlbase.h(561) : warning C4996: '_vsnwprintf': This function or variable may be unsafe. Consider using _vsnwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.
1> c:\programas\microsoft visual studio 8\vc\include\wchar.h(719) : see declaration of '_vsnwprintf'
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlbase.h(584) : warning C4996: '_vsnwprintf': This function or variable may be unsafe. Consider using _vsnwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.
1> c:\programas\microsoft visual studio 8\vc\include\wchar.h(719) : see declaration of '_vsnwprintf'
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3242) : error C2065: '_Module' : undeclared identifier
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3242) : error C2228: left of '.Lock' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3244) : error C2228: left of '.Unlock' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3366) : error C2228: left of '.CreateInstance' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3373) : error C2228: left of '.Lock' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3375) : error C2228: left of '.Unlock' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3641) : error C2228: left of '.m_csTypeInfoHolder' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3658) : error C2228: left of '.AddTermFunc' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlcom.h(3667) : error C2228: left of '.m_csTypeInfoHolder' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlwin.h(155) : error C2228: left of '.GetModuleInstance' must have class/struct/union
1> type is ''unknown-type''
1>c:\programas\microsoft platform sdk for windows server 2003 r2\include\atl\atlwin.h(168) : error C2228: left of '.GetModuleInstance' must have class/struct/union
1> type is ''unknown-type''
1>c:\doutorado\spacenavigator\exemplos\atlcube3d\src\stdafx.h(37) : fatal error C1083: Cannot open include file: 'atltypes.h': No such file or directory
1>Build log was saved at "file://c:\Doutorado\SpaceNavigator\Exemplos\AtlCube3d\src\Debug\BuildLog.htm"
1>AtlCube3d - 12 error(s), 4 warning(s)
ngomes
Moderator
Moderator
Posts: 3347
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

Hi rodrigo.seabra,

The demos are Visual Studio 2005 projects. What are you using?
rodrigo.seabra
Posts: 44
Joined: Fri Apr 04, 2008 7:03 am

Post by rodrigo.seabra »

Hi ngomes,

I am using Visual C++ 2005 Express Edition.
Post Reply