|
2 | 2 | //=============== Changed by r57zone (https://github.com/r57zone) =============== |
3 | 3 |
|
4 | 4 | #include <openvr_driver.h> |
| 5 | +//#include "driverlog.h" |
5 | 6 |
|
6 | 7 | #include <vector> |
7 | 8 | #include <thread> |
8 | 9 | #include <chrono> |
9 | 10 |
|
10 | | -#include <stdio.h> |
11 | 11 | #include <winsock2.h> |
12 | 12 | #pragma comment (lib, "WSock32.Lib") |
| 13 | +//#include <Windows.h> |
13 | 14 |
|
14 | | -#if defined( _WINDOWS ) |
15 | | -#include <windows.h> |
16 | | -#endif |
17 | 15 |
|
18 | 16 | using namespace vr; |
19 | 17 |
|
@@ -67,6 +65,10 @@ static const char * const k_pch_Sample_RenderWidth_Int32 = "renderWidth"; |
67 | 65 | static const char * const k_pch_Sample_RenderHeight_Int32 = "renderHeight"; |
68 | 66 | static const char * const k_pch_Sample_SecondsFromVsyncToPhotons_Float = "secondsFromVsyncToPhotons"; |
69 | 67 | static const char * const k_pch_Sample_DisplayFrequency_Float = "displayFrequency"; |
| 68 | +static const char * const k_pch_Sample_DistortionK1_Float = "DistortionK1"; |
| 69 | +static const char * const k_pch_Sample_DistortionK2_Float = "DistortionK2"; |
| 70 | +static const char * const k_pch_Sample_ZoomWidth_Float = "ZoomWidth"; |
| 71 | +static const char * const k_pch_Sample_ZoomHeight_Float = "ZoomHeight"; |
70 | 72 |
|
71 | 73 | //OpenTrack vars |
72 | 74 | double qW, qX, qY, qZ; |
@@ -243,6 +245,11 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV |
243 | 245 | m_flSecondsFromVsyncToPhotons = vr::VRSettings()->GetFloat( k_pch_Sample_Section, k_pch_Sample_SecondsFromVsyncToPhotons_Float ); |
244 | 246 | m_flDisplayFrequency = vr::VRSettings()->GetFloat( k_pch_Sample_Section, k_pch_Sample_DisplayFrequency_Float ); |
245 | 247 |
|
| 248 | + m_fDistortionK1 = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DistortionK1_Float); |
| 249 | + m_fDistortionK2 = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_DistortionK2_Float); |
| 250 | + m_fZoomWidth = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ZoomWidth_Float); |
| 251 | + m_fZoomHeight = vr::VRSettings()->GetFloat(k_pch_Sample_Section, k_pch_Sample_ZoomHeight_Float); |
| 252 | + |
246 | 253 | //DriverLog( "driver_null: Serial Number: %s\n", m_sSerialNumber.c_str() ); |
247 | 254 | //DriverLog( "driver_null: Model Number: %s\n", m_sModelNumber.c_str() ); |
248 | 255 | //DriverLog( "driver_null: Window: %d %d %d %d\n", m_nWindowX, m_nWindowY, m_nWindowWidth, m_nWindowHeight ); |
@@ -445,12 +452,28 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV |
445 | 452 | virtual DistortionCoordinates_t ComputeDistortion( EVREye eEye, float fU, float fV ) |
446 | 453 | { |
447 | 454 | DistortionCoordinates_t coordinates; |
448 | | - coordinates.rfBlue[0] = fU; |
449 | | - coordinates.rfBlue[1] = fV; |
450 | | - coordinates.rfGreen[0] = fU; |
451 | | - coordinates.rfGreen[1] = fV; |
452 | | - coordinates.rfRed[0] = fU; |
453 | | - coordinates.rfRed[1] = fV; |
| 455 | + |
| 456 | + //distortion for lens from https://github.com/HelenXR/openvr_survivor/blob/master/src/head_mount_display_device.cc |
| 457 | + float hX; |
| 458 | + float hY; |
| 459 | + double rr; |
| 460 | + double r2; |
| 461 | + double theta; |
| 462 | + |
| 463 | + rr = sqrt((fU - 0.5f)*(fU - 0.5f) + (fV - 0.5f)*(fV - 0.5f)); |
| 464 | + r2 = rr * (1 + m_fDistortionK1*(rr*rr) + m_fDistortionK2*(rr*rr*rr*rr)); |
| 465 | + theta = atan2(fU - 0.5f, fV - 0.5f); |
| 466 | + hX = sin(theta)*r2*m_fZoomWidth; |
| 467 | + hY = cos(theta)*r2*m_fZoomHeight; |
| 468 | + |
| 469 | + coordinates.rfBlue[0] = hX + 0.5f; |
| 470 | + coordinates.rfBlue[1] = hY + 0.5f; |
| 471 | + coordinates.rfGreen[0] = hX + 0.5f; |
| 472 | + coordinates.rfGreen[1] = hY + 0.5f; |
| 473 | + coordinates.rfRed[0] = hX + 0.5f; |
| 474 | + coordinates.rfRed[1] = hY + 0.5f; |
| 475 | + |
| 476 | + |
454 | 477 | return coordinates; |
455 | 478 | } |
456 | 479 |
|
@@ -517,6 +540,10 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV |
517 | 540 | float m_flSecondsFromVsyncToPhotons; |
518 | 541 | float m_flDisplayFrequency; |
519 | 542 | float m_flIPD; |
| 543 | + float m_fDistortionK1; |
| 544 | + float m_fDistortionK2; |
| 545 | + float m_fZoomWidth; |
| 546 | + float m_fZoomHeight; |
520 | 547 | }; |
521 | 548 |
|
522 | 549 | //----------------------------------------------------------------------------- |
|
0 commit comments