Skip to content

Commit 1135d7a

Browse files
committed
Added offset output views
1 parent cdf3bc3 commit 1135d7a

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

OpenVR/FreeTrack/samples/driver_sample/driver_sample.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ static const char * const k_pch_Sample_DistortionK1_Float = "DistortionK1";
6767
static const char * const k_pch_Sample_DistortionK2_Float = "DistortionK2";
6868
static const char * const k_pch_Sample_ZoomWidth_Float = "ZoomWidth";
6969
static const char * const k_pch_Sample_ZoomHeight_Float = "ZoomHeight";
70+
static const char * const k_pch_Sample_DistanceBetweenEyes_Int32 = "DistanceBetweenEyes";
71+
static const char * const k_pch_Sample_ScreenOffsetX_Int32 = "ScreenOffsetX";
7072
static const char * const k_pch_Sample_DebugMode_Bool = "DebugMode";
7173

7274
#define FREETRACK_HEAP "FT_SharedMem"
@@ -121,7 +123,7 @@ FTData *FreeTrack;
121123
bool HMDConnected = false;
122124
std::thread *pFTthread = NULL;
123125

124-
//FreeTrack implementation from https://github.com/opentrack/opentrack/tree/unstable/freetrackclient
126+
//FreeTrack implementation from OpenTrack (https://github.com/opentrack/opentrack/tree/unstable/freetrackclient)
125127
static BOOL impl_create_mapping(void)
126128
{
127129
if (ipc_heap != NULL)
@@ -273,6 +275,8 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
273275
m_fDistortionK2 = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DistortionK2_Float);
274276
m_fZoomWidth = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ZoomWidth_Float);
275277
m_fZoomHeight = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ZoomHeight_Float);
278+
m_nDistanceBetweenEyes = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DistanceBetweenEyes_Int32);
279+
m_nScreenOffsetX = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ScreenOffsetX_Int32);
276280
m_bDebugMode = vr::VRSettings()->GetBool(k_pch_Sample_Section, k_pch_Sample_DebugMode_Bool);
277281

278282
//DriverLog( "driver_null: Serial Number: %s\n", m_sSerialNumber.c_str() );
@@ -317,7 +321,7 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
317321
// avoid "not fullscreen" warnings from vrmonitor
318322
vr::VRProperties()->SetBoolProperty( m_ulPropertyContainer, Prop_IsOnDesktop_Bool, false );
319323

320-
//Debug mode activate Windowed Mode (borderless fullscreen) on "Headset Window" and you can move window to second screen with buttons (Shift + Win + Right or Left), but lock to 30 FPS
324+
//Debug mode activate Windowed Mode (borderless fullscreen), lock to 30 FPS
321325
vr::VRProperties()->SetBoolProperty(m_ulPropertyContainer, Prop_DisplayDebugMode_Bool, m_bDebugMode);
322326
// Icons can be configured in code or automatically configured by an external file "drivername\resources\driver.vrresources".
323327
// Icon properties NOT configured in code (post Activate) are then auto-configured by the optional presence of a driver's "drivername\resources\driver.vrresources".
@@ -418,17 +422,17 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
418422

419423
virtual void GetEyeOutputViewport( EVREye eEye, uint32_t *pnX, uint32_t *pnY, uint32_t *pnWidth, uint32_t *pnHeight )
420424
{
421-
*pnY = 0;
425+
*pnY = m_nScreenOffsetX;
422426
*pnWidth = m_nWindowWidth / 2;
423427
*pnHeight = m_nWindowHeight;
424-
425-
if ( eEye == Eye_Left )
428+
429+
if (eEye == Eye_Left)
426430
{
427-
*pnX = 0;
431+
*pnX = m_nDistanceBetweenEyes;
428432
}
429433
else
430434
{
431-
*pnX = m_nWindowWidth / 2;
435+
*pnX = (m_nWindowWidth / 2) - m_nDistanceBetweenEyes;
432436
}
433437
}
434438

@@ -534,6 +538,8 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
534538
float m_fDistortionK2;
535539
float m_fZoomWidth;
536540
float m_fZoomHeight;
541+
int32_t m_nDistanceBetweenEyes;
542+
int32_t m_nScreenOffsetX;
537543
bool m_bDebugMode;
538544
};
539545

OpenVR/UDP/samples/driver_sample/driver_sample.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ static const char * const k_pch_Sample_DistortionK1_Float = "DistortionK1";
6969
static const char * const k_pch_Sample_DistortionK2_Float = "DistortionK2";
7070
static const char * const k_pch_Sample_ZoomWidth_Float = "ZoomWidth";
7171
static const char * const k_pch_Sample_ZoomHeight_Float = "ZoomHeight";
72+
static const char * const k_pch_Sample_DistanceBetweenEyes_Int32 = "DistanceBetweenEyes";
73+
static const char * const k_pch_Sample_ScreenOffsetX_Int32 = "ScreenOffsetX";
7274
static const char * const k_pch_Sample_DebugMode_Bool = "DebugMode";
7375

7476
//OpenTrack vars
@@ -250,6 +252,8 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
250252
m_fDistortionK2 = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DistortionK2_Float);
251253
m_fZoomWidth = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ZoomWidth_Float);
252254
m_fZoomHeight = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ZoomHeight_Float);
255+
m_nDistanceBetweenEyes = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DistanceBetweenEyes_Int32);
256+
m_nScreenOffsetX = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ScreenOffsetX_Int32);
253257
m_bDebugMode = vr::VRSettings()->GetBool(k_pch_Sample_Section, k_pch_Sample_DebugMode_Bool);
254258

255259
//DriverLog( "driver_null: Serial Number: %s\n", m_sSerialNumber.c_str() );
@@ -428,17 +432,17 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
428432

429433
virtual void GetEyeOutputViewport( EVREye eEye, uint32_t *pnX, uint32_t *pnY, uint32_t *pnWidth, uint32_t *pnHeight )
430434
{
431-
*pnY = 0;
435+
*pnY = m_nScreenOffsetX;
432436
*pnWidth = m_nWindowWidth / 2;
433437
*pnHeight = m_nWindowHeight;
434-
435-
if ( eEye == Eye_Left )
438+
439+
if (eEye == Eye_Left)
436440
{
437-
*pnX = 0;
441+
*pnX = m_nDistanceBetweenEyes;
438442
}
439443
else
440444
{
441-
*pnX = m_nWindowWidth / 2;
445+
*pnX = (m_nWindowWidth / 2) - m_nDistanceBetweenEyes;
442446
}
443447
}
444448

@@ -545,6 +549,8 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
545549
float m_fDistortionK2;
546550
float m_fZoomWidth;
547551
float m_fZoomHeight;
552+
int32_t m_nDistanceBetweenEyes;
553+
int32_t m_nScreenOffsetX;
548554
bool m_bDebugMode;
549555
};
550556

0 commit comments

Comments
 (0)