-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
InfiniteLlamas
committed
Feb 3, 2018
1 parent
48d1b06
commit df1a41a
Showing
13 changed files
with
593 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.vs/ | ||
Debug/ | ||
*.sln | ||
*.vc* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include "DummyController.h" | ||
|
||
DummyController::DummyController() | ||
{ | ||
} | ||
|
||
DummyController::DummyController(std::string serial, bool side, DriverPose_t initial_pose, VRControllerState_t initial_state) : | ||
serial_(serial), | ||
side_(side), | ||
controller_pose_(initial_pose), | ||
controller_state_(initial_state) | ||
{ | ||
} | ||
|
||
DummyController::~DummyController() | ||
{ | ||
} | ||
|
||
void DummyController::updateControllerState(VRControllerState_t new_state) | ||
{ | ||
controller_state_ = new_state; | ||
} | ||
|
||
void DummyController::updateControllerPose(DriverPose_t new_pose) | ||
{ | ||
controller_pose_ = new_pose; | ||
} | ||
|
||
uint32_t DummyController::getObjectID() | ||
{ | ||
return object_id_; | ||
} | ||
|
||
VRControllerState_t DummyController::GetControllerState() | ||
{ | ||
return controller_state_; | ||
} | ||
|
||
bool DummyController::TriggerHapticPulse(uint32_t unAxisId, uint16_t usPulseDurationMicroseconds) | ||
{ | ||
return false; | ||
} | ||
|
||
EVRInitError DummyController::Activate(uint32_t unObjectId) | ||
{ | ||
object_id_ = unObjectId; | ||
|
||
PropertyContainerHandle_t prop_handle = VRProperties()->TrackedDeviceToPropertyContainer(unObjectId); | ||
|
||
VRProperties()->SetBoolProperty(prop_handle, vr::Prop_WillDriftInYaw_Bool, false); | ||
VRProperties()->SetBoolProperty(prop_handle, vr::Prop_DeviceIsWireless_Bool, true); | ||
VRProperties()->SetBoolProperty(prop_handle, vr::Prop_HasControllerComponent_Bool, true); | ||
|
||
if (side_) { | ||
VRProperties()->SetInt32Property(prop_handle, vr::Prop_ControllerRoleHint_Int32, ETrackedControllerRole::TrackedControllerRole_RightHand); | ||
}else { | ||
VRProperties()->SetInt32Property(prop_handle, vr::Prop_ControllerRoleHint_Int32, ETrackedControllerRole::TrackedControllerRole_LeftHand); | ||
} | ||
|
||
VRProperties()->SetInt32Property(prop_handle, vr::Prop_Axis0Type_Int32, vr::k_eControllerAxis_TrackPad); | ||
VRProperties()->SetInt32Property(prop_handle, vr::Prop_Axis1Type_Int32, vr::k_eControllerAxis_Trigger); | ||
|
||
VRProperties()->SetStringProperty(prop_handle, Prop_SerialNumber_String, serial_.c_str()); | ||
VRProperties()->SetStringProperty(prop_handle, Prop_ModelNumber_String, "Vive Controller MV"); | ||
VRProperties()->SetStringProperty(prop_handle, Prop_RenderModelName_String, "vr_controller_vive_1_5"); | ||
VRProperties()->SetStringProperty(prop_handle, Prop_ManufacturerName_String, "HTC"); | ||
|
||
uint64_t available_buttons = vr::ButtonMaskFromId(vr::k_EButton_ApplicationMenu) | | ||
vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Touchpad) | | ||
vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Trigger) | | ||
vr::ButtonMaskFromId(vr::k_EButton_System) | | ||
vr::ButtonMaskFromId(vr::k_EButton_Grip); | ||
|
||
vr::VRProperties()->SetUint64Property(prop_handle, Prop_SupportedButtons_Uint64, available_buttons); | ||
|
||
return EVRInitError::VRInitError_None; | ||
} | ||
|
||
void DummyController::Deactivate() | ||
{ | ||
} | ||
|
||
void DummyController::EnterStandby() | ||
{ | ||
} | ||
|
||
void * DummyController::GetComponent(const char * pchComponentNameAndVersion) | ||
{ | ||
if (0 == strcmp(IVRControllerComponent_Version, pchComponentNameAndVersion)) | ||
{ | ||
return (vr::IVRControllerComponent*)this; | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
void DummyController::DebugRequest(const char * pchRequest, char * pchResponseBuffer, uint32_t unResponseBufferSize) | ||
{ | ||
if (unResponseBufferSize >= 1) | ||
pchResponseBuffer[0] = 0; | ||
} | ||
|
||
DriverPose_t DummyController::GetPose() | ||
{ | ||
return controller_pose_; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <openvr_driver.h> | ||
using namespace vr; | ||
|
||
class DummyController : public ITrackedDeviceServerDriver, public IVRControllerComponent | ||
{ | ||
public: | ||
DummyController(); | ||
|
||
DummyController(std::string serial, bool side, DriverPose_t initial_pose, VRControllerState_t initial_state); | ||
|
||
virtual ~DummyController(); | ||
|
||
virtual void updateControllerState(VRControllerState_t new_state); | ||
|
||
virtual void updateControllerPose(DriverPose_t new_pose); | ||
|
||
virtual uint32_t getObjectID(); | ||
|
||
/* | ||
Inherited from ITrackedDeviceServerDriver: | ||
*/ | ||
|
||
EVRInitError Activate(uint32_t unObjectId) override; | ||
|
||
void Deactivate() override; | ||
|
||
void EnterStandby() override; | ||
|
||
void *GetComponent(const char* pchComponentNameAndVersion) override; | ||
|
||
void DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize) override; | ||
|
||
DriverPose_t GetPose() override; | ||
|
||
/* | ||
Inherited from IVRControllerComponent: | ||
*/ | ||
|
||
VRControllerState_t GetControllerState() override; | ||
|
||
bool TriggerHapticPulse(uint32_t unAxisId, uint16_t usPulseDurationMicroseconds) override; | ||
|
||
private: | ||
VRControllerState_t controller_state_; | ||
|
||
DriverPose_t controller_pose_; | ||
|
||
uint32_t object_id_; | ||
|
||
std::string serial_; | ||
|
||
bool side_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#include "DummyHMD.h" | ||
|
||
DummyHMD::DummyHMD() | ||
{ | ||
|
||
} | ||
|
||
DummyHMD::DummyHMD(std::string serial, DriverPose_t initial_pose): | ||
serial_(serial), | ||
hmd_pose_(initial_pose) | ||
{ | ||
} | ||
|
||
DummyHMD::~DummyHMD() | ||
{ | ||
} | ||
|
||
void DummyHMD::updateHMDPose(DriverPose_t new_pose) | ||
{ | ||
hmd_pose_ = new_pose; | ||
} | ||
|
||
uint32_t DummyHMD::getObjectID() | ||
{ | ||
return object_id_; | ||
} | ||
|
||
EVRInitError DummyHMD::Activate(uint32_t unObjectId) | ||
{ | ||
object_id_ = unObjectId; | ||
PropertyContainerHandle_t prop_handle = VRProperties()->TrackedDeviceToPropertyContainer(object_id_); | ||
VRProperties()->SetFloatProperty(prop_handle, Prop_UserIpdMeters_Float, 0.065f); | ||
VRProperties()->SetFloatProperty(prop_handle, Prop_UserHeadToEyeDepthMeters_Float, 0.f); | ||
VRProperties()->SetFloatProperty(prop_handle, Prop_DisplayFrequency_Float, 90.f); | ||
VRProperties()->SetFloatProperty(prop_handle, Prop_SecondsFromVsyncToPhotons_Float, 0.1f); | ||
VRProperties()->SetUint64Property(prop_handle, Prop_CurrentUniverseId_Uint64, 2); | ||
|
||
hmd_pose_.poseIsValid = true; | ||
hmd_pose_.result = TrackingResult_Running_OK; | ||
hmd_pose_.deviceIsConnected = true; | ||
|
||
hmd_pose_.qWorldFromDriverRotation = { 1, 0, 0, 0 }; | ||
hmd_pose_.qDriverFromHeadRotation = { 1, 0, 0, 0 }; | ||
|
||
return EVRInitError::VRInitError_None; | ||
} | ||
|
||
void DummyHMD::Deactivate() | ||
{ | ||
} | ||
|
||
void DummyHMD::EnterStandby() | ||
{ | ||
} | ||
|
||
void * DummyHMD::GetComponent(const char * pchComponentNameAndVersion) | ||
{ | ||
if (0 == strcmp(pchComponentNameAndVersion, vr::IVRDisplayComponent_Version)) | ||
{ | ||
return (vr::IVRDisplayComponent*)this; | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
void DummyHMD::DebugRequest(const char * pchRequest, char * pchResponseBuffer, uint32_t unResponseBufferSize) | ||
{ | ||
if (unResponseBufferSize >= 1) | ||
pchResponseBuffer[0] = 0; | ||
} | ||
|
||
DriverPose_t DummyHMD::GetPose() | ||
{ | ||
return hmd_pose_; | ||
} | ||
|
||
void DummyHMD::GetWindowBounds(int32_t * pnX, int32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight) | ||
{ | ||
*pnX = window_x_; | ||
*pnY = window_y_; | ||
*pnWidth = window_width_; | ||
*pnHeight = window_height_; | ||
} | ||
|
||
bool DummyHMD::IsDisplayOnDesktop() | ||
{ | ||
return true; | ||
} | ||
|
||
bool DummyHMD::IsDisplayRealDisplay() | ||
{ | ||
return false; | ||
} | ||
|
||
void DummyHMD::GetRecommendedRenderTargetSize(uint32_t * pnWidth, uint32_t * pnHeight) | ||
{ | ||
*pnWidth = window_width_; | ||
*pnHeight = window_height_; | ||
} | ||
|
||
void DummyHMD::GetEyeOutputViewport(EVREye eEye, uint32_t * pnX, uint32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight) | ||
{ | ||
*pnY = 0; | ||
*pnWidth = (window_width_ / 2) - separation_; | ||
*pnHeight = window_height_; | ||
|
||
if (eEye == Eye_Left) | ||
{ | ||
*pnX = separation_; | ||
} | ||
else | ||
{ | ||
*pnX = window_width_ / 2; | ||
} | ||
} | ||
|
||
void DummyHMD::GetProjectionRaw(EVREye eEye, float * pfLeft, float * pfRight, float * pfTop, float * pfBottom) | ||
{ | ||
*pfLeft = -1.0; | ||
*pfRight = 1.0; | ||
*pfTop = -1.0; | ||
*pfBottom = 1.0; | ||
} | ||
|
||
DistortionCoordinates_t DummyHMD::ComputeDistortion(EVREye eEye, float fU, float fV) | ||
{ | ||
vr::DistortionCoordinates_t oDistortion{}; | ||
oDistortion.rfBlue[0] = fU; | ||
oDistortion.rfBlue[1] = fV; | ||
oDistortion.rfGreen[0] = fU; | ||
oDistortion.rfGreen[1] = fV; | ||
oDistortion.rfRed[0] = fU; | ||
oDistortion.rfRed[1] = fV; | ||
return oDistortion; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <openvr_driver.h> | ||
using namespace vr; | ||
|
||
class DummyHMD : public ITrackedDeviceServerDriver, public IVRDisplayComponent | ||
{ | ||
public: | ||
DummyHMD(); | ||
DummyHMD(std::string serial, DriverPose_t initial_pose); | ||
~DummyHMD(); | ||
virtual void updateHMDPose(DriverPose_t new_pose); | ||
virtual uint32_t getObjectID(); | ||
|
||
// Inherited via ITrackedDeviceServerDriver | ||
virtual 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 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(EVREye eEye, uint32_t * pnX, uint32_t * pnY, uint32_t * pnWidth, uint32_t * pnHeight) override; | ||
virtual void GetProjectionRaw(EVREye eEye, float * pfLeft, float * pfRight, float * pfTop, float * pfBottom) override; | ||
virtual DistortionCoordinates_t ComputeDistortion(EVREye eEye, float fU, float fV) override; | ||
|
||
private: | ||
uint32_t object_id_; | ||
std::string serial_; | ||
|
||
int window_width_ = 1920; | ||
int window_height_ = 1080; | ||
int window_x_ = 1920; | ||
int window_y_ = 0; | ||
int separation_ = 75; | ||
|
||
DriverPose_t hmd_pose_; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
# Simple-OpenVR-Driver-Tutorial | ||
A tutorial and sample code for how to write a simple OpenVR (SteamVR) driver. | ||
|
||
I am by no means an expert (I am also learning this as I go) so if you have a comment or suggestion please make an issue or pull request. | ||
I am by no means an expert (I am also learning this as I go) so if you have a comment, suggestion, or change you would like to make please make an issue or pull request. | ||
|
||
## IN PROGRESS | ||
|
||
See Wiki | ||
|
||
### Currently Completed: | ||
- Controllers | ||
- HMD | ||
|
||
### To Do: | ||
- Vive Trackers | ||
- Virtual Display |
Oops, something went wrong.