diff --git a/README.md b/README.md index d9ae21d..658e800 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,11 @@ Edit file `C:\Users\\AppData\Local\openvr\openvrpaths.vrpath`, add `"P ## Contributions By contributing to this project you are placing all your code under MIT or less restricting licenses, and you certify that the code you have used is compatible with those licenses or is authored by you. If you're doing so on your work time, you certify that your employer is okay with this. + +### Building + +To build the project with VSCode you need to install two things: [vcpkg](https://vcpkg.io/en/getting-started.html) and [VS Build Tools](https://visualstudio.microsoft.com/downloads/). + +After installing vcpkg if you're on Windows, you need to run `vcpkg integrate install` command from the vcpkg folder to integrate it for VSCode. + +For other systems and IDEs instructions are not available as of now, contributions are welcome. diff --git a/src/ControllerDevice.cpp b/src/ControllerDevice.cpp deleted file mode 100644 index 157fbe4..0000000 --- a/src/ControllerDevice.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "ControllerDevice.hpp" - -SlimeVRDriver::ControllerDevice::ControllerDevice(std::string serial, int deviceId, ControllerDevice::Handedness handedness): - serial_(serial), handedness_(handedness), deviceId_(deviceId) -{ -} - -std::string SlimeVRDriver::ControllerDevice::GetSerial() -{ - return this->serial_; -} - -void SlimeVRDriver::ControllerDevice::Update() -{ - if (this->device_index_ == vr::k_unTrackedDeviceIndexInvalid) - return; - - // Check if this device was asked to be identified - auto events = GetDriver()->GetOpenVREvents(); - for (auto event : events) { - // Note here, event.trackedDeviceIndex does not necessarily equal this->device_index_, not sure why, but the component handle will match so we can just use that instead - //if (event.trackedDeviceIndex == this->device_index_) { - if (event.eventType == vr::EVREventType::VREvent_Input_HapticVibration) { - if (event.data.hapticVibration.componentHandle == this->haptic_component_) { - this->did_vibrate_ = true; - } - } - //} - } - - // Check if we need to keep vibrating - if (this->did_vibrate_) { - this->vibrate_anim_state_ += (GetDriver()->GetLastFrameTime().count()/1000.f); - if (this->vibrate_anim_state_ > 1.0f) { - this->did_vibrate_ = false; - this->vibrate_anim_state_ = 0.0f; - } - } -} - -DeviceType SlimeVRDriver::ControllerDevice::GetDeviceType() -{ - return DeviceType::CONTROLLER; -} - -SlimeVRDriver::ControllerDevice::Handedness SlimeVRDriver::ControllerDevice::GetHandedness() -{ - return this->handedness_; -} - -vr::TrackedDeviceIndex_t SlimeVRDriver::ControllerDevice::GetDeviceIndex() -{ - return this->device_index_; -} - -vr::EVRInitError SlimeVRDriver::ControllerDevice::Activate(uint32_t unObjectId) -{ - this->device_index_ = unObjectId; - - GetDriver()->Log("Activating controller " + this->serial_); - - // Get the properties handle - auto props = GetDriver()->GetProperties()->TrackedDeviceToPropertyContainer(this->device_index_); - - // Setup inputs and outputs - GetDriver()->GetInput()->CreateHapticComponent(props, "/output/haptic", &this->haptic_component_); - - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/a/click", &this->a_button_click_component_); - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/a/touch", &this->a_button_touch_component_); - - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/b/click", &this->b_button_click_component_); - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/b/touch", &this->b_button_touch_component_); - - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/trigger/click", &this->trigger_click_component_); - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/trigger/touch", &this->trigger_touch_component_); - GetDriver()->GetInput()->CreateScalarComponent(props, "/input/trigger/value", &this->trigger_value_component_, vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedOneSided); - - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/grip/touch", &this->grip_touch_component_); - GetDriver()->GetInput()->CreateScalarComponent(props, "/input/grip/value", &this->grip_value_component_, vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedOneSided); - GetDriver()->GetInput()->CreateScalarComponent(props, "/input/grip/force", &this->grip_force_component_, vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedOneSided); - - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/system/click", &this->system_click_component_); - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/system/touch", &this->system_touch_component_); - - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/trackpad/click", &this->trackpad_click_component_); - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/trackpad/touch", &this->trackpad_touch_component_); - GetDriver()->GetInput()->CreateScalarComponent(props, "/input/trackpad/x", &this->trackpad_x_component_, vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedTwoSided); - GetDriver()->GetInput()->CreateScalarComponent(props, "/input/trackpad/y", &this->trackpad_y_component_, vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedTwoSided); - - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/joystick/click", &this->joystick_click_component_); - GetDriver()->GetInput()->CreateBooleanComponent(props, "/input/joystick/touch", &this->joystick_touch_component_); - GetDriver()->GetInput()->CreateScalarComponent(props, "/input/joystick/x", &this->joystick_x_component_, vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedTwoSided); - GetDriver()->GetInput()->CreateScalarComponent(props, "/input/joystick/y", &this->joystick_y_component_, vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedTwoSided); - - // Set some universe ID (Must be 2 or higher) - GetDriver()->GetProperties()->SetUint64Property(props, vr::Prop_CurrentUniverseId_Uint64, 2); - - // Set up a model "number" (not needed but good to have) - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ModelNumber_String, "example_controller"); - - // Set up a render model path - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_RenderModelName_String, "{example}example_controller"); - - // Give SteamVR a hint at what hand this controller is for - if (this->handedness_ == Handedness::LEFT) { - GetDriver()->GetProperties()->SetInt32Property(props, vr::Prop_ControllerRoleHint_Int32, vr::ETrackedControllerRole::TrackedControllerRole_LeftHand); - } - else if (this->handedness_ == Handedness::RIGHT) { - GetDriver()->GetProperties()->SetInt32Property(props, vr::Prop_ControllerRoleHint_Int32, vr::ETrackedControllerRole::TrackedControllerRole_RightHand); - } - else { - GetDriver()->GetProperties()->SetInt32Property(props, vr::Prop_ControllerRoleHint_Int32, vr::ETrackedControllerRole::TrackedControllerRole_OptOut); - } - - // Set controller profile - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_InputProfilePath_String, "{example}/input/example_controller_bindings.json"); - - // Change the icon depending on which handedness this controller is using (ANY uses right) - std::string controller_handedness_str = this->handedness_ == Handedness::LEFT ? "left" : "right"; - std::string controller_ready_file = "{example}/icons/controller_ready_" + controller_handedness_str + ".png"; - std::string controller_not_ready_file = "{example}/icons/controller_not_ready_" + controller_handedness_str + ".png"; - - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReady_String, controller_ready_file.c_str()); - - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceOff_String, controller_not_ready_file.c_str()); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearching_String, controller_not_ready_file.c_str()); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearchingAlert_String, controller_not_ready_file.c_str()); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReadyAlert_String, controller_not_ready_file.c_str()); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceNotReady_String, controller_not_ready_file.c_str()); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceStandby_String, controller_not_ready_file.c_str()); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceAlertLow_String, controller_not_ready_file.c_str()); - - return vr::EVRInitError::VRInitError_None; -} - -void SlimeVRDriver::ControllerDevice::PositionMessage(messages::Position &position) -{ - if (this->device_index_ == vr::k_unTrackedDeviceIndexInvalid) - return; - - // Setup pose for this frame - auto pose = this->last_pose_; - //send the new position and rotation from the pipe to the tracker object - if(position.has_x()) { - pose.vecPosition[0] = position.x(); - pose.vecPosition[1] = position.y(); - pose.vecPosition[2] = position.z(); - } - - pose.qRotation.w = position.qw(); - pose.qRotation.x = position.qx(); - pose.qRotation.y = position.qy(); - pose.qRotation.z = position.qz(); - - // Post pose - GetDriver()->GetDriverHost()->TrackedDevicePoseUpdated(this->device_index_, pose, sizeof(vr::DriverPose_t)); - this->last_pose_ = pose; -} - -void SlimeVRDriver::ControllerDevice::Deactivate() -{ - this->device_index_ = vr::k_unTrackedDeviceIndexInvalid; -} - -void SlimeVRDriver::ControllerDevice::EnterStandby() -{ -} - -void* SlimeVRDriver::ControllerDevice::GetComponent(const char* pchComponentNameAndVersion) -{ - return nullptr; -} - -void SlimeVRDriver::ControllerDevice::DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize) -{ - if (unResponseBufferSize >= 1) - pchResponseBuffer[0] = 0; -} - -vr::DriverPose_t SlimeVRDriver::ControllerDevice::GetPose() -{ - return last_pose_; -} - -int SlimeVRDriver::ControllerDevice::getDeviceId() -{ - return deviceId_; -} diff --git a/src/ControllerDevice.hpp b/src/ControllerDevice.hpp deleted file mode 100644 index 850cd0a..0000000 --- a/src/ControllerDevice.hpp +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include -#include - -namespace SlimeVRDriver { - class ControllerDevice : public IVRDevice { - public: - - enum class Handedness { - LEFT, - RIGHT, - ANY - }; - - ControllerDevice(std::string serial, int deviceId, Handedness handedness = Handedness::ANY); - ~ControllerDevice() = default; - - // Inherited via IVRDevice - virtual std::string GetSerial() override; - virtual void Update() override; - virtual vr::TrackedDeviceIndex_t GetDeviceIndex() override; - virtual DeviceType GetDeviceType() override; - virtual Handedness GetHandedness(); - - virtual vr::EVRInitError Activate(uint32_t unObjectId) override; - virtual void Deactivate() override; - virtual void EnterStandby() override; - virtual void* GetComponent(const char* pchComponentNameAndVersion) override; - virtual void DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize) override; - virtual vr::DriverPose_t GetPose() override; - virtual int getDeviceId() override; - virtual void PositionMessage(messages::Position &position) override; - - private: - vr::TrackedDeviceIndex_t device_index_ = vr::k_unTrackedDeviceIndexInvalid; - std::string serial_; - Handedness handedness_; - - vr::DriverPose_t last_pose_; - - bool did_vibrate_ = false; - int deviceId_; - float vibrate_anim_state_ = 0.f; - - vr::VRInputComponentHandle_t haptic_component_ = 0; - - vr::VRInputComponentHandle_t a_button_click_component_ = 0; - vr::VRInputComponentHandle_t a_button_touch_component_ = 0; - - vr::VRInputComponentHandle_t b_button_click_component_ = 0; - vr::VRInputComponentHandle_t b_button_touch_component_ = 0; - - vr::VRInputComponentHandle_t trigger_value_component_ = 0; - vr::VRInputComponentHandle_t trigger_click_component_ = 0; - vr::VRInputComponentHandle_t trigger_touch_component_ = 0; - - vr::VRInputComponentHandle_t grip_touch_component_ = 0; - vr::VRInputComponentHandle_t grip_value_component_ = 0; - vr::VRInputComponentHandle_t grip_force_component_ = 0; - - vr::VRInputComponentHandle_t system_click_component_ = 0; - vr::VRInputComponentHandle_t system_touch_component_ = 0; - - - vr::VRInputComponentHandle_t trackpad_click_component_ = 0; - vr::VRInputComponentHandle_t trackpad_touch_component_ = 0; - vr::VRInputComponentHandle_t trackpad_x_component_ = 0; - vr::VRInputComponentHandle_t trackpad_y_component_ = 0; - - vr::VRInputComponentHandle_t joystick_click_component_ = 0; - vr::VRInputComponentHandle_t joystick_touch_component_ = 0; - vr::VRInputComponentHandle_t joystick_x_component_ = 0; - vr::VRInputComponentHandle_t joystick_y_component_ = 0; - - //vr::VRInputComponentHandle_t skeleton_left_component_ = 0; - //vr::VRInputComponentHandle_t skeleton_right_component_ = 0; - }; -}; \ No newline at end of file diff --git a/src/HMDDevice.cpp b/src/HMDDevice.cpp deleted file mode 100644 index 4b74f75..0000000 --- a/src/HMDDevice.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "HMDDevice.hpp" - -SlimeVRDriver::HMDDevice::HMDDevice(std::string serial, int deviceId): - serial_(serial), deviceId_(deviceId) -{ -} - -std::string SlimeVRDriver::HMDDevice::GetSerial() -{ - return this->serial_; -} - -void SlimeVRDriver::HMDDevice::Update() -{ - if (this->device_index_ == vr::k_unTrackedDeviceIndexInvalid) - return; -} - -void SlimeVRDriver::HMDDevice::PositionMessage(messages::Position &position) -{ - if (this->device_index_ == vr::k_unTrackedDeviceIndexInvalid) - return; - - // Setup pose for this frame - auto pose = this->last_pose_; - //send the new position and rotation from the pipe to the tracker object - if(position.has_x()) { - pose.vecPosition[0] = position.x(); - pose.vecPosition[1] = position.y(); - pose.vecPosition[2] = position.z(); - } - - pose.qRotation.w = position.qw(); - pose.qRotation.x = position.qx(); - pose.qRotation.y = position.qy(); - pose.qRotation.z = position.qz(); - - // Post pose - GetDriver()->GetDriverHost()->TrackedDevicePoseUpdated(this->device_index_, pose, sizeof(vr::DriverPose_t)); - this->last_pose_ = pose; -} - -DeviceType SlimeVRDriver::HMDDevice::GetDeviceType() -{ - return DeviceType::HMD; -} - -vr::TrackedDeviceIndex_t SlimeVRDriver::HMDDevice::GetDeviceIndex() -{ - return this->device_index_; -} - -vr::EVRInitError SlimeVRDriver::HMDDevice::Activate(uint32_t unObjectId) -{ - this->device_index_ = unObjectId; - - GetDriver()->Log("Activating HMD " + this->serial_); - - // Load settings values - // Could probably make this cleaner with making a wrapper class - try { - int window_x = std::get(GetDriver()->GetSettingsValue("window_x")); - if (window_x > 0) - this->window_x_ = window_x; - } - catch (const std::bad_variant_access&) {}; // Wrong type or doesn't exist - - try { - int window_y = std::get(GetDriver()->GetSettingsValue("window_y")); - if (window_y > 0) - this->window_x_ = window_y; - } - catch (const std::bad_variant_access&) {}; // Wrong type or doesn't exist - - try { - int window_width = std::get(GetDriver()->GetSettingsValue("window_width")); - if (window_width > 0) - this->window_width_ = window_width; - } - catch (const std::bad_variant_access&) {}; // Wrong type or doesn't exist - - try { - int window_height = std::get(GetDriver()->GetSettingsValue("window_height")); - if (window_height > 0) - this->window_height_ = window_height; - } - catch (const std::bad_variant_access&) {}; // Wrong type or doesn't exist - - // Get the properties handle - auto props = GetDriver()->GetProperties()->TrackedDeviceToPropertyContainer(this->device_index_); - - // Set some universe ID (Must be 2 or higher) - GetDriver()->GetProperties()->SetUint64Property(props, vr::Prop_CurrentUniverseId_Uint64, 2); - - // Set the IPD to be whatever steam has configured - GetDriver()->GetProperties()->SetFloatProperty(props, vr::Prop_UserIpdMeters_Float, vr::VRSettings()->GetFloat(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_IPD_Float)); - - // Set the display FPS - GetDriver()->GetProperties()->SetFloatProperty(props, vr::Prop_DisplayFrequency_Float, 90.f); - - // Set up a model "number" (not needed but good to have) - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ModelNumber_String, "EXAMPLE_HMD_DEVICE"); - - // Set up icon paths - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReady_String, "{example}/icons/hmd_ready.png"); - - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceOff_String, "{example}/icons/hmd_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearching_String, "{example}/icons/hmd_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearchingAlert_String, "{example}/icons/hmd_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{example}/icons/hmd_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceNotReady_String, "{example}/icons/hmd_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceStandby_String, "{example}/icons/hmd_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceAlertLow_String, "{example}/icons/hmd_not_ready.png"); - - - - - return vr::EVRInitError::VRInitError_None; -} - -void SlimeVRDriver::HMDDevice::Deactivate() -{ - this->device_index_ = vr::k_unTrackedDeviceIndexInvalid; -} - -void SlimeVRDriver::HMDDevice::EnterStandby() -{ -} - -void* SlimeVRDriver::HMDDevice::GetComponent(const char* pchComponentNameAndVersion) -{ - if (!std::strcmp(pchComponentNameAndVersion, vr::IVRDisplayComponent_Version)) { - return static_cast(this); - } - return nullptr; -} - -void SlimeVRDriver::HMDDevice::DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize) -{ - if (unResponseBufferSize >= 1) - pchResponseBuffer[0] = 0; -} - -vr::DriverPose_t SlimeVRDriver::HMDDevice::GetPose() -{ - return this->last_pose_; -} - -void SlimeVRDriver::HMDDevice::GetWindowBounds(int32_t* pnX, int32_t* pnY, uint32_t* pnWidth, uint32_t* pnHeight) -{ - *pnX = this->window_x_; - *pnY = this->window_y_; - *pnWidth = this->window_width_; - *pnHeight = this->window_height_; -} - -bool SlimeVRDriver::HMDDevice::IsDisplayOnDesktop() -{ - return true; -} - -bool SlimeVRDriver::HMDDevice::IsDisplayRealDisplay() -{ - return false; -} - -void SlimeVRDriver::HMDDevice::GetRecommendedRenderTargetSize(uint32_t* pnWidth, uint32_t* pnHeight) -{ - *pnWidth = this->window_width_; - *pnHeight = this->window_height_; -} - -void SlimeVRDriver::HMDDevice::GetEyeOutputViewport(vr::EVREye eEye, uint32_t* pnX, uint32_t* pnY, uint32_t* pnWidth, uint32_t* pnHeight) -{ - *pnY = 0; - *pnWidth = this->window_width_ / 2; - *pnHeight = this->window_height_; - - if (eEye == vr::EVREye::Eye_Left) { - *pnX = 0; - } - else { - *pnX = this->window_width_ / 2; - } -} - -void SlimeVRDriver::HMDDevice::GetProjectionRaw(vr::EVREye eEye, float* pfLeft, float* pfRight, float* pfTop, float* pfBottom) -{ - *pfLeft = -1; - *pfRight = 1; - *pfTop = -1; - *pfBottom = 1; -} - -vr::DistortionCoordinates_t SlimeVRDriver::HMDDevice::ComputeDistortion(vr::EVREye eEye, float fU, float fV) -{ - vr::DistortionCoordinates_t coordinates; - coordinates.rfBlue[0] = fU; - coordinates.rfBlue[1] = fV; - coordinates.rfGreen[0] = fU; - coordinates.rfGreen[1] = fV; - coordinates.rfRed[0] = fU; - coordinates.rfRed[1] = fV; - return coordinates; -} - -int SlimeVRDriver::HMDDevice::getDeviceId() -{ - return deviceId_; -} \ No newline at end of file diff --git a/src/HMDDevice.hpp b/src/HMDDevice.hpp deleted file mode 100644 index a38e59d..0000000 --- a/src/HMDDevice.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include -#include - -namespace SlimeVRDriver { - class HMDDevice : public IVRDevice, public vr::IVRDisplayComponent { - public: - HMDDevice(std::string serial, int deviceId); - ~HMDDevice() = default; - - // Inherited via IVRDevice - virtual std::string GetSerial() override; - virtual void Update() override; - virtual vr::TrackedDeviceIndex_t GetDeviceIndex() override; - virtual DeviceType GetDeviceType() override; - - virtual vr::EVRInitError Activate(uint32_t unObjectId) override; - virtual void Deactivate() override; - virtual void EnterStandby() override; - virtual void* GetComponent(const char* pchComponentNameAndVersion) override; - virtual void DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize) override; - virtual vr::DriverPose_t GetPose() override; - - // Inherited via IVRDisplayComponent - virtual void GetWindowBounds(int32_t* pnX, int32_t* pnY, uint32_t* pnWidth, uint32_t* pnHeight) override; - virtual bool IsDisplayOnDesktop() override; - virtual bool IsDisplayRealDisplay() override; - virtual void GetRecommendedRenderTargetSize(uint32_t* pnWidth, uint32_t* pnHeight) override; - virtual void GetEyeOutputViewport(vr::EVREye eEye, uint32_t* pnX, uint32_t* pnY, uint32_t* pnWidth, uint32_t* pnHeight) override; - virtual void GetProjectionRaw(vr::EVREye eEye, float* pfLeft, float* pfRight, float* pfTop, float* pfBottom) override; - virtual vr::DistortionCoordinates_t ComputeDistortion(vr::EVREye eEye, float fU, float fV) override; - virtual int getDeviceId() override; - virtual void PositionMessage(messages::Position &position) override; - private: - vr::TrackedDeviceIndex_t device_index_ = vr::k_unTrackedDeviceIndexInvalid; - std::string serial_; - int deviceId_; - - vr::DriverPose_t last_pose_ = IVRDevice::MakeDefaultPose(); - - uint32_t window_x_ = 0; - uint32_t window_y_ = 0; - uint32_t window_width_ = 1920; - uint32_t window_height_ = 1080; - - float pos_x_ = 0, pos_y_ = 0, pos_z_ = 0; - float rot_y_ = 0, rot_x_ = 0; - - }; -}; \ No newline at end of file diff --git a/src/TrackingReferenceDevice.cpp b/src/TrackingReferenceDevice.cpp deleted file mode 100644 index 90a5add..0000000 --- a/src/TrackingReferenceDevice.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "TrackingReferenceDevice.hpp" - -SlimeVRDriver::TrackingReferenceDevice::TrackingReferenceDevice(std::string serial): - serial_(serial) -{ - - // Get some random angle to place this tracking reference at in the scene - this->random_angle_rad_ = fmod(rand() / 10000.f, 2 * 3.14159f); -} - -std::string SlimeVRDriver::TrackingReferenceDevice::GetSerial() -{ - return this->serial_; -} - -void SlimeVRDriver::TrackingReferenceDevice::Update() -{ - if (this->device_index_ == vr::k_unTrackedDeviceIndexInvalid) - return; -} - -DeviceType SlimeVRDriver::TrackingReferenceDevice::GetDeviceType() -{ - return DeviceType::TRACKING_REFERENCE; -} - -vr::TrackedDeviceIndex_t SlimeVRDriver::TrackingReferenceDevice::GetDeviceIndex() -{ - return this->device_index_; -} - -vr::EVRInitError SlimeVRDriver::TrackingReferenceDevice::Activate(uint32_t unObjectId) -{ - this->device_index_ = unObjectId; - - GetDriver()->Log("Activating tracking reference " + this->serial_); - - // Get the properties handle - auto props = GetDriver()->GetProperties()->TrackedDeviceToPropertyContainer(this->device_index_); - - // Set some universe ID (Must be 2 or higher) - GetDriver()->GetProperties()->SetUint64Property(props, vr::Prop_CurrentUniverseId_Uint64, 2); - - // Set up a model "number" (not needed but good to have) - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_ModelNumber_String, "example_trackingreference"); - - // Set up a render model path - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_RenderModelName_String, "locator"); - - // Set the icons - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReady_String, "{example}/icons/trackingreference_ready.png"); - - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceOff_String, "{example}/icons/trackingreference_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearching_String, "{example}/icons/trackingreference_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceSearchingAlert_String, "{example}/icons/trackingreference_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{example}/icons/trackingreference_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceNotReady_String, "{example}/icons/trackingreference_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceStandby_String, "{example}/icons/trackingreference_not_ready.png"); - GetDriver()->GetProperties()->SetStringProperty(props, vr::Prop_NamedIconPathDeviceAlertLow_String, "{example}/icons/trackingreference_not_ready.png"); - - return vr::EVRInitError::VRInitError_None; -} - -void SlimeVRDriver::TrackingReferenceDevice::Deactivate() -{ - this->device_index_ = vr::k_unTrackedDeviceIndexInvalid; -} - -void SlimeVRDriver::TrackingReferenceDevice::EnterStandby() -{ -} - -void* SlimeVRDriver::TrackingReferenceDevice::GetComponent(const char* pchComponentNameAndVersion) -{ - return nullptr; -} - -void SlimeVRDriver::TrackingReferenceDevice::DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize) -{ - if (unResponseBufferSize >= 1) - pchResponseBuffer[0] = 0; -} - -vr::DriverPose_t SlimeVRDriver::TrackingReferenceDevice::GetPose() -{ - return last_pose_; -} - -void SlimeVRDriver::TrackingReferenceDevice::PositionMessage(messages::Position &position) -{ - if (this->device_index_ == vr::k_unTrackedDeviceIndexInvalid) - return; - - // Setup pose for this frame - auto pose = this->last_pose_; - //send the new position and rotation from the pipe to the tracker object - if(position.has_x()) { - pose.vecPosition[0] = position.x(); - pose.vecPosition[1] = position.y(); - pose.vecPosition[2] = position.z(); - } - - pose.qRotation.w = position.qw(); - pose.qRotation.x = position.qx(); - pose.qRotation.y = position.qy(); - pose.qRotation.z = position.qz(); - - // Post pose - GetDriver()->GetDriverHost()->TrackedDevicePoseUpdated(this->device_index_, pose, sizeof(vr::DriverPose_t)); - this->last_pose_ = pose; -} diff --git a/src/TrackingReferenceDevice.hpp b/src/TrackingReferenceDevice.hpp deleted file mode 100644 index 580de01..0000000 --- a/src/TrackingReferenceDevice.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include -#include - -#include - -#include -#include - -namespace SlimeVRDriver { - class TrackingReferenceDevice : public IVRDevice { - public: - - TrackingReferenceDevice(std::string serial); - ~TrackingReferenceDevice() = default; - - // Inherited via IVRDevice - virtual std::string GetSerial() override; - virtual void Update() override; - virtual vr::TrackedDeviceIndex_t GetDeviceIndex() override; - virtual DeviceType GetDeviceType() override; - - virtual vr::EVRInitError Activate(uint32_t unObjectId) override; - virtual void Deactivate() override; - virtual void EnterStandby() override; - virtual void* GetComponent(const char* pchComponentNameAndVersion) override; - virtual void DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize) override; - virtual vr::DriverPose_t GetPose() override; - virtual void PositionMessage(messages::Position &position) override; - - private: - vr::TrackedDeviceIndex_t device_index_ = vr::k_unTrackedDeviceIndexInvalid; - std::string serial_; - - vr::DriverPose_t last_pose_ = IVRDevice::MakeDefaultPose(); - - float random_angle_rad_; - - }; -}; \ No newline at end of file diff --git a/src/VRDriver.cpp b/src/VRDriver.cpp index cf25c31..7174d2c 100644 --- a/src/VRDriver.cpp +++ b/src/VRDriver.cpp @@ -1,8 +1,5 @@ #include "VRDriver.hpp" -#include #include -#include -#include #include "bridge/bridge.hpp" #include "TrackerRole.hpp" #include