@@ -44,7 +44,6 @@ std::thread *pRRthread = NULL;
4444void RazorIMURead ()
4545{
4646 DWORD bytesRead;
47- memset (&RazorIMU, 0 , sizeof (RazorIMU));
4847
4948 while (HMDConnected) {
5049 ReadFile (hSerial, &RazorIMU, sizeof (RazorIMU), &bytesRead, 0 );
@@ -88,18 +87,24 @@ void RazorInit(){
8887 if (SetCommState (hSerial, &dcbSerialParams))
8988 {
9089 HMDConnected = true ;
91- unsigned long ulCommErr = 0 ;
92- ClearCommError (hSerial, &ulCommErr, NULL );
90+ PurgeComm (hSerial, PURGE_TXCLEAR | PURGE_RXCLEAR);
9391 pRRthread = new std::thread (RazorIMURead);
9492 }
9593 }
9694 }
9795 }
9896}
9997
100- double MyOffset (float f, float f2)
98+ float MyOffset (float f, float f2)
10199{
102- return fmod (f - f2, 180 );
100+ f -= f2;
101+ if (f < -180 ) {
102+ f += 360 ;
103+ } else if (f > 180 ) {
104+ f -= 360 ;
105+ }
106+
107+ return f;
103108}
104109
105110BOOL APIENTRY DllMain (HMODULE hModule,
@@ -117,8 +122,6 @@ BOOL APIENTRY DllMain(HMODULE hModule,
117122 delete pRRthread;
118123 pRRthread = nullptr ;
119124 }
120- unsigned long ulCommErr = 0 ;
121- ClearCommError (hSerial, &ulCommErr, NULL );
122125 CloseHandle (hSerial);
123126 }
124127 break ;
@@ -128,7 +131,7 @@ BOOL APIENTRY DllMain(HMODULE hModule,
128131}
129132
130133#define StepPos 0.0033 ;
131- #define StepRot 0.2 ;
134+ #define StepRot 0.1 ;
132135
133136DLLEXPORT DWORD __stdcall GetHMDData (__out THMD *myHMD)
134137{
@@ -139,22 +142,22 @@ DLLEXPORT DWORD __stdcall GetHMDData(__out THMD *myHMD)
139142
140143 if (HMDConnected) {
141144
142- if ((GetAsyncKeyState (VK_NUMPAD8) & 0x8000 ) != 0 ) fPos [2 ] = fPos [ 2 ] - StepPos;
143- if ((GetAsyncKeyState (VK_NUMPAD2) & 0x8000 ) != 0 ) fPos [2 ] = fPos [ 2 ] + StepPos;
145+ if ((GetAsyncKeyState (VK_NUMPAD8) & 0x8000 ) != 0 ) fPos [2 ] -= StepPos;
146+ if ((GetAsyncKeyState (VK_NUMPAD2) & 0x8000 ) != 0 ) fPos [2 ] += StepPos;
144147
145- if ((GetAsyncKeyState (VK_NUMPAD4) & 0x8000 ) != 0 ) fPos [0 ] = fPos [ 0 ] - StepPos;
146- if ((GetAsyncKeyState (VK_NUMPAD6) & 0x8000 ) != 0 ) fPos [0 ] = fPos [ 0 ] + StepPos;
148+ if ((GetAsyncKeyState (VK_NUMPAD4) & 0x8000 ) != 0 ) fPos [0 ] -= StepPos;
149+ if ((GetAsyncKeyState (VK_NUMPAD6) & 0x8000 ) != 0 ) fPos [0 ] += StepPos;
147150
148- if ((GetAsyncKeyState (VK_PRIOR) & 0x8000 ) != 0 ) fPos [1 ] = fPos [ 1 ] + StepPos;
149- if ((GetAsyncKeyState (VK_NEXT) & 0x8000 ) != 0 ) fPos [1 ] = fPos [ 1 ] - StepPos;
151+ if ((GetAsyncKeyState (VK_PRIOR) & 0x8000 ) != 0 ) fPos [1 ] += StepPos;
152+ if ((GetAsyncKeyState (VK_NEXT) & 0x8000 ) != 0 ) fPos [1 ] -= StepPos;
150153
151154 // Yaw fixing
152- if ((GetAsyncKeyState (VK_NUMPAD1) & 0x8000 ) != 0 ) yprOffset[0 ] = yprOffset[0 ] + StepRot;
153- if ((GetAsyncKeyState (VK_NUMPAD3) & 0x8000 ) != 0 ) yprOffset[0 ] = yprOffset[0 ] - StepRot;
155+ if ((GetAsyncKeyState (VK_NUMPAD1) & 0x8000 ) != 0 && yprOffset[0 ] < 180 ) yprOffset[0 ] += StepRot;
156+ if ((GetAsyncKeyState (VK_NUMPAD3) & 0x8000 ) != 0 && yprOffset[0 ] > - 180 ) yprOffset[0 ] -= StepRot;
154157
155158 // Roll fixing
156- if ((GetAsyncKeyState (VK_NUMPAD7) & 0x8000 ) != 0 ) yprOffset[2 ] = yprOffset[2 ] + StepRot;
157- if ((GetAsyncKeyState (VK_NUMPAD9) & 0x8000 ) != 0 ) yprOffset[2 ] = yprOffset[2 ] - StepRot;
159+ if ((GetAsyncKeyState (VK_NUMPAD7) & 0x8000 ) != 0 && yprOffset[2 ] < 180 ) yprOffset[2 ] += StepRot;
160+ if ((GetAsyncKeyState (VK_NUMPAD9) & 0x8000 ) != 0 && yprOffset[2 ] > - 180 ) yprOffset[2 ] -= StepRot;
158161
159162 if ((GetAsyncKeyState (VK_SUBTRACT) & 0x8000 ) != 0 ) {
160163 fPos [0 ] = 0 ;
0 commit comments