@@ -11,26 +11,34 @@ namespace alvr_chaperone {
1111using namespace alvr_chaperone ;
1212#endif
1313
14- static std::mutex chaperone_mutex;
14+ std::mutex chaperone_mutex;
1515
16- #ifdef __linux__
17- vr::HmdMatrix34_t GetRawZeroPose () {
18- vr::HmdMatrix34_t out = {};
16+ void InitChaperoneClient () {
17+ #ifndef __APPLE__
1918 std::unique_lock<std::mutex> lock (chaperone_mutex);
19+
2020 vr::EVRInitError error;
2121 vr::VR_Init (&error, vr::VRApplication_Utility);
22+
2223 if (error != vr::VRInitError_None) {
23- Warn (" Failed to init OpenVR client to get raw zero pose ! Error: %d" , error);
24- return out ;
24+ Warn (" Failed to init OpenVR client to update Chaperone boundary ! Error: %d" , error);
25+ return ;
2526 }
26- out = vr::VRSystem ()->GetRawZeroPoseToStandingAbsoluteTrackingPose ();
27- vr::VR_Shutdown ();
28- return out;
27+ #endif
2928}
29+
30+ void ShutdownChaperoneClient () {
31+ #ifndef __APPLE__
32+ std::unique_lock<std::mutex> lock (chaperone_mutex);
33+
34+ vr::VR_Shutdown ();
3035#endif
36+ }
3137
32- void SetChaperone (float areaWidth, float areaHeight) {
38+ void SetChaperoneArea (float areaWidth, float areaHeight) {
3339#ifndef __APPLE__
40+ std::unique_lock<std::mutex> lock (chaperone_mutex);
41+
3442 const vr::HmdMatrix34_t MATRIX_IDENTITY = {
3543 {{1.0 , 0.0 , 0.0 , 0.0 }, {0.0 , 1.0 , 0.0 , 0.0 }, {0.0 , 0.0 , 1.0 , 0.0 }}};
3644
@@ -45,16 +53,6 @@ void SetChaperone(float areaWidth, float areaHeight) {
4553 perimeterPoints[3 ][0 ] = 1 .0f * areaWidth;
4654 perimeterPoints[3 ][1 ] = -1 .0f * areaHeight;
4755
48- std::unique_lock<std::mutex> lock (chaperone_mutex);
49-
50- vr::EVRInitError error;
51- vr::VR_Init (&error, vr::VRApplication_Utility);
52-
53- if (error != vr::VRInitError_None) {
54- Warn (" Failed to init OpenVR client to update Chaperone boundary! Error: %d" , error);
55- return ;
56- }
57-
5856 vr::VRChaperoneSetup ()->RoomSetupStarting ();
5957 vr::VRChaperoneSetup ()->SetWorkingPerimeter (
6058 reinterpret_cast <vr::HmdVector2_t *>(perimeterPoints), 4 );
@@ -66,7 +64,21 @@ void SetChaperone(float areaWidth, float areaHeight) {
6664 // Hide SteamVR Chaperone
6765 vr::VRSettings ()->SetFloat (
6866 vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_FadeDistance_Float, 0 .0f );
67+ #endif
68+ }
6969
70+ #ifdef __linux__
71+ vr::HmdMatrix34_t GetRawZeroPose () {
72+ vr::HmdMatrix34_t out = {};
73+ std::unique_lock<std::mutex> lock (chaperone_mutex);
74+ vr::EVRInitError error;
75+ vr::VR_Init (&error, vr::VRApplication_Utility);
76+ if (error != vr::VRInitError_None) {
77+ Warn (" Failed to init OpenVR client to get raw zero pose! Error: %d" , error);
78+ return out;
79+ }
80+ out = vr::VRSystem ()->GetRawZeroPoseToStandingAbsoluteTrackingPose ();
7081 vr::VR_Shutdown ();
71- #endif
72- }
82+ return out;
83+ }
84+ #endif
0 commit comments