PSMoveSteamVRBridge
utils.h
1 #pragma once
2 #include "openvr_driver.h"
3 #include "PSMoveClient_CAPI.h"
4 #include <string>
5 #include <vector>
6 
7 // Platform specific includes
8 #if defined( _WIN32 )
9 #include <windows.h>
10 #include <direct.h>
11 #define getcwd _getcwd // suppress "deprecation" warning
12 #else
13 #include <unistd.h>
14 #endif
15 
16 #if _MSC_VER
17 #define strcasecmp(a, b) stricmp(a,b)
18 #pragma warning (disable: 4996) // 'This function or variable may be unsafe': snprintf
19 #define snprintf _snprintf
20 #endif
21 
22 namespace steamvrbridge {
23 
24  class Utils {
25  public:
26  static int find_index_of_string_in_table(const char **string_table, const int string_table_count, const char *string);
27  static std::string Path_StripFilename(const std::string & sPath, char slash);
28  static std::string Path_GetThisModulePath();
29  static std::string Path_GetHomeDirectory();
30  static std::string Path_GetPSMoveSteamVRBridgeInstallPath(const class ServerDriverConfig *config);
31  static std::string Path_GetPSMoveSteamVRBridgeDriverRootPath(const class ServerDriverConfig *config);
32  static std::string Path_GetPSMoveSteamVRBridgeDriverBinPath(const class ServerDriverConfig *config);
33  static std::string Path_GetPSMoveSteamVRBridgeDriverResourcesPath(const class ServerDriverConfig *config);
34  static std::string Path_GetPSMoveServiceInstallPath(const class ServerDriverConfig *config);
35  static bool Path_CreateDirectory(const std::string &path);
36  static bool Path_FileExists(const std::string& filename);
37  static bool IsProcessRunning(const std::string &processName);
38  static bool LaunchProcess(const std::string &processPath, const std::string &processName, const std::vector<std::string> &args);
39  static bool GetHMDDeviceIndex(vr::TrackedDeviceIndex_t *out_hmd_device_index);
40  static bool GetTrackedDevicePose(const vr::TrackedDeviceIndex_t device_index, PSMPosef *out_device_pose);
41  static PSMQuatf ExtractHMDYawQuaternion(const PSMQuatf & q);
42  static PSMQuatf ExtractPSMoveYawQuaternion(const PSMQuatf & q);
43  // Takes a given controller position vector, applies a given quartenian rotation and sets the result to a given output position vector.
44  static void GetMetersPosInRotSpace(const PSMQuatf * rotation, PSMVector3f * out_position, const PSMPSMove & view);
45 
46  // Returns the HMD pose in meters.
47  // Throws a std::exception when HMD index or HMD pose can't be obtained.
48  static PSMPosef Utils::GetHMDPoseInMeters();
49 
50  // Returns a PSM pose of the controller aligned to the HMD tracking space. Returns NULL pointer when
51  // HMD index or pose can't be obtained.
52  static PSMPosef Utils::RealignHMDTrackingSpace(PSMQuatf controllerOrientationInHmdSpaceQuat,
53  PSMVector3f controllerLocalOffsetFromHmdPosition,
54  PSMControllerID controllerId,
55  PSMPosef hmd_pose_meters,
56  bool useControllerOrientation);
57  static PSMQuatf openvrMatrixExtractPSMQuatf(const vr::HmdMatrix34_t &openVRTransform);
58  static PSMQuatf psmMatrix3fToPSMQuatf(const PSMMatrix3f &psmMat);
59  static float psmVector3fDistance(const PSMVector3f &a, const PSMVector3f &b);
60  static PSMVector3f psmVector3fLerp(const PSMVector3f &a, const PSMVector3f &b, float u);
61  static PSMVector3f openvrMatrixExtractPSMVector3f(const vr::HmdMatrix34_t &openVRTransform);
62  static PSMPosef openvrMatrixExtractPSMPosef(const vr::HmdMatrix34_t &openVRTransform);
63  static std::string PSMVector3fToString(const PSMVector3f& position);
64  static std::string PSMQuatfToString(const PSMQuatf& rotation);
65  static std::string PSMPosefToString(const PSMPosef& pose);
66  static void GenerateTrackerSerialNumber(char *p, int psize, int tracker);
67  static void GenerateControllerSteamVRIdentifier(char *p, int psize, int controller);
68  };
69 }
Provides printf-style line logging via the vr::IVRDriverLog interface provided by SteamVR during init...
Definition: config.cpp:18
Definition: settings_util.h:8
Definition: utils.h:24