|
5 | 5 | #include <vector> |
6 | 6 | #include <thread> |
7 | 7 | #include <chrono> |
8 | | -#include <Windows.h> |
| 8 | + |
9 | 9 | #include <atlbase.h> |
| 10 | +//#include <Windows.h> |
10 | 11 |
|
11 | 12 | using namespace vr; |
12 | 13 |
|
13 | | - |
14 | 14 | #if defined(_WIN32) |
15 | 15 | #define HMD_DLL_EXPORT extern "C" __declspec( dllexport ) |
16 | 16 | #define HMD_DLL_IMPORT extern "C" __declspec( dllimport ) |
@@ -60,6 +60,10 @@ static const char * const k_pch_Sample_RenderWidth_Int32 = "renderWidth"; |
60 | 60 | static const char * const k_pch_Sample_RenderHeight_Int32 = "renderHeight"; |
61 | 61 | static const char * const k_pch_Sample_SecondsFromVsyncToPhotons_Float = "secondsFromVsyncToPhotons"; |
62 | 62 | static const char * const k_pch_Sample_DisplayFrequency_Float = "displayFrequency"; |
| 63 | +static const char * const k_pch_Sample_DistortionK1_Float = "DistortionK1"; |
| 64 | +static const char * const k_pch_Sample_DistortionK2_Float = "DistortionK2"; |
| 65 | +static const char * const k_pch_Sample_ZoomWidth_Float = "ZoomWidth"; |
| 66 | +static const char * const k_pch_Sample_ZoomHeight_Float = "ZoomHeight"; |
63 | 67 |
|
64 | 68 | typedef struct _HMDData |
65 | 69 | { |
@@ -191,6 +195,11 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV |
191 | 195 | m_flSecondsFromVsyncToPhotons = vr::VRSettings()->GetFloat( k_pch_Sample_Section, k_pch_Sample_SecondsFromVsyncToPhotons_Float ); |
192 | 196 | m_flDisplayFrequency = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DisplayFrequency_Float); |
193 | 197 |
|
| 198 | + m_fDistortionK1 = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DistortionK1_Float); |
| 199 | + m_fDistortionK2 = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DistortionK2_Float); |
| 200 | + m_fZoomWidth = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ZoomWidth_Float); |
| 201 | + m_fZoomHeight = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ZoomHeight_Float); |
| 202 | + |
194 | 203 | //DriverLog( "driver_null: Serial Number: %s\n", m_sSerialNumber.c_str() ); |
195 | 204 | //DriverLog( "driver_null: Model Number: %s\n", m_sModelNumber.c_str() ); |
196 | 205 | //DriverLog( "driver_null: Window: %d %d %d %d\n", m_nWindowX, m_nWindowY, m_nWindowWidth, m_nWindowHeight ); |
@@ -415,12 +424,27 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV |
415 | 424 | virtual DistortionCoordinates_t ComputeDistortion( EVREye eEye, float fU, float fV ) |
416 | 425 | { |
417 | 426 | DistortionCoordinates_t coordinates; |
418 | | - coordinates.rfBlue[0] = fU; |
419 | | - coordinates.rfBlue[1] = fV; |
420 | | - coordinates.rfGreen[0] = fU; |
421 | | - coordinates.rfGreen[1] = fV; |
422 | | - coordinates.rfRed[0] = fU; |
423 | | - coordinates.rfRed[1] = fV; |
| 427 | + |
| 428 | + //distortion for lens from https://github.com/HelenXR/openvr_survivor/blob/master/src/head_mount_display_device.cc |
| 429 | + float hX; |
| 430 | + float hY; |
| 431 | + double rr; |
| 432 | + double r2; |
| 433 | + double theta; |
| 434 | + |
| 435 | + rr = sqrt((fU - 0.5f)*(fU - 0.5f) + (fV - 0.5f)*(fV - 0.5f)); |
| 436 | + r2 = rr * (1 + m_fDistortionK1*(rr*rr) + m_fDistortionK2*(rr*rr*rr*rr)); |
| 437 | + theta = atan2(fU - 0.5f, fV - 0.5f); |
| 438 | + hX = sin(theta)*r2*m_fZoomWidth; |
| 439 | + hY = cos(theta)*r2*m_fZoomHeight; |
| 440 | + |
| 441 | + coordinates.rfBlue[0] = hX + 0.5f; |
| 442 | + coordinates.rfBlue[1] = hY + 0.5f; |
| 443 | + coordinates.rfGreen[0] = hX + 0.5f; |
| 444 | + coordinates.rfGreen[1] = hY + 0.5f; |
| 445 | + coordinates.rfRed[0] = hX + 0.5f; |
| 446 | + coordinates.rfRed[1] = hY + 0.5f; |
| 447 | + |
424 | 448 | return coordinates; |
425 | 449 | } |
426 | 450 |
|
@@ -494,6 +518,10 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV |
494 | 518 | float m_flSecondsFromVsyncToPhotons; |
495 | 519 | float m_flDisplayFrequency; |
496 | 520 | float m_flIPD; |
| 521 | + float m_fDistortionK1; |
| 522 | + float m_fDistortionK2; |
| 523 | + float m_fZoomWidth; |
| 524 | + float m_fZoomHeight; |
497 | 525 | }; |
498 | 526 |
|
499 | 527 | //----------------------------------------------------------------------------- |
|
0 commit comments