├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── je_nourish_openhmd.cpp ├── je_nourish_openhmd.json └── sample-configs ├── Oculus_Rift_DK1.json ├── osvr_server_config.json └── renderManager.extended.landscape.json /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/hidapi"] 2 | path = vendor/hidapi 3 | url = https://github.com/signal11/hidapi 4 | [submodule "vendor/OpenHMD"] 5 | path = vendor/OpenHMD 6 | url = https://github.com/OpenHMD/OpenHMD 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(OpenHMDPlugin) 3 | 4 | find_package(osvr REQUIRED) 5 | 6 | # OpenHMD 7 | set(OPENHMD_DIR "${CMAKE_CURRENT_LIST_DIR}/vendor/OpenHMD") 8 | include_directories(${OPENHMD_DIR}/include) 9 | set(OPENHMD_SOURCES 10 | ${OPENHMD_DIR}/src/openhmd.c 11 | ${OPENHMD_DIR}/src/platform-win32.c 12 | ${OPENHMD_DIR}/src/drv_dummy/dummy.c 13 | ${OPENHMD_DIR}/src/omath.c 14 | ${OPENHMD_DIR}/src/platform-posix.c 15 | ${OPENHMD_DIR}/src/fusion.c 16 | ) 17 | OPTION(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1 and DK2" ON) 18 | OPTION(OPENHMD_DRIVER_EXTERNAL "External sensor driver" OFF) 19 | OPTION(OPENHMD_DRIVER_ANDROID "General Android driver" OFF) 20 | 21 | if(OPENHMD_DRIVER_OCULUS_RIFT) 22 | set(OPENHMD_SOURCES ${OPENHMD_SOURCES} 23 | ${OPENHMD_DIR}/src/drv_oculus_rift/rift.c 24 | ${OPENHMD_DIR}/src/drv_oculus_rift/packet.c 25 | ) 26 | add_definitions(-DDRIVER_OCULUS_RIFT) 27 | endif(OPENHMD_DRIVER_OCULUS_RIFT) 28 | 29 | if (OPENHMD_DRIVER_EXTERNAL) 30 | set(OPENHMD_SOURCES ${OPENHMD_SOURCES} 31 | ${OPENHMD_DIR}/src/drv_external/external.c 32 | ) 33 | add_definitions(-DDRIVER_EXTERNAL) 34 | endif(OPENHMD_DRIVER_EXTERNAL) 35 | 36 | if (OPENHMD_DRIVER_ANDROID) 37 | set(OPENHMD_SOURCES ${OPENHMD_SOURCES} 38 | ${OPENHMD_DIR}/src/drv_android/android.c 39 | ) 40 | add_definitions(-DDRIVER_ANDROID) 41 | endif(OPENHMD_DRIVER_ANDROID) 42 | 43 | add_definitions(-DOHMD_STATIC) 44 | 45 | if (WIN32) 46 | execute_process(COMMAND powershell -Command "(gc ${OPENHMD_DIR}/src/platform-win32.c) -replace '__stdcall DWORD', 'DWORD __stdcall' | Out-File ${OPENHMD_DIR}/src/platform-win32.c") 47 | endif(WIN32) 48 | 49 | # HIDAPI 50 | set(HIDAPI_DIR "${CMAKE_CURRENT_LIST_DIR}/vendor/hidapi") 51 | include_directories(${HIDAPI_DIR}/hidapi) 52 | 53 | IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 54 | set (HIDAPI_SOURCES ${HIDAPI_DIR}/mac/hid.c) 55 | set (LIBS ${LIBS} "-framework CoreFoundation -framework IOKit") 56 | ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 57 | 58 | if (WIN32) 59 | set (HIDAPI_SOURCES ${HIDAPI_DIR}/windows/hid.c) 60 | set (LIBS ${LIBS} setupapi) 61 | endif(WIN32) 62 | 63 | IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 64 | set (HIDAPI_SOURCES ${HIDAPI_DIR}/libusb/hid.c) 65 | find_package(PkgConfig REQUIRED) 66 | pkg_search_module(LIBUSB REQUIRED libusb-1.0) 67 | set (LIBS ${LIBS} ${LIBUSB_LIBRARIES}) 68 | include_directories(${LIBUSB_INCLUDE_DIRS}) 69 | ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 70 | 71 | # OSVR Plugin 72 | osvr_convert_json(je_nourish_openhmd_json 73 | je_nourish_openhmd.json 74 | "${CMAKE_CURRENT_BINARY_DIR}/je_nourish_openhmd_json.h") 75 | 76 | include_directories("${CMAKE_CURRENT_BINARY_DIR}") 77 | 78 | osvr_add_plugin(NAME je_nourish_openhmd 79 | CPP # indicates we'd like to use the C++ wrapper 80 | SOURCES 81 | je_nourish_openhmd.cpp 82 | "${CMAKE_CURRENT_BINARY_DIR}/je_nourish_openhmd_json.h" 83 | ${HIDAPI_SOURCES} 84 | ${OPENHMD_SOURCES}) 85 | 86 | target_link_libraries(je_nourish_openhmd ${LIBS}) 87 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Steve Le Roy Harris 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OSVR-OpenHMD Plugin [![Donate](https://nourish.je/assets/images/donate.svg)](http://ko-fi.com/A250KJT) 2 | 3 | This is an OSVR plugin providing Oculus Rift DK1 & DK2 orientation tracking via OpenHMD. OpenHMD and hidapi are embedded so you don't need those libraries installed. 4 | 5 | git clone https://github.com/simlrh/OSVR-OpenHMD 6 | cd OSVR-OpenHMD 7 | git submodule init 8 | git submodule update 9 | 10 | Then follow [the standard OSVR plugin build instructions](http://resource.osvr.com/docs/OSVR-Core/TopicWritingDevicePlugin.html). 11 | 12 | Tested on Windows, Linux and Mac. 64 bit binaries available on the releases page. 13 | 14 | The tracker device doesn't need configuration, but there are sample OSVR server config files for the DK1 display in the sample-configs folder. 15 | -------------------------------------------------------------------------------- /je_nourish_openhmd.cpp: -------------------------------------------------------------------------------- 1 | // Internal Includes 2 | #include 3 | #include 4 | 5 | // Generated JSON header file 6 | #include "je_nourish_openhmd_json.h" 7 | 8 | // Library/third-party includes 9 | #include 10 | 11 | // Standard includes 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace { 18 | 19 | class OculusHMD { 20 | public: 21 | OculusHMD(OSVR_PluginRegContext ctx, ohmd_context* ohmd_ctx, int i) : m_context(ohmd_ctx) { 22 | std::string name ("Oculus "); 23 | name.append(ohmd_list_gets(m_context, i, OHMD_PRODUCT)); 24 | 25 | m_device = ohmd_list_open_device(m_context, i); 26 | 27 | OSVR_DeviceInitOptions opts = osvrDeviceCreateInitOptions(ctx); 28 | osvrDeviceTrackerConfigure(opts, &m_tracker); 29 | 30 | m_dev.initAsync(ctx, name.c_str(), opts); 31 | m_dev.sendJsonDescriptor(je_nourish_openhmd_json); 32 | m_dev.registerUpdateCallback(this); 33 | 34 | osvrQuatSetIdentity(&m_state); 35 | } 36 | 37 | ~OculusHMD() { 38 | ohmd_close_device(m_device); 39 | } 40 | 41 | OSVR_ReturnCode update() { 42 | ohmd_ctx_update(m_context); 43 | 44 | float quat[4]; 45 | ohmd_device_getf(m_device, OHMD_ROTATION_QUAT, quat); 46 | 47 | osvrQuatSetX(&m_state, quat[0]); 48 | osvrQuatSetY(&m_state, quat[1]); 49 | osvrQuatSetZ(&m_state, quat[2]); 50 | osvrQuatSetW(&m_state, quat[3]); 51 | 52 | osvrDeviceTrackerSendOrientation(m_dev, m_tracker, &m_state, 0); 53 | 54 | return OSVR_RETURN_SUCCESS; 55 | } 56 | 57 | private: 58 | osvr::pluginkit::DeviceToken m_dev; 59 | OSVR_TrackerDeviceInterface m_tracker; 60 | OSVR_Quaternion m_state; 61 | ohmd_context* m_context; 62 | ohmd_device* m_device; 63 | }; 64 | 65 | class HardwareDetection { 66 | public: 67 | HardwareDetection() : m_found(false) { 68 | ohmd_ctx = ohmd_ctx_create(); 69 | } 70 | 71 | ~HardwareDetection() { 72 | ohmd_ctx_destroy(ohmd_ctx); 73 | } 74 | 75 | OSVR_ReturnCode operator()(OSVR_PluginRegContext ctx) { 76 | 77 | if (!m_found) { 78 | int num_devices = ohmd_ctx_probe(ohmd_ctx); 79 | 80 | if (num_devices < 0) { 81 | std::cout << "OpenHMD failed to probe devices: " << ohmd_ctx_get_error(ohmd_ctx) << std::endl; 82 | return OSVR_RETURN_FAILURE; 83 | } 84 | 85 | std::string product; 86 | 87 | for (int i = 0; i < num_devices; i++) { 88 | 89 | product = ohmd_list_gets(ohmd_ctx, i, OHMD_PRODUCT); 90 | 91 | if (product.compare("Dummy Device") != 0) { 92 | osvr::pluginkit::registerObjectForDeletion( 93 | ctx, new OculusHMD(ctx, ohmd_ctx, i)); 94 | m_found = true; 95 | } 96 | } 97 | } 98 | 99 | 100 | return OSVR_RETURN_SUCCESS; 101 | } 102 | 103 | private: 104 | ohmd_context* ohmd_ctx; 105 | bool m_found; 106 | 107 | 108 | }; 109 | } // namespace 110 | 111 | OSVR_PLUGIN(je_nourish_openhmd) { 112 | osvr::pluginkit::PluginContext context(ctx); 113 | 114 | context.registerHardwareDetectCallback(new HardwareDetection()); 115 | 116 | return OSVR_RETURN_SUCCESS; 117 | } 118 | -------------------------------------------------------------------------------- /je_nourish_openhmd.json: -------------------------------------------------------------------------------- 1 | { 2 | "deviceVendor": "Oculus VR", 3 | "deviceName": "Oculus Rift Trackers/Sensors (via OpenHMD)", 4 | "author": "Steve Le Roy Harris ", 5 | "version": 1, 6 | "lastModified": "2016-06-21T09:35:07.585Z", 7 | "interfaces": { 8 | "tracker": { 9 | "count": 1, 10 | "position": false, 11 | "orientation": true 12 | } 13 | }, 14 | "semantic": { 15 | "hmd": "tracker/0" 16 | }, 17 | "automaticAliases": { 18 | "/me/head": "semantic/hmd" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample-configs/Oculus_Rift_DK1.json: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "schemaVersion": 1 4 | }, 5 | "hmd": { 6 | "device": { 7 | "vendor": "Oculus", 8 | "model": "Rift", 9 | "num_displays": 1, 10 | "Version": "DK1", 11 | "Note": "" 12 | }, 13 | "field_of_view": { 14 | "monocular_horizontal": 83, 15 | "monocular_vertical": 92, 16 | "overlap_percent": 93, 17 | "pitch_tilt": 0 18 | }, 19 | "resolutions": [ 20 | { 21 | "width": 1280, 22 | "height": 800, 23 | "video_inputs": 1, 24 | "display_mode": "horz_side_by_side", 25 | "swap_eyes": 0 26 | } 27 | ], 28 | "distortion": { 29 | "distance_scale_x": 1, 30 | "distance_scale_y": 1, 31 | "polynomial_coeffs_red": [ 0, 1, 0.22, 0.24 ], 32 | "polynomial_coeffs_green": [ 0, 1, 0.22, 0.24 ], 33 | "polynomial_coeffs_blue": [ 0, 1, 0.22, 0.24 ] 34 | }, 35 | "rendering": { 36 | "right_roll": 0, 37 | "left_roll": 0 38 | }, 39 | "eyes": [ 40 | { 41 | "center_proj_x": 0.576, 42 | "center_proj_y": 0.5, 43 | "rotate_180": 0 44 | }, 45 | { 46 | "center_proj_x": 0.424, 47 | "center_proj_y": 0.5, 48 | "rotate_180": 0 49 | } 50 | ] 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sample-configs/osvr_server_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "display": "Oculus_Rift_DK1.json", 3 | "renderManagerConfig": "renderManager.extended.landscape.json" 4 | } 5 | -------------------------------------------------------------------------------- /sample-configs/renderManager.extended.landscape.json: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "schemaVersion": 1 4 | }, 5 | "renderManagerConfig": { 6 | "directModeEnabled": false, 7 | "directDisplayIndex": 0, 8 | "directHighPriorityEnabled": true, 9 | "numBuffers": 2, 10 | "verticalSyncEnabled": true, 11 | "verticalSyncBlockRenderingEnabled": true, 12 | "renderOverfillFactor": 1.5, 13 | "renderOversampleFactor": 1.0, 14 | 15 | "window": { 16 | "title": "OSVR", 17 | "fullScreenEnabled": true, 18 | "xPosition": 1920, // Change this to put the window onto your HMD display 19 | "yPosition": 0 20 | }, 21 | 22 | "display": { 23 | "rotation": 0, 24 | "bitsPerColor": 8 25 | }, 26 | 27 | "prediction": { 28 | "enabled": true, 29 | "staticDelayMS": 48, 30 | "leftEyeDelayMS": 7.5, 31 | "rightEyeDelayMS": 0, 32 | "localTimeOverride": true 33 | }, 34 | 35 | "timeWarp": { 36 | "enabled": true, 37 | "asynchronous": false, 38 | "maxMsBeforeVSync": 5 39 | } 40 | } 41 | } 42 | --------------------------------------------------------------------------------