Skip to content

Commit

Permalink
Merge pull request #4 from Prof-Butts/UDP
Browse files Browse the repository at this point in the history
Refresh the master branch with the latest changes from the UDP branch.
  • Loading branch information
Prof-Butts authored Nov 28, 2020
2 parents ba55185 + 2e634e6 commit bd85daa
Show file tree
Hide file tree
Showing 18 changed files with 2,273 additions and 179 deletions.
23 changes: 21 additions & 2 deletions FreePIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ void log_debug(const char *format, ...);

typedef UINT32(__cdecl *freepie_io_6dof_slots_fun_type)();
typedef INT32(__cdecl *freepie_io_6dof_read_fun_type)(UINT32 index, UINT32 length, freepie_io_6dof_data *output);
typedef INT32(__cdecl *freepie_io_6dof_write_fun_type)(UINT32 index, UINT32 length, freepie_io_6dof_data *data);

freepie_io_6dof_slots_fun_type freepie_io_6dof_slots = NULL;
freepie_io_6dof_read_fun_type freepie_io_6dof_read = NULL;
freepie_io_6dof_write_fun_type freepie_io_6dof_write = NULL;

bool g_bFreePIELoaded = false, g_bFreePIEInitialized = false;
bool g_bFreePIELoaded = false, g_bFreePIEInitialized = false, g_bFreePIEAlreadyInitialized = false;
freepie_io_6dof_data g_FreePIEData;
HMODULE hFreePIE = NULL;

bool InitFreePIE() {
LONG lRes = ERROR_SUCCESS;
char regvalue[1024];
DWORD size = 1024;

if (g_bFreePIEAlreadyInitialized) {
log_debug("FreePIE already initialized");
return true;
}

log_debug("Initializing FreePIE");

lRes = RegGetValueA(HKEY_CURRENT_USER, "Software\\FreePIE", "path", RRF_RT_ANY, NULL, regvalue, &size);
Expand All @@ -40,9 +48,13 @@ bool InitFreePIE() {
log_debug("FreePIE loaded");
freepie_io_6dof_slots = (freepie_io_6dof_slots_fun_type)GetProcAddress(hFreePIE, "freepie_io_6dof_slots");
freepie_io_6dof_read = (freepie_io_6dof_read_fun_type)GetProcAddress(hFreePIE, "freepie_io_6dof_read");
freepie_io_6dof_write = (freepie_io_6dof_write_fun_type)GetProcAddress(hFreePIE, "freepie_io_6dof_write");

if (freepie_io_6dof_slots == NULL || freepie_io_6dof_read == NULL) {
if (freepie_io_6dof_slots == NULL || freepie_io_6dof_read == NULL ||
freepie_io_6dof_write == NULL) {
log_debug("Could not load all of FreePIE's functions");
log_debug("read: 0x%x", freepie_io_6dof_read);
log_debug("write: 0x%x", freepie_io_6dof_write);
return false;
}
g_bFreePIELoaded = true;
Expand All @@ -55,6 +67,7 @@ bool InitFreePIE() {
log_debug("Could not load FreePIE");
}
g_bFreePIEInitialized = true;
g_bFreePIEAlreadyInitialized = true;
return true;
}

Expand All @@ -73,3 +86,9 @@ bool ReadFreePIE(int slot) {
}
return true;
}

void WriteFreePIE(int slot) {
int error = freepie_io_6dof_write(slot, 1, &g_FreePIEData);
if (error != 0)
log_debug("Could not write to FreePIE, error: 0x%x", error);
}
1 change: 1 addition & 0 deletions FreePIE.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ extern freepie_io_6dof_data g_FreePIEData;
bool InitFreePIE();
void ShutdownFreePIE();
bool ReadFreePIE(int slot);
void WriteFreePIE(int slot);
Binary file modified Hook_XWACockpitLook.aps
Binary file not shown.
Binary file modified Hook_XWACockpitLook.rc
Binary file not shown.
7 changes: 5 additions & 2 deletions Hook_XWACockpitLook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;openvr_api.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy /Y $(TargetPath) "c:\Program Files (x86)\GOG Galaxy\Games\Star Wars - X-Wing Alliance"
copy /Y $(TargetPath) "C:\Program Files (x86)\Steam\steamapps\common\Star Wars X-Wing Alliance"</Command>
<Command>copy /Y $(TargetPath) "c:\Program Files (x86)\GOG Galaxy\Games\Star Wars - X-Wing Alliance"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -147,7 +146,9 @@ copy /Y $(TargetPath) "C:\Program Files (x86)\Steam\steamapps\common\Star Wars X
<ClCompile Include="cockpitlook.cpp" />
<ClCompile Include="Matrices.cpp" />
<ClCompile Include="SteamVR.cpp" />
<ClCompile Include="Telemetry.cpp" />
<ClCompile Include="TrackIR.cpp" />
<ClCompile Include="UDP.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="FreePIE.h" />
Expand All @@ -159,7 +160,9 @@ copy /Y $(TargetPath) "C:\Program Files (x86)\Steam\steamapps\common\Star Wars X
<ClInclude Include="cockpitlook.h" />
<ClInclude Include="SteamVR.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="Telemetry.h" />
<ClInclude Include="TrackIR.h" />
<ClInclude Include="UDP.h" />
<ClInclude Include="Vectors.h" />
<ClInclude Include="XWAEnums.h" />
<ClInclude Include="XWAFramework.h" />
Expand Down
12 changes: 12 additions & 0 deletions Hook_XWACockpitLook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<ClCompile Include="Matrices.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="UDP.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Telemetry.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Hex.h">
Expand Down Expand Up @@ -80,6 +86,12 @@
<ClInclude Include="Vectors.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="UDP.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Telemetry.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Hook_XWACockpitLook.rc">
Expand Down
36 changes: 28 additions & 8 deletions SteamVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bool InitSteamVR()
return false;
}
log_debug("VR runtime loaded");

