├── .idea ├── vcs.xml ├── modules.xml ├── misc.xml └── vrpn-openvr.iml ├── .gitmodules ├── VRPN-OpenVR ├── vrpn_Tracker_OpenVR_HMD.cpp ├── vrpn_Tracker_OpenVR_HMD.h ├── vrpn_Tracker_OpenVR.h ├── vrpn_Tracker_OpenVR_Controller.h ├── main.cpp ├── vrpn_Server_OpenVR.h ├── VRPN-OpenVR.vcxproj.filters ├── vrpn_Tracker_OpenVR_Controller.cpp ├── vrpn_Tracker_OpenVR.cpp ├── vrpn_Server_OpenVR.cpp └── VRPN-OpenVR.vcxproj ├── CMakeLists.txt ├── OpenVR ├── OpenVR.vcxitems.filters └── OpenVR.vcxitems ├── README.md ├── .gitattributes ├── VRPN-OpenVR.sln └── .gitignore /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/openvr"] 2 | path = vendor/openvr 3 | url = https://github.com/ValveSoftware/openvr.git 4 | [submodule "vendor/vrpn"] 5 | path = vendor/vrpn 6 | url=https://github.com/sat-metalab/vrpn.git -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VRPN-OpenVR/vrpn_Tracker_OpenVR_HMD.cpp: -------------------------------------------------------------------------------- 1 | #include "vrpn_Tracker_OpenVR_HMD.h" 2 | 3 | vrpn_Tracker_OpenVR_HMD::vrpn_Tracker_OpenVR_HMD(const std::string& name, vrpn_Connection* connection, vr::IVRSystem * vr) : 4 | vrpn_Tracker_OpenVR(name.c_str(), connection, vr) 5 | { 6 | } 7 | 8 | void vrpn_Tracker_OpenVR_HMD::mainloop() { 9 | vrpn_Tracker_OpenVR::mainloop(); 10 | } -------------------------------------------------------------------------------- /VRPN-OpenVR/vrpn_Tracker_OpenVR_HMD.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "vrpn_Tracker_OpenVR.h" 6 | 7 | class vrpn_Tracker_OpenVR_HMD : 8 | public vrpn_Tracker_OpenVR 9 | { 10 | public: 11 | vrpn_Tracker_OpenVR_HMD() = delete; 12 | vrpn_Tracker_OpenVR_HMD(const std::string& name, vrpn_Connection* connection, vr::IVRSystem * vr); 13 | void mainloop(); 14 | private: 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(VRPN-OpenVR) 4 | 5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") 6 | 7 | include_directories( 8 | vendor/openvr/headers 9 | vendor/vrpn/quat 10 | vendor/vrpn 11 | ) 12 | 13 | add_executable(shingles 14 | VRPN-OpenVR/main.cpp 15 | VRPN-OpenVR/vrpn_Server_OpenVR.cpp 16 | VRPN-OpenVR/vrpn_Tracker_OpenVR.cpp 17 | VRPN-OpenVR/vrpn_Tracker_OpenVR_HMD.cpp 18 | VRPN-OpenVR/vrpn_Tracker_OpenVR_Controller.cpp 19 | ) -------------------------------------------------------------------------------- /VRPN-OpenVR/vrpn_Tracker_OpenVR.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class vrpn_Tracker_OpenVR : 9 | public vrpn_Tracker 10 | { 11 | public: 12 | vrpn_Tracker_OpenVR(const std::string& name, vrpn_Connection* connection, vr::IVRSystem * vr); 13 | void mainloop(); 14 | void updateTracking(vr::TrackedDevicePose_t *pose); 15 | protected: 16 | vr::IVRSystem * vr; 17 | private: 18 | std::string name; 19 | q_matrix_type matrix; 20 | static void ConvertSteamVRMatrixToQMatrix(const vr::HmdMatrix34_t &matPose, q_matrix_type &matrix); 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /VRPN-OpenVR/vrpn_Tracker_OpenVR_Controller.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "vrpn_Tracker_OpenVR.h" 8 | 9 | class vrpn_Tracker_OpenVR_Controller : 10 | public vrpn_Tracker_OpenVR, 11 | public vrpn_Analog, 12 | public vrpn_Button_Filter 13 | { 14 | public: 15 | vrpn_Tracker_OpenVR_Controller() = delete; 16 | vrpn_Tracker_OpenVR_Controller(const std::string& name, vrpn_Connection* connection, vr::IVRSystem * vr); 17 | void mainloop(); 18 | void updateController(vr::TrackedDeviceIndex_t unTrackedDevice); 19 | private: 20 | vr::VRControllerState_t pControllerState; 21 | }; -------------------------------------------------------------------------------- /OpenVR/OpenVR.vcxitems.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {7e90a88f-90cb-4050-b8e4-d04a20676da7} 6 | h;hh;hpp;hxx;hm;inl;inc;xsd 7 | 8 | 9 | 10 | 11 | Header Files 12 | 13 | 14 | Header Files 15 | 16 | 17 | Header Files 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VRPN-OpenVR 2 | OpenVR support for VRPN. Builds as a server that exposes OpenVR HMDs and controllers as as openvr/[hmd|controller]/[trackedDeviceId]. 3 | Each of which having the relevant vrpn devices that it supports: vrpn_Tracker for HMDs and vrpn_Tracker, crpn_Analog and vrpn_Button 4 | for the controllers. 5 | 6 | # Building 7 | This server currently only builds in Visual Studio (2015 was used) as OpenVR is only supported in windows and we ran 8 | into issues trying to build it with CMake under Cygwin. A CMake file generating a VS project was considered but was 9 | found to introduce too many steps for the end result still requiring switching to VS for the build. 10 | 11 | Note: the current `CMakeLists.txt` is only a dummy to allow CLion to understand the project. 12 | 13 | * Initialize the repository with submodules in order to retrieve OpenVR and VRPN 14 | 15 | git submodule update --init --recursive 16 | 17 | * Open the `VRNP-OpenVR.sln` solution and build from the IDE 18 | 19 | # Acknowledgements 20 | This is still very much a work in progress and is by no means a complete and stable solution for using OpenVR with VRPN. 21 | The primary goal of this server is to provide controller data to a Blender instance running on a separate Linux machine. -------------------------------------------------------------------------------- /VRPN-OpenVR/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "vrpn_Server_OpenVR.h" 4 | 5 | static volatile int done = 0; 6 | std::unique_ptr server{}; 7 | 8 | // install a signal handler to shut down the devices 9 | // On Windows, the signal handler is run in a different thread from 10 | // the main application. We don't want to go destroying things in 11 | // here while they are being used there, so we set a flag telling the 12 | // main program it is time to exit. 13 | #if defined(_WIN32) && !defined(__CYGWIN__) 14 | /** 15 | * Handle exiting cleanly when we get ^C or other signals. 16 | */ 17 | BOOL WINAPI handleConsoleSignalsWin(DWORD signaltype) 18 | { 19 | switch (signaltype) { 20 | case CTRL_C_EVENT: 21 | case CTRL_BREAK_EVENT: 22 | case CTRL_CLOSE_EVENT: 23 | case CTRL_SHUTDOWN_EVENT: 24 | done = 1; 25 | return TRUE; 26 | // Don't exit, but return FALSE so default handler 27 | // gets called. The default handler, ExitProcess, will exit. 28 | default: 29 | return FALSE; 30 | } 31 | } 32 | #endif 33 | 34 | int main(int argc, char *argv[]) { 35 | server = std::make_unique(); 36 | while (!done) { 37 | server->mainloop(); 38 | vrpn_SleepMsecs(16); 39 | } 40 | server.reset(nullptr); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /OpenVR/OpenVR.vcxitems: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {45d41acc-2c3c-43d2-bc10-02aa73ffc7c7} 7 | OpenVR 8 | 9 | 10 | 11 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /VRPN-OpenVR/vrpn_Server_OpenVR.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "vrpn_Tracker_OpenVR_HMD.h" 10 | #include "vrpn_Tracker_OpenVR_Controller.h" 11 | 12 | /// Sensor numbers in SteamVR and for tracking 13 | static const auto HMD_SENSOR = 0; 14 | static const auto CONTROLLER_SENSORS = { 1, 2 }; 15 | static const auto MAX_CONTROLLER_ID = 2; 16 | 17 | //static const auto NUM_TRACKERS = 3; 18 | //static const auto NUM_ANALOGS = 7; 19 | //static const auto NUM_BUTTONS = 14; 20 | 21 | /// For the HMD and two controllers 22 | static const std::array FIRST_BUTTON_ID{ 0, 2, 8 }; 23 | static const std::array FIRST_ANALOG_ID{ 0, 1, 4 }; 24 | 25 | /// Offsets from the first button ID for a controller that a button is 26 | /// reported. 27 | static const auto SYSTEM_BUTTON_OFFSET = 0; 28 | static const auto MENU_BUTTON_OFFSET = 1; 29 | static const auto GRIP_BUTTON_OFFSET = 2; 30 | static const auto TRACKPAD_TOUCH_BUTTON_OFFSET = 3; 31 | static const auto TRACKPAD_CLICK_BUTTON_OFFSET = 4; 32 | static const auto TRIGGER_BUTTON_OFFSET = 4; 33 | 34 | /// Offsets from the first button ID for a controller that an analog is 35 | /// reported. 36 | static const auto TRACKPAD_X_ANALOG_OFFSET = 0; 37 | static const auto TRACKPAD_Y_ANALOG_OFFSET = 1; 38 | static const auto TRIGGER_ANALOG_OFFSET = 2; 39 | 40 | class vrpn_Server_OpenVR { 41 | public: 42 | vrpn_Server_OpenVR(); 43 | ~vrpn_Server_OpenVR(); 44 | void mainloop(); 45 | 46 | private: 47 | std::unique_ptr vr{ nullptr }; 48 | vrpn_Connection *connection; 49 | std::map> hmds{}; 50 | std::map> controllers{}; 51 | }; 52 | 53 | -------------------------------------------------------------------------------- /VRPN-OpenVR/VRPN-OpenVR.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | -------------------------------------------------------------------------------- /VRPN-OpenVR/vrpn_Tracker_OpenVR_Controller.cpp: -------------------------------------------------------------------------------- 1 | #include "vrpn_Tracker_OpenVR_Controller.h" 2 | 3 | vrpn_Tracker_OpenVR_Controller::vrpn_Tracker_OpenVR_Controller(const std::string& name, vrpn_Connection* connection, vr::IVRSystem * vr) : 4 | vrpn_Tracker_OpenVR(name.c_str(), connection, vr), 5 | vrpn_Analog(name.c_str(), connection), 6 | vrpn_Button_Filter(name.c_str(), connection) 7 | { 8 | // Initialize the vrpn_Analog 9 | vrpn_Analog::num_channel = vr::k_unControllerStateAxisCount * 2; // * 2 for x&y 10 | for (auto i = 0; i < vrpn_Analog::num_channel; i++) { 11 | vrpn_Analog::channel[i] = vrpn_Analog::last[i] = 0; 12 | } 13 | 14 | // Initialize the vrpn_Button_Filter 15 | vrpn_Button_Filter::num_buttons = vr::k_EButton_Max; 16 | for (auto i = 0; i < vrpn_Button_Filter::num_buttons; i++) { 17 | vrpn_Button_Filter::buttons[i] = vrpn_Button_Filter::lastbuttons[i] = 0; 18 | } 19 | } 20 | 21 | void vrpn_Tracker_OpenVR_Controller::mainloop() { 22 | vrpn_gettimeofday( &(vrpn_Tracker_OpenVR::timestamp), NULL ); 23 | vrpn_Tracker_OpenVR::mainloop(); 24 | 25 | vrpn_gettimeofday( &(vrpn_Analog::timestamp), NULL ); 26 | vrpn_Analog::report_changes(); 27 | 28 | 29 | vrpn_gettimeofday( &(vrpn_Button_Filter::timestamp), NULL ); 30 | vrpn_Button_Filter::report_changes(); 31 | } 32 | 33 | void vrpn_Tracker_OpenVR_Controller::updateController(vr::TrackedDeviceIndex_t unTrackedDevice) { 34 | // Analog & Buttons 35 | if (vr->GetTrackedDeviceClass(unTrackedDevice) == vr::TrackedDeviceClass_Controller) { 36 | vr->GetControllerState(unTrackedDevice, &pControllerState); 37 | 38 | for (unsigned int buttonId = 0; buttonId < vr::k_EButton_Max; ++buttonId) { 39 | uint64_t mask = vr::ButtonMaskFromId(static_cast(buttonId)); 40 | vrpn_Button_Filter::buttons[buttonId] = static_cast(((mask & pControllerState.ulButtonTouched) == mask) ? 2 : 0); 41 | vrpn_Button_Filter::buttons[buttonId] = static_cast(((mask & pControllerState.ulButtonPressed) == mask) ? 1 : vrpn_Button_Filter::buttons[buttonId]); 42 | } 43 | 44 | for (unsigned int axisId = 0; axisId < vr::k_unControllerStateAxisCount; ++axisId) { 45 | vrpn_Analog::channel[axisId * 2] = pControllerState.rAxis[axisId].x; 46 | vrpn_Analog::channel[axisId * 2 + 1] = pControllerState.rAxis[axisId].y; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /VRPN-OpenVR.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VRPN", "vendor\vrpn\vrpn.vcxproj", "{7EE1DB03-16A5-4465-9164-061BE0C88B8C}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "quatlib", "vendor\vrpn\quat\quatlib.vcxproj", "{0C16E98C-A372-4E58-990D-EE276B32644E}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VRPN-OpenVR", "VRPN-OpenVR\VRPN-OpenVR.vcxproj", "{5A9FE86D-14AB-4247-8853-31B0717ACAB9}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenVR", "OpenVR\OpenVR.vcxitems", "{45D41ACC-2C3C-43D2-BC10-02AA73FFC7C7}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|x64 = Debug|x64 17 | Debug|x86 = Debug|x86 18 | Release|x64 = Release|x64 19 | Release|x86 = Release|x86 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {7EE1DB03-16A5-4465-9164-061BE0C88B8C}.Debug|x64.ActiveCfg = Debug|x64 23 | {7EE1DB03-16A5-4465-9164-061BE0C88B8C}.Debug|x64.Build.0 = Debug|x64 24 | {7EE1DB03-16A5-4465-9164-061BE0C88B8C}.Debug|x86.ActiveCfg = Debug|Win32 25 | {7EE1DB03-16A5-4465-9164-061BE0C88B8C}.Debug|x86.Build.0 = Debug|Win32 26 | {7EE1DB03-16A5-4465-9164-061BE0C88B8C}.Release|x64.ActiveCfg = Release|Win32 27 | {7EE1DB03-16A5-4465-9164-061BE0C88B8C}.Release|x86.ActiveCfg = Release|Win32 28 | {7EE1DB03-16A5-4465-9164-061BE0C88B8C}.Release|x86.Build.0 = Release|Win32 29 | {0C16E98C-A372-4E58-990D-EE276B32644E}.Debug|x64.ActiveCfg = Debug|x64 30 | {0C16E98C-A372-4E58-990D-EE276B32644E}.Debug|x64.Build.0 = Debug|x64 31 | {0C16E98C-A372-4E58-990D-EE276B32644E}.Debug|x86.ActiveCfg = Debug|Win32 32 | {0C16E98C-A372-4E58-990D-EE276B32644E}.Debug|x86.Build.0 = Debug|Win32 33 | {0C16E98C-A372-4E58-990D-EE276B32644E}.Release|x64.ActiveCfg = Release|Win32 34 | {0C16E98C-A372-4E58-990D-EE276B32644E}.Release|x86.ActiveCfg = Release|Win32 35 | {0C16E98C-A372-4E58-990D-EE276B32644E}.Release|x86.Build.0 = Release|Win32 36 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9}.Debug|x64.ActiveCfg = Debug|x64 37 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9}.Debug|x64.Build.0 = Debug|x64 38 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9}.Debug|x86.ActiveCfg = Debug|Win32 39 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9}.Debug|x86.Build.0 = Debug|Win32 40 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9}.Release|x64.ActiveCfg = Release|x64 41 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9}.Release|x64.Build.0 = Release|x64 42 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9}.Release|x86.ActiveCfg = Release|Win32 43 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9}.Release|x86.Build.0 = Release|Win32 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /VRPN-OpenVR/vrpn_Tracker_OpenVR.cpp: -------------------------------------------------------------------------------- 1 | #include "vrpn_Tracker_OpenVR.h" 2 | #include 3 | #include 4 | #include 5 | 6 | vrpn_Tracker_OpenVR::vrpn_Tracker_OpenVR(const std::string& name, vrpn_Connection* connection, vr::IVRSystem * vr) : 7 | vrpn_Tracker(name.c_str(), connection), name(name), vr(vr) 8 | { 9 | // Initialize the vrpn_Tracker 10 | // We track each device separately so this will only ever have one sensor 11 | vrpn_Tracker::num_sensors = 1; 12 | } 13 | 14 | void vrpn_Tracker_OpenVR::updateTracking(vr::TrackedDevicePose_t *pose) { 15 | if (!pose->bPoseIsValid) { 16 | return; 17 | } 18 | if (pose->eTrackingResult != vr::TrackingResult_Running_OK) { 19 | switch (pose->eTrackingResult) { 20 | case vr::TrackingResult_Uninitialized: 21 | std::cerr << "[" << name << "] Uninitialized" << std::endl; 22 | break; 23 | case vr::TrackingResult_Calibrating_InProgress: 24 | std::cerr << "[" << name << "] Calibrating (In Progress)" << std::endl; 25 | break; 26 | case vr::TrackingResult_Calibrating_OutOfRange: 27 | std::cerr << "[" << name << "] Calibrating (Out of Range)" << std::endl; 28 | break; 29 | case vr::TrackingResult_Running_OK: 30 | std::cerr << "[" << name << "] Running (OK)" << std::endl; 31 | break; 32 | case vr::TrackingResult_Running_OutOfRange: 33 | std::cerr << "[" << name << "] Running (Out of Range)" << std::endl; 34 | break; 35 | default: 36 | std::cerr << "[" << name << "] Unknown tracking result" << std::endl; 37 | break; 38 | } 39 | } 40 | 41 | // Sensor, doesn't change since we are tracking individual devices 42 | d_sensor = 0; 43 | 44 | // Position 45 | pos[0] = pose->mDeviceToAbsoluteTracking.m[0][3]; 46 | pos[1] = pose->mDeviceToAbsoluteTracking.m[1][3]; 47 | pos[2] = pose->mDeviceToAbsoluteTracking.m[2][3]; 48 | 49 | // Quaternion 50 | ConvertSteamVRMatrixToQMatrix(pose->mDeviceToAbsoluteTracking, matrix); 51 | q_from_col_matrix(d_quat, matrix); 52 | 53 | // Pack message 54 | vrpn_gettimeofday(×tamp, NULL); 55 | char msgbuf[1000]; 56 | vrpn_int32 len = vrpn_Tracker::encode_to(msgbuf); 57 | if (d_connection->pack_message(len, timestamp, position_m_id, d_sender_id, msgbuf, vrpn_CONNECTION_LOW_LATENCY)) { 58 | std::cerr << "[\" << name << \"] Can't write message" << std::endl; 59 | } 60 | } 61 | 62 | void vrpn_Tracker_OpenVR::mainloop() { 63 | vrpn_gettimeofday( &(vrpn_Tracker_OpenVR::timestamp), NULL ); 64 | vrpn_Tracker::server_mainloop(); 65 | } 66 | 67 | void vrpn_Tracker_OpenVR::ConvertSteamVRMatrixToQMatrix(const vr::HmdMatrix34_t &matPose, q_matrix_type &matrix) { 68 | matrix[0][0] = matPose.m[0][0]; 69 | matrix[1][0] = matPose.m[1][0]; 70 | matrix[2][0] = matPose.m[2][0]; 71 | matrix[3][0] = 0.0; 72 | matrix[0][1] = matPose.m[0][1]; 73 | matrix[1][1] = matPose.m[1][1]; 74 | matrix[2][1] = matPose.m[2][1]; 75 | matrix[3][1] = 0.0; 76 | matrix[0][2] = matPose.m[0][2]; 77 | matrix[1][2] = matPose.m[1][2]; 78 | matrix[2][2] = matPose.m[2][2]; 79 | matrix[3][2] = 0.0; 80 | matrix[0][3] = matPose.m[0][3]; 81 | matrix[1][3] = matPose.m[1][3]; 82 | matrix[2][3] = matPose.m[2][3]; 83 | matrix[3][3] = 1.0f; 84 | } -------------------------------------------------------------------------------- /VRPN-OpenVR/vrpn_Server_OpenVR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "vrpn_Server_OpenVR.h" 6 | 7 | vrpn_Server_OpenVR::vrpn_Server_OpenVR() { 8 | // Initialize OpenVR 9 | vr::EVRInitError eError = vr::VRInitError_None; 10 | vr = std::unique_ptr(vr::VR_Init(&eError, vr::VRApplication_Overlay)); 11 | if (eError != vr::VRInitError_None) { 12 | vr.reset(nullptr); 13 | std::cerr << "Unable to init VR runtime: " << vr::VR_GetVRInitErrorAsEnglishDescription(eError) << std::endl; 14 | } 15 | 16 | // Initialize VRPN Connection 17 | std::string connectionName = ":" + std::to_string(vrpn_DEFAULT_LISTEN_PORT_NO); 18 | connection = vrpn_create_server_connection(connectionName.c_str()); 19 | } 20 | 21 | 22 | vrpn_Server_OpenVR::~vrpn_Server_OpenVR() { 23 | vr::VR_Shutdown(); 24 | if (connection) { 25 | connection->removeReference(); 26 | connection = NULL; 27 | } 28 | } 29 | 30 | void vrpn_Server_OpenVR::mainloop() { 31 | // Get Tracking Information 32 | vr::TrackedDevicePose_t m_rTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; 33 | vr->GetDeviceToAbsoluteTrackingPose( 34 | vr::TrackingUniverseStanding, 35 | 0/*float fPredictedSecondsToPhotonsFromNow*/, 36 | m_rTrackedDevicePose, 37 | vr::k_unMaxTrackedDeviceCount 38 | ); 39 | 40 | for (vr::TrackedDeviceIndex_t unTrackedDevice = 0; 41 | unTrackedDevice < vr::k_unMaxTrackedDeviceCount; unTrackedDevice++) { 42 | // Forget about disconnected devices 43 | if (!m_rTrackedDevicePose[unTrackedDevice].bDeviceIsConnected) { 44 | continue; 45 | } 46 | 47 | // Treat different device types separately 48 | switch (vr->GetTrackedDeviceClass(unTrackedDevice)) { 49 | case vr::TrackedDeviceClass_HMD: { 50 | vrpn_Tracker_OpenVR_HMD *hmd{nullptr}; 51 | auto search = hmds.find(unTrackedDevice); 52 | if (search == hmds.end()) { 53 | std::unique_ptr newHMD = std::make_unique( 54 | "openvr/hmd/" + std::to_string(unTrackedDevice), 55 | connection, 56 | vr.get() 57 | ); 58 | hmd = newHMD.get(); 59 | hmds[unTrackedDevice] = std::move(newHMD); 60 | } else { 61 | hmd = search->second.get(); 62 | } 63 | hmd->updateTracking(&m_rTrackedDevicePose[unTrackedDevice]); 64 | hmd->mainloop(); 65 | break; 66 | } 67 | case vr::TrackedDeviceClass_Controller: { 68 | vrpn_Tracker_OpenVR_Controller *controller{nullptr}; 69 | auto search = controllers.find(unTrackedDevice); 70 | if (search == controllers.end()) { 71 | std::unique_ptr newController = std::make_unique( 72 | "openvr/controller/" + std::to_string(unTrackedDevice), 73 | connection, 74 | vr.get() 75 | ); 76 | controller = newController.get(); 77 | controllers[unTrackedDevice] = std::move(newController); 78 | } else { 79 | controller = search->second.get(); 80 | } 81 | controller->updateTracking(&m_rTrackedDevicePose[unTrackedDevice]); 82 | controller->updateController(unTrackedDevice); 83 | controller->mainloop(); 84 | break; 85 | } 86 | default: { 87 | break; 88 | } 89 | } 90 | } 91 | 92 | // Send and receive all messages. 93 | connection->mainloop(); 94 | 95 | // Bail if the connection is in trouble. 96 | if (!connection->doing_okay()) { 97 | std::cerr << "Connection is not doing ok. Should we bail?" << std::endl; 98 | } 99 | } 100 | 101 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | -------------------------------------------------------------------------------- /VRPN-OpenVR/VRPN-OpenVR.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {5A9FE86D-14AB-4247-8853-31B0717ACAB9} 23 | VRPNVive 24 | 8.1 25 | VRPN-OpenVR 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v140 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Level3 76 | Disabled 77 | true 78 | 79 | 80 | 81 | 82 | Level3 83 | Disabled 84 | true 85 | ../vendor/openvr/headers;../vendor/vrpn;../vendor/vrpn/quat;%(AdditionalIncludeDirectories) 86 | 87 | 88 | openvr_api.lib;vrpn.lib;quat.lib;%(AdditionalDependencies) 89 | ../vendor/vrpn/quat/$(IntDir);../vendor/vrpn/$(IntDir);../vendor/openvr/lib/win64;%(AdditionalLibraryDirectories) 90 | 91 | 92 | xcopy /y "$(ProjectDir)..\vendor\openvr\bin\win64\*.dll" "$(OutDir)" 93 | 94 | 95 | 96 | 97 | Level3 98 | MaxSpeed 99 | true 100 | true 101 | true 102 | 103 | 104 | true 105 | true 106 | 107 | 108 | 109 | 110 | Level3 111 | MaxSpeed 112 | true 113 | true 114 | true 115 | 116 | 117 | true 118 | true 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | {0c16e98c-a372-4e58-990d-ee276b32644e} 137 | 138 | 139 | {7ee1db03-16a5-4465-9164-061be0c88b8c} 140 | 141 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /.idea/vrpn-openvr.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | --------------------------------------------------------------------------------