MS VS 2005 - sample project

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

Moderator: Moderators

Post Reply
mikeda
Posts: 4
Joined: Tue Jul 31, 2007 2:04 am

MS VS 2005 - sample project

Post by mikeda »

hello...

i've got a big problem concerning the sample projects... i downloaded both of them and could compile them without any problems...

but when i tried to make a new console project based on those sample projects they simply don't do what I like them to do... (printing numbers which represent forces and momentums applied to the cap on the screen...)

I could compile them and where I'm printing the devicetype it's 6 (for spacenavigator) so the connection to the device should actually be established... but why do all the other values remain 0 even if i move the cap... ???

I'm asking kindly if anybody could explain me what I'm doing wrong... ?

Has anybody got a very basic hello world project which could be shared somehow ?

Code: Select all

// testprojekt.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"
#include "atlbase.h"
#include "objbase.h"
#include <atlstr>
#include "math3d.h"
#include <iostream>

using namespace std;

#define ScaleRotation		1024.0
#define ScaleTranslation	512.0





int _tmain(int argc, _TCHAR* argv[])
{
	double Sensitivity = 1.0;
	CComPtr<ISensor> g3DSensor;
	CComPtr<IKeyboard> g3DKeyboard;
	__int64 gKeyStates=0;
	// ------------------ init ----------------


	HRESULT hr=CoInitializeEx(NULL, COINIT_APARTMENTTHREADED );
	
	if (!SUCCEEDED(hr))
	{
		CString strError;
		strError.FormatMessage (_T("Error 0x%x"), hr);
		::MessageBox (NULL, strError, _T("CoInitializeEx failed"), MB_ICONERROR|MB_OK);
		return FALSE;
	}


	CComPtr<IUnknown> _3DxDevice;

	// Create the device object
	hr = _3DxDevice.CoCreateInstance(__uuidof(Device));


	DWORD error=GetLastError();
	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;
			g3DKeyboard = _3DxSimpleDevice->Keyboard;

			// Associate a configuration with this device
			//_3DxSimpleDevice->LoadPreferences(_T("SpaceMouse"));
			// Connect to the driver
			_3DxSimpleDevice->Connect();

			cout << "*********************************************************" <<endl>get_Type(&type);
			cout << "Devicetype : " << type << endl;
			cout << "*********************************************************" << endl;
			Sleep(4000);
			// Create timer used to poll the 3dconnexion device

		}
	}

	// --------------- data --------------------


	//static DWORD s_dwLastDraw = 0;
	double *rotx = new double();

	do {
		//Sleep(25);
		system("cls");		

    if (g3DSensor)
		{
			try {

				CComPtr<IAngleAxis> pRotation = g3DSensor->Rotation;
				CComPtr<IVector3D>  pTranslation = g3DSensor->Translation;

				//**********************************************************************
				// Check if the cap is still displaced
			//	cout << "angle " <<pRotation>Angle << endl;
			//	cout << "trans " <<pTranslation>Length <<endl>get_X(rotx);
				cout << "rotx : " << *rotx <<endl>get_Length(tr);
				cout << "trans " << *tr <<endl>Angle;
				if (pRotation->Angle > 0. || pTranslation->Length > 0.)
				{

					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 );
					//        if ( FrameCube.MathTranslation[2] > NearPosition )
					//           FrameCube.MathTranslation[2] = NearPosition;

					//       if (MainhWnd)
					//          DisplayCube( MainhWnd, &FrameCube, &VGAVideo );
				}
				else
//					s_dwLastDraw = 0;

				pRotation.Release();
				pTranslation.Release();
			}

			//******************************************************************* 

			catch (...)
			{
				// Some sort of exception handling
			}
		}
	} while (1);

	// ------------------- deinit --------------------
	//    CComPtr<ISimpleDevice> _3DxDevice;


	// Release the sensor and keyboard interfaces
	if (g3DSensor)
	{
		//    g3DSensor->get_Device((IDispatch**)&_3DxDevice);
		g3DSensor.Release();
	}

	if (g3DKeyboard)
		g3DKeyboard.Release();

	if (_3DxDevice)
	{
		// Disconnect it from the driver
		//  _3DxDevice->Disconnect();
		_3DxDevice.Release();
	}


	return 0;
}
ngomes
Moderator
Moderator
Posts: 3344
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Post by ngomes »

(Moved topic to the Windows Developer's Forum.)


Hi mikeda,

Your application is required to have a message pump. You can search on this Forum for some suggestions.
Nuno Gomes
Post Reply