1
1
#include " HMDDevice.hpp"
2
2
#include < Windows.h>
3
3
4
- TutorialDriver ::HMDDevice::HMDDevice (std::string serial):m_serial(serial)
4
+ ExampleDriver ::HMDDevice::HMDDevice (std::string serial):m_serial(serial)
5
5
{
6
6
}
7
7
8
- std::string TutorialDriver ::HMDDevice::serial ()
8
+ std::string ExampleDriver ::HMDDevice::getSerial ()
9
9
{
10
10
return this ->m_serial ;
11
11
}
12
12
13
- void TutorialDriver ::HMDDevice::update (std::vector<vr::VREvent_t> events )
13
+ void ExampleDriver ::HMDDevice::update ()
14
14
{
15
15
if (this ->m_deviceIndex == vr::k_unTrackedDeviceIndexInvalid)
16
16
return ;
17
17
18
- // Get deltatime
19
- auto now = std::chrono::system_clock::now ();
20
- double deltaTimeSeconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastFrameTime).count ()/1000.0 ;
21
- this ->m_lastFrameTime = now;
22
-
23
18
// Setup pose for this frame
24
19
auto pose = this ->GetPose ();
25
20
21
+ float deltaSeconds = ExampleDriver::getDriver ()->getLastFrameTime ().count () / 1000.0 ;
22
+
26
23
// Get orientation
27
- this ->m_yRot += (1.0 * (GetAsyncKeyState (VK_RIGHT) == 0 ) - 1.0 * (GetAsyncKeyState (VK_LEFT) == 0 )) * deltaTimeSeconds ;
28
- this ->m_xRot += (-1.0 * (GetAsyncKeyState (VK_UP) == 0 ) + 1.0 * (GetAsyncKeyState (VK_DOWN) == 0 )) * deltaTimeSeconds ;
24
+ this ->m_yRot += (1.0 * (GetAsyncKeyState (VK_RIGHT) == 0 ) - 1.0 * (GetAsyncKeyState (VK_LEFT) == 0 )) * deltaSeconds ;
25
+ this ->m_xRot += (-1.0 * (GetAsyncKeyState (VK_UP) == 0 ) + 1.0 * (GetAsyncKeyState (VK_DOWN) == 0 )) * deltaSeconds ;
29
26
this ->m_xRot = std::fmax (this ->m_xRot , -3.14159 /2 );
30
27
this ->m_xRot = std::fmin (this ->m_xRot , 3.14159 /2 );
31
28
@@ -45,7 +42,7 @@ void TutorialDriver::HMDDevice::update(std::vector<vr::VREvent_t> events)
45
42
linalg::vec<float , 3 > right_vec{0 , 0 , 1 .0f * (GetAsyncKeyState (0x57 ) == 0 ) - 1 .0f * (GetAsyncKeyState (0x53 ) == 0 ) };
46
43
linalg::vec<float , 3 > final_dir = forward_vec + right_vec;
47
44
if (linalg::length (final_dir) > 0.01 ) {
48
- final_dir = linalg::normalize (final_dir) * (float )deltaTimeSeconds ;
45
+ final_dir = linalg::normalize (final_dir) * (float )deltaSeconds ;
49
46
final_dir = linalg::qrot (pose_rot, final_dir);
50
47
this ->m_x += final_dir.x ;
51
48
this ->m_y += final_dir.y ;
@@ -57,15 +54,20 @@ void TutorialDriver::HMDDevice::update(std::vector<vr::VREvent_t> events)
57
54
pose.vecPosition [2 ] = this ->m_z ;
58
55
59
56
// Post pose
60
- vr::VRServerDriverHost ()->TrackedDevicePoseUpdated (this ->device_index (), pose, sizeof (vr::DriverPose_t));
57
+ vr::VRServerDriverHost ()->TrackedDevicePoseUpdated (this ->getDeviceIndex (), pose, sizeof (vr::DriverPose_t));
58
+ }
59
+
60
+ DeviceType ExampleDriver::HMDDevice::getDeviceType ()
61
+ {
62
+ return DeviceType::HMD;
61
63
}
62
64
63
- vr::TrackedDeviceIndex_t TutorialDriver ::HMDDevice::device_index ()
65
+ vr::TrackedDeviceIndex_t ExampleDriver ::HMDDevice::getDeviceIndex ()
64
66
{
65
67
return this ->m_deviceIndex ;
66
68
}
67
69
68
- vr::EVRInitError TutorialDriver ::HMDDevice::Activate (uint32_t unObjectId)
70
+ vr::EVRInitError ExampleDriver ::HMDDevice::Activate (uint32_t unObjectId)
69
71
{
70
72
this ->m_deviceIndex = unObjectId;
71
73
@@ -94,36 +96,34 @@ vr::EVRInitError TutorialDriver::HMDDevice::Activate(uint32_t unObjectId)
94
96
vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceNotReady_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
95
97
vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceStandby_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
96
98
vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceAlertLow_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
97
-
98
- this ->m_lastFrameTime = std::chrono::system_clock::now ();
99
99
100
100
return vr::EVRInitError::VRInitError_None;
101
101
}
102
102
103
- void TutorialDriver ::HMDDevice::Deactivate ()
103
+ void ExampleDriver ::HMDDevice::Deactivate ()
104
104
{
105
105
this ->m_deviceIndex = vr::k_unTrackedDeviceIndexInvalid;
106
106
}
107
107
108
- void TutorialDriver ::HMDDevice::EnterStandby ()
108
+ void ExampleDriver ::HMDDevice::EnterStandby ()
109
109
{
110
110
}
111
111
112
- void * TutorialDriver ::HMDDevice::GetComponent (const char * pchComponentNameAndVersion)
112
+ void * ExampleDriver ::HMDDevice::GetComponent (const char * pchComponentNameAndVersion)
113
113
{
114
114
if (!stricmp (pchComponentNameAndVersion, vr::IVRDisplayComponent_Version)) {
115
115
return static_cast <vr::IVRDisplayComponent*>(this );
116
116
}
117
117
return nullptr ;
118
118
}
119
119
120
- void TutorialDriver ::HMDDevice::DebugRequest (const char * pchRequest, char * pchResponseBuffer, uint32_t unResponseBufferSize)
120
+ void ExampleDriver ::HMDDevice::DebugRequest (const char * pchRequest, char * pchResponseBuffer, uint32_t unResponseBufferSize)
121
121
{
122
122
if (unResponseBufferSize >= 1 )
123
123
pchResponseBuffer[0 ] = 0 ;
124
124
}
125
125
126
- vr::DriverPose_t TutorialDriver ::HMDDevice::GetPose ()
126
+ vr::DriverPose_t ExampleDriver ::HMDDevice::GetPose ()
127
127
{
128
128
vr::DriverPose_t out_pose = { 0 };
129
129
@@ -137,31 +137,31 @@ vr::DriverPose_t TutorialDriver::HMDDevice::GetPose()
137
137
return out_pose;
138
138
}
139
139
140
- void TutorialDriver ::HMDDevice::GetWindowBounds (int32_t * pnX, int32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight)
140
+ void ExampleDriver ::HMDDevice::GetWindowBounds (int32_t * pnX, int32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight)
141
141
{
142
142
*pnX = this ->m_windowX ;
143
143
*pnY = this ->m_windowY ;
144
144
*pnWidth = this ->m_windowWidth ;
145
145
*pnHeight = this ->m_windowHeight ;
146
146
}
147
147
148
- bool TutorialDriver ::HMDDevice::IsDisplayOnDesktop ()
148
+ bool ExampleDriver ::HMDDevice::IsDisplayOnDesktop ()
149
149
{
150
150
return true ;
151
151
}
152
152
153
- bool TutorialDriver ::HMDDevice::IsDisplayRealDisplay ()
153
+ bool ExampleDriver ::HMDDevice::IsDisplayRealDisplay ()
154
154
{
155
155
return false ;
156
156
}
157
157
158
- void TutorialDriver ::HMDDevice::GetRecommendedRenderTargetSize (uint32_t * pnWidth, uint32_t * pnHeight)
158
+ void ExampleDriver ::HMDDevice::GetRecommendedRenderTargetSize (uint32_t * pnWidth, uint32_t * pnHeight)
159
159
{
160
160
*pnWidth = this ->m_windowWidth ;
161
161
*pnHeight = this ->m_windowHeight ;
162
162
}
163
163
164
- void TutorialDriver ::HMDDevice::GetEyeOutputViewport (vr::EVREye eEye, uint32_t * pnX, uint32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight)
164
+ void ExampleDriver ::HMDDevice::GetEyeOutputViewport (vr::EVREye eEye, uint32_t * pnX, uint32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight)
165
165
{
166
166
*pnY = 0 ;
167
167
*pnWidth = this ->m_windowWidth / 2 ;
@@ -175,15 +175,15 @@ void TutorialDriver::HMDDevice::GetEyeOutputViewport(vr::EVREye eEye, uint32_t*
175
175
}
176
176
}
177
177
178
- void TutorialDriver ::HMDDevice::GetProjectionRaw (vr::EVREye eEye, float * pfLeft, float * pfRight, float * pfTop, float * pfBottom)
178
+ void ExampleDriver ::HMDDevice::GetProjectionRaw (vr::EVREye eEye, float * pfLeft, float * pfRight, float * pfTop, float * pfBottom)
179
179
{
180
180
*pfLeft = -1 ;
181
181
*pfRight = 1 ;
182
182
*pfTop = -1 ;
183
183
*pfBottom = 1 ;
184
184
}
185
185
186
- vr::DistortionCoordinates_t TutorialDriver ::HMDDevice::ComputeDistortion (vr::EVREye eEye, float fU , float fV )
186
+ vr::DistortionCoordinates_t ExampleDriver ::HMDDevice::ComputeDistortion (vr::EVREye eEye, float fU , float fV )
187
187
{
188
188
vr::DistortionCoordinates_t coordinates;
189
189
coordinates.rfBlue [0 ] = fU ;
0 commit comments