1
1
#include " ControllerDevice.hpp"
2
+ #include < string>
2
3
#include < Windows.h>
3
4
4
- TutorialDriver::ControllerDevice::ControllerDevice (std::string serial):m_serial(serial)
5
+ TutorialDriver::ControllerDevice::ControllerDevice (std::string serial, bool isLeftController ):m_serial(serial),m_isLeft(isLeftController )
5
6
{
6
7
}
7
8
@@ -20,43 +21,14 @@ void TutorialDriver::ControllerDevice::update(std::vector<vr::VREvent_t> events)
20
21
double deltaTimeSeconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastFrameTime).count ()/1000.0 ;
21
22
this ->m_lastFrameTime = now;
22
23
23
- // Setup pose for this frame
24
- auto pose = this ->GetPose ();
25
24
26
- // Get orientation
27
- this ->m_yRot += (1.0 * (GetAsyncKeyState (0x66 ) == 0 ) - 1.0 * (GetAsyncKeyState (0x64 ) == 0 )) * deltaTimeSeconds;
28
- this ->m_xRot += (-1.0 * (GetAsyncKeyState (0x68 ) == 0 ) + 1.0 * (GetAsyncKeyState (0x62 ) == 0 )) * deltaTimeSeconds;
29
- this ->m_xRot = std::fmax (this ->m_xRot , -3.14159 /2 );
30
- this ->m_xRot = std::fmin (this ->m_xRot , 3.14159 /2 );
31
-
32
- linalg::vec<float , 4 > yQuat{ 0 , std::sinf ((float )this ->m_yRot / 2 ), 0 , std::cosf ((float )this ->m_yRot / 2 ) };
33
-
34
- linalg::vec<float , 4 > xQuat{ std::sinf ((float )this ->m_xRot / 2 ), 0 , 0 , std::cosf ((float )this ->m_xRot / 2 ) };
35
-
36
- linalg::vec<float , 4 > pose_rot = linalg::qmul (yQuat, xQuat);
37
-
38
- pose.qRotation .w = pose_rot.w ;
39
- pose.qRotation .x = pose_rot.x ;
40
- pose.qRotation .y = pose_rot.y ;
41
- pose.qRotation .z = pose_rot.z ;
42
-
43
- // Update position based on rotation
44
- linalg::vec<float , 3 > forward_vec{-1 .0f * (GetAsyncKeyState (0x65 ) == 0 ) + 1 .0f * (GetAsyncKeyState (0x60 ) == 0 ), 0 , 0 };
45
- linalg::vec<float , 3 > right_vec{0 , 0 , 0 };
46
- linalg::vec<float , 3 > final_dir = forward_vec + right_vec;
47
- if (linalg::length (final_dir) > 0.01 ) {
48
- final_dir = linalg::normalize (final_dir) * (float )deltaTimeSeconds;
49
- final_dir = linalg::qrot (pose_rot, final_dir);
50
- this ->m_x += final_dir.x ;
51
- this ->m_y += final_dir.y ;
52
- this ->m_z += final_dir.z ;
53
- }
54
25
55
- pose.vecPosition [0 ] = this ->m_x ;
56
- pose.vecPosition [1 ] = this ->m_y ;
57
- pose.vecPosition [2 ] = this ->m_z ;
26
+
27
+
58
28
59
29
// Post pose
30
+ auto pose = this ->GetPose ();
31
+ pose.vecPosition [0 ] = this ->m_isLeft ? 1 : -1 ;
60
32
vr::VRServerDriverHost ()->TrackedDevicePoseUpdated (this ->device_index (), pose, sizeof (vr::DriverPose_t));
61
33
}
62
34
@@ -74,27 +46,62 @@ vr::EVRInitError TutorialDriver::ControllerDevice::Activate(uint32_t unObjectId)
74
46
75
47
// Set some universe ID (Must be 2 or higher)
76
48
vr::VRProperties ()->SetUint64Property (props, vr::Prop_CurrentUniverseId_Uint64, 2 );
77
-
78
- // Set the IPD to be whatever steam has configured
79
- vr::VRProperties ()->SetFloatProperty (props, vr::Prop_UserIpdMeters_Float, vr::VRSettings ()->GetFloat (vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_IPD_Float));
80
-
81
- // Set the display FPS
82
- vr::VRProperties ()->SetFloatProperty (props, vr::Prop_DisplayFrequency_Float, 90 .f );
83
49
84
50
// Set up a model "number" (not needed but good to have)
85
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_ModelNumber_String, " Tutorial HMD Device" );
51
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_ModelNumber_String, " Tutorial Controller Device" );
52
+
53
+ // Set render model which is visible in SteamVR and some SteamVR apps
54
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_RenderModelName_String, " locator" );
55
+
56
+ if (this ->m_isLeft ) {
57
+ vr::VRProperties ()->SetInt32Property (props, vr::Prop_ControllerRoleHint_Int32, vr::ETrackedControllerRole::TrackedControllerRole_LeftHand);
58
+ } else {
59
+ vr::VRProperties ()->SetInt32Property (props, vr::Prop_ControllerRoleHint_Int32, vr::ETrackedControllerRole::TrackedControllerRole_RightHand);
60
+ }
86
61
87
62
// Set up icon paths
88
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceReady_String, " {tutorial_hmd}/icons/hmd_ready.png" );
89
-
90
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceOff_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
91
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceSearching_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
92
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceSearchingAlert_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
93
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceReadyAlert_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
94
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceNotReady_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
95
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceStandby_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
96
- vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceAlertLow_String, " {tutorial_hmd}/icons/hmd_not_ready.png" );
63
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceReady_String, " {tutorial_devices}/icons/controller_ready.png" );
64
+
65
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceOff_String, " {tutorial_devices}/icons/controller_not_ready.png" );
66
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceSearching_String, " {tutorial_devices}/icons/controller_not_ready.png" );
67
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceSearchingAlert_String, " {tutorial_devices}/icons/controller_not_ready.png" );
68
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceReadyAlert_String, " {tutorial_devices}/icons/controller_not_ready.png" );
69
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceNotReady_String, " {tutorial_devices}/icons/controller_not_ready.png" );
70
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceStandby_String, " {tutorial_devices}/icons/controller_not_ready.png" );
71
+ vr::VRProperties ()->SetStringProperty (props, vr::Prop_NamedIconPathDeviceAlertLow_String, " {tutorial_devices}/icons/controller_not_ready.png" );
72
+
73
+ // Create input/output paths
74
+ vr::VRDriverInput ()->CreateHapticComponent (props, " /output/haptic" , &this ->m_compHaptic );
75
+
76
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/a/touch" , &this ->m_compATouch );
77
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/a/click" , &this ->m_compAClick );
97
78
79
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/b/touch" , &this ->m_compBTouch );
80
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/b/click" , &this ->m_compBClick );
81
+
82
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/system/touch" , &this ->m_compSysTouch );
83
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/system/click" , &this ->m_compSysClick );
84
+
85
+ vr::VRDriverInput ()->CreateScalarComponent (props, " /input/trigger/value" , &this ->m_compTriggerValue , vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedOneSided);
86
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/trigger/touch" , &this ->m_compTriggerTouch );
87
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/trigger/click" , &this ->m_compTriggerClick );
88
+
89
+ vr::VRDriverInput ()->CreateScalarComponent (props, " /input/grip/value" , &this ->m_compGripValue , vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedOneSided);
90
+ vr::VRDriverInput ()->CreateScalarComponent (props, " /input/grip/force" , &this ->m_compGripForce , vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedOneSided);
91
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/grip/touch" , &this ->m_compGripTouch );
92
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/grip/click" , &this ->m_compGripClick );
93
+
94
+ vr::VRDriverInput ()->CreateScalarComponent (props, " /input/trackpad/x" , &this ->m_compTrackpadX , vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedTwoSided);
95
+ vr::VRDriverInput ()->CreateScalarComponent (props, " /input/trackpad/y" , &this ->m_compTrackpadY , vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedTwoSided);
96
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/trackpad/touch" , &this ->m_compTrackpadTouch );
97
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/trackpad/click" , &this ->m_compTrackpadClick );
98
+
99
+ vr::VRDriverInput ()->CreateScalarComponent (props, " /input/joystick/x" , &this ->m_compJoystickX , vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedTwoSided);
100
+ vr::VRDriverInput ()->CreateScalarComponent (props, " /input/joystick/y" , &this ->m_compJoystickY , vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedTwoSided);
101
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/joystick/touch" , &this ->m_compJoystickTouch );
102
+ vr::VRDriverInput ()->CreateBooleanComponent (props, " /input/joystick/click" , &this ->m_compJoystickClick );
103
+
104
+
98
105
this ->m_lastFrameTime = std::chrono::system_clock::now ();
99
106
100
107
return vr::EVRInitError::VRInitError_None;
0 commit comments