Skip to content

Commit 1099f77

Browse files
committed
Fix offset
1 parent 4dc4fd4 commit 1099f77

9 files changed

Lines changed: 58 additions & 26 deletions

File tree

144 Bytes
Binary file not shown.
142 Bytes
Binary file not shown.

C++/FreeTrack/FreeTrack.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,17 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
144144
return true;
145145
}
146146

147-
double MyOffset(float f, double f2)
147+
double MyOffset(float f, float f2)
148148
{
149-
return fmod(f - f2, 180);
149+
f -= f2;
150+
if (f < -180) {
151+
f += 360;
152+
}
153+
else if (f > 180) {
154+
f -= 360;
155+
}
156+
157+
return f;
150158
}
151159

152160
double RadToDeg(float r) {

C++/FreeTrack/FreeTrack.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ProjectGuid>{BC41B8A1-5C3F-415F-9CBC-D0AAEF7E29C0}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>FreeTrack</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

C++/RazorIMU/RazorIMU.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ std::thread *pRRthread = NULL;
4444
void 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

105110
BOOL 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

133136
DLLEXPORT 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;

C++/RazorIMU/RazorIMU.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ProjectGuid>{9A769781-B09C-4A56-AF94-DBE2E9D32C4D}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>RazorIMU</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

C++/RazorIMU/stdafx.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
// stdafx.h: включаемый файл для стандартных системных включаемых файлов
2+
// или включаемых файлов для конкретного проекта, которые часто используются, но
3+
// не часто изменяются
4+
//
5+
16
#pragma once
27

38
#include "targetver.h"
49

5-
#define WIN32_LEAN_AND_MEAN
6-
10+
#define WIN32_LEAN_AND_MEAN // Исключите редко используемые компоненты из заголовков Windows
11+
// Файлы заголовков Windows:
712
#include <windows.h>
13+
14+
15+
16+
// TODO: Установите здесь ссылки на дополнительные заголовки, требующиеся для программы

C++/RazorIMU/targetver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#pragma once
22

3+
// Включение SDKDDKVer.h обеспечивает определение самой последней доступной платформы Windows.
4+
5+
// Если требуется выполнить сборку приложения для предыдущей версии Windows, включите WinSDKVer.h и
6+
// задайте для макроса _WIN32_WINNT значение поддерживаемой платформы перед включением SDKDDKVer.h.
7+
38
#include <SDKDDKVer.h>

Delphi/Razor IMU/RazorIMU.dpr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,20 @@ end;
6363

6464
function MyOffset(f, f2: double): double;
6565
begin
66-
Result:=fmod(f - f2, 180);
66+
f:=f - f2;
67+
68+
if (f < -180) then
69+
f:=f + 360
70+
else if (f > 180) then
71+
f:=f - 360;
72+
73+
Result:=f;
6774
end;
6875

6976
function GetHMDData(out myHMD: THMD): DWORD; stdcall;
7077
const
7178
StepPos = 0.0033;
72-
StepRot = 0.2;
79+
StepRot = 0.1;
7380
begin
7481
//For some games need position tracking which is not have in Razor IMU.
7582
if GetAsyncKeyState(VK_NUMPAD8) <> 0 then PosZ:=PosZ - StepPos;

0 commit comments

Comments
 (0)