cgv
Loading...
Searching...
No Matches
vr_state.cxx
1#include "vr_state.h"
2
3namespace vr {
6 {
8 pose[0] = pose[4] = pose[8] = 1;
9 pose[1] = pose[2] = pose[3] = pose[5] = pose[6] = pose[7] = 0;
10 pose[9] = pose[10] = pose[11] = 0;
11 }
14 {
15 time_stamp = 0;
16 button_flags = 0;
17 for (unsigned i = 0; i < max_nr_controller_axes; ++i)
18 axes[i] = 0;
19 vibration[0] = vibration[1] = 0;
20 }
21 void vr_controller_state::put_ray(float* ray_origin, float* ray_direction) const
22 {
23 ray_origin[0] = pose[9];
24 ray_origin[1] = pose[10];
25 ray_origin[2] = pose[11];
26 ray_direction[0] = -pose[6];
27 ray_direction[1] = -pose[7];
28 ray_direction[2] = -pose[8];
29 }
30
31
38 {
39 return hmd == state.hmd &&
40 controller[0] == state.controller[0] &&
41 controller[1] == state.controller[1];
42 }
45 {
46 return status == state.status &&
47 pose[0] == state.pose[0] &&
48 pose[1] == state.pose[1] &&
49 pose[2] == state.pose[2] &&
50 pose[3] == state.pose[3] &&
51 pose[4] == state.pose[4] &&
52 pose[5] == state.pose[5] &&
53 pose[6] == state.pose[6] &&
54 pose[7] == state.pose[7] &&
55 pose[8] == state.pose[8] &&
56 pose[9] == state.pose[9] &&
57 pose[10] == state.pose[10] &&
58 pose[11] == state.pose[11];
59 }
62 {
63 return
65 button_flags == state.button_flags &&
66 axes[0] == state.axes[0] &&
67 axes[1] == state.axes[1] &&
68 axes[2] == state.axes[2] &&
69 axes[3] == state.axes[3] &&
70 axes[4] == state.axes[4] &&
71 axes[5] == state.axes[5] &&
72 axes[6] == state.axes[6] &&
73 axes[7] == state.axes[7] &&
74 vibration[0] == state.vibration[0] &&
75 vibration[1] == state.vibration[1];
76 }
78 std::string get_key_string(unsigned short key)
79 {
80 static const char* vr_key_names[] = {
81 "VR_UNKNOWN",
82 "VR_SYSTEM",
83 "VR_MENU",
84 "VR_GRIP",
85 "VR_DPAD_DOWN_LEFT",
86 "VR_DPAD_DOWN",
87 "VR_DPAD_DOWN_RIGHT",
88 "VR_DPAD_LEFT",
89 "VR_DPAD_RIGHT",
90 "VR_DPAD_UP_LEFT",
91 "VR_DPAD_UP",
92 "VR_DPAD_UP_RIGHT",
93 "VR_A",
94 "VR_INPUT0_TOUCH",
95 "VR_INPUT0",
96 "VR_INPUT1_TOUCH",
97 "VR_INPUT1",
98 "VR_INPUT2_TOUCH",
99 "VR_INPUT2",
100 "VR_INPUT3_TOUCH",
101 "VR_INPUT3",
102 "VR_INPUT4_TOUCH",
103 "VR_INPUT4",
104 "VR_PROXIMITY"
105 };
106 int index = key - (int)VR_UNKNOWN;
107 return index < 24 ? vr_key_names[index] : "VR_UNKNOWN";
108 }
111 {
112 static const char* flag_names[] = {
113 "SYSTEM",
114 "MENU",
115 "GRIP",
116 "DPAD_LEFT",
117 "DPAD_RIGHT",
118 "DPAD_DOWN",
119 "DPAD_UP",
120 "A",
121 "INPUT0_TOUCH",
122 "INPUT0",
123 "INPUT1_TOUCH",
124 "INPUT1",
125 "INPUT2_TOUCH",
126 "INPUT2",
127 "INPUT3_TOUCH",
128 "INPUT3",
129 "INPUT4_TOUCH",
130 "INPUT4",
131 "PROXIMITY"
132 };
133 static const VRButtonStateFlags flag_values[] = {
134 VRF_SYSTEM ,
135 VRF_MENU ,
136 VRF_GRIP ,
141 VRF_A ,
143 VRF_INPUT0 ,
145 VRF_INPUT1 ,
147 VRF_INPUT2 ,
149 VRF_INPUT3 ,
151 VRF_INPUT4 ,
153 };
154 std::string result;
155 for (unsigned i = 0; i < 19; ++i)
156 if ((flags & flag_values[i]) != 0) {
157 if (result.empty())
158 result = flag_names[i];
159 else
160 result += std::string("+") + flag_names[i];
161 }
162 return result;
163
164 }
166 std::string get_status_string(VRStatus status)
167 {
168 switch (status) {
169 case VRS_DETACHED: return "detached";
170 case VRS_ATTACHED: return "attached";
171 case VRS_TRACKED: return "tracked";
172 default: return "unknown status";
173 }
174 }
175}
the vr namespace for virtual reality support
VRButtonStateFlags
one flag for each vr controller button
Definition vr_state.h:62
@ VRF_INPUT0
button of input 0
Definition vr_state.h:72
@ VRF_MENU
application menu button
Definition vr_state.h:64
@ VRF_DPAD_LEFT
direction pad left button
Definition vr_state.h:66
@ VRF_A
A button.
Definition vr_state.h:70
@ VRF_INPUT1_TOUCH
touch sensor for input 1 which often is touchpad or stick
Definition vr_state.h:73
@ VRF_DPAD_RIGHT
direction pad right button
Definition vr_state.h:67
@ VRF_GRIP
grip button
Definition vr_state.h:65
@ VRF_INPUT3_TOUCH
touch sensor for input 3 which often is touchpad or stick
Definition vr_state.h:77
@ VRF_DPAD_UP
direction pad up button
Definition vr_state.h:69
@ VRF_INPUT1
button of input 1
Definition vr_state.h:74
@ VRF_SYSTEM
system button
Definition vr_state.h:63
@ VRF_PROXIMITY
proximity sensor
Definition vr_state.h:81
@ VRF_INPUT4_TOUCH
touch sensor for input 4 which often is touchpad or stick
Definition vr_state.h:79
@ VRF_INPUT0_TOUCH
touch sensor for input 0 which often is touchpad or stick
Definition vr_state.h:71
@ VRF_INPUT2
button of input 2
Definition vr_state.h:76
@ VRF_INPUT2_TOUCH
touch sensor for input 2 which often is touchpad or stick
Definition vr_state.h:75
@ VRF_INPUT4
button of input 4
Definition vr_state.h:80
@ VRF_DPAD_DOWN
direction pad down button
Definition vr_state.h:68
@ VRF_INPUT3
button of input 3
Definition vr_state.h:78
std::string get_key_string(unsigned short key)
convert key to string
Definition vr_state.cxx:78
std::string get_status_string(VRStatus status)
convert flags to string
Definition vr_state.cxx:166
const unsigned max_nr_controller_axes
maximum number of axes per controller
Definition vr_state.h:23
VRStatus
different status values for a trackable
Definition vr_state.h:85
@ VRS_TRACKED
trackable is connected and tracked
Definition vr_state.h:88
@ VRS_ATTACHED
trackable is connected via wireless but not tracked
Definition vr_state.h:87
@ VRS_DETACHED
trackable is not reachable via wireless
Definition vr_state.h:86
std::string get_state_flag_string(VRButtonStateFlags flags)
convert flags to string
Definition vr_state.cxx:110
Extends the trackable state by information on the buttons, input axes and vibration strengths.
Definition vr_state.h:118
vr_controller_state()
standard constructor for initialization of members
Definition vr_state.cxx:13
void put_ray(float *ray_origin, float *ray_direction) const
place the 3d ray origin and the 3d ray direction into the given arrays which must provide space for 3...
Definition vr_state.cxx:21
float axes[max_nr_controller_axes]
up to vr::max_nr_controller_axes axis values in the range [-1,1] or [0,1] (VIVE: 0|1....
Definition vr_state.h:124
unsigned time_stamp
a unique time stamp for fast test whether state changed
Definition vr_state.h:120
float vibration[2]
strength of the vibration motors
Definition vr_state.h:126
bool operator==(const vr_controller_state &state) const
equal comparison operator
Definition vr_state.cxx:61
unsigned button_flags
combination of flags in VRButtonStateFlags combined with the OR operation
Definition vr_state.h:122
structure that stores all information describing the state of a VR kit
Definition vr_state.h:139
vr_controller_state controller[max_nr_controllers]
status, pose, button, axes, and vibration information of up to vr::max_nr_controllers controller and ...
Definition vr_state.h:143
bool operator==(const vr_kit_state &state) const
check for equality
Definition vr_state.cxx:37
vr_trackable_state hmd
status and pose of hmd
Definition vr_state.h:141
vr_kit_state()
standard constructor for initialization of members
Definition vr_state.cxx:32
a trackable knows whether it is tracked and its 6d pose stored as 3x4 matrix in column major format
Definition vr_state.h:94
VRStatus status
whether trackable is currently tracked, only in case of true, the pose member contains useful informa...
Definition vr_state.h:96
float pose[12]
pose as 3x4 matrix in column major format, where each column is a vector in world coordinates
Definition vr_state.h:104
bool operator==(const vr_trackable_state &state) const
equality check
Definition vr_state.cxx:44
vr_trackable_state()
standard constructor for initialization of members
Definition vr_state.cxx:5
defines types to store the state vr::vr_kit_state of a vr kit, which is split into sub states for the...