g_bSteamVRInitialized = true;
return true;
}
Expand Down Expand Up @@ -104,7 +105,7 @@ void quatToEuler(vr::HmdQuaternionf_t q, float *yaw, float *roll, float *pitch)
*roll = atan2(2.0f * q.x*q.w - 2.0f * q.y*q.z, 1.0f - 2.0f * sqx - 2.0f * sqz);
}

bool GetSteamVRPositionalData(float *yaw, float *pitch)
bool GetSteamVRPositionalData(float *yaw, float *pitch, float *x, float *y, float *z)
{
if (g_pHMD == NULL) {
log_debug("GetSteamVRPositional Data with g_pHMD = NULL");
Expand All @@ -127,16 +128,35 @@ bool GetSteamVRPositionalData(float *yaw, float *pitch)
vr::VRControllerState_t state;
if (g_pHMD->GetControllerState(unDevice, &state, sizeof(state)))
{
vr::TrackedDevicePose_t trackedDevicePose;
//vr::TrackedDevicePose_t trackedDevicePose;
vr::TrackedDevicePose_t trackedDevicePoseArray[vr::k_unMaxTrackedDeviceCount];
vr::HmdMatrix34_t poseMatrix;
vr::HmdQuaternionf_t q;
vr::ETrackedDeviceClass trackedDeviceClass = vr::VRSystem()->GetTrackedDeviceClass(unDevice);
//vr::ETrackedDeviceClass trackedDeviceClass = vr::VRSystem()->GetTrackedDeviceClass(unDevice);

//vr::VRSystem()->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, 0.029, &trackedDevicePose, 1);

/* Get the last pose predicted for the current frame during WaitGetPoses for the last frame.
This should remove jitter although it may introduce some error due to the prediction when doing quick changes of velocity/direction.
Also, it removes the need to deal with prediction time calculations. All is handled by WaitGetPoses as part of running start algorithm.
*/
vr::VRCompositor()->GetLastPoses(NULL, 0, trackedDevicePoseArray, vr::k_unMaxTrackedDeviceCount);
//vr::VRCompositor()->GetLastPoses(trackedDevicePoseArray, vr::k_unMaxTrackedDeviceCount, NULL, 0);

vr::VRSystem()->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, 0, &trackedDevicePose, 1);
poseMatrix = trackedDevicePose.mDeviceToAbsoluteTracking; // This matrix contains all positional and rotational data.
q = rotationToQuaternion(trackedDevicePose.mDeviceToAbsoluteTracking);
quatToEuler(q, yaw, pitch, &roll);
return true;
if (trackedDevicePoseArray[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid) {
poseMatrix = trackedDevicePoseArray[vr::k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking; // This matrix contains all positional and rotational data.
q = rotationToQuaternion(poseMatrix);
quatToEuler(q, yaw, pitch, &roll);
*x = poseMatrix.m[0][3];
*y = poseMatrix.m[1][3];
*z = poseMatrix.m[2][3];
return true;
}
else
{
log_debug("[DBG] HMD pose not valid");
return false;
}
}
return false;
}
2 changes: 1 addition & 1 deletion SteamVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

bool InitSteamVR();
void ShutdownSteamVR();
bool GetSteamVRPositionalData(float *yaw, float *pitch);
bool GetSteamVRPositionalData(float *yaw, float *pitch, float *x, float *y, float *z);
Loading

0 comments on commit bd85daa

Please sign in to comment.