cgv
Loading...
Searching...
No Matches
vr_events.cxx
1#include "vr_events.h"
2#include <cassert>
3
4namespace cgv {
5 namespace gui {
7 vr_event_extension::vr_event_extension(void* _device_handle, const vr::vr_kit_state& _state)
8 : device_handle(_device_handle), state(_state)
9 {
10
11 }
13 vr_key_event::vr_key_event(void* _device_handle, unsigned _player_index, unsigned _controller_index, const vr::vr_kit_state& _state,
14 unsigned short _key, KeyAction _action, unsigned char _char,
15 unsigned char _modifiers, double _time)
16 : vr_event_extension(_device_handle, _state), controller_index(_controller_index), player_index(_player_index),
17 key_event(_key, _action, _char, _modifiers, 0, _time)
18 {
19 flags = EF_VR;
20 }
22 void vr_key_event::stream_out(std::ostream& os) const
23 {
26 switch (action) {
27 case KA_RELEASE:
28 os << " up ";
29 break;
30 case KA_PRESS:
31 if (get_char())
32 os << " = '" << get_char() << "'";
33 break;
34 case KA_REPEAT:
35 os << " repeat ";
36 break;
37 }
38 if (get_modifiers() != 0) {
40 }
41 os << "<" << (unsigned)player_index << ":" << (unsigned)controller_index << ">";
42 os << "*" << device_handle << "*";
43 }
45 void vr_key_event::stream_in(std::istream& is)
46 {
48 }
49
51 vr_throttle_event::vr_throttle_event(void* _device_handle, unsigned _controller_index, const vr::vr_kit_state& _state,
52 float _x, float _dx, unsigned _player_index, unsigned _throttle_index, double _time)
53 : throttle_event(_x, _dx, _player_index, _controller_index, _throttle_index, _time),
54 vr_event_extension(_device_handle, _state)
55 {
56 flags = EF_VR;
57 }
59 void vr_throttle_event::stream_out(std::ostream& os) const
60 {
62 os << "*" << device_handle << "*";
63 }
65 vr_stick_event::vr_stick_event(void* _device_handle, unsigned _controller_index, const vr::vr_kit_state& _state,
66 StickAction _action, float _x, float _y, float _dx, float _dy,
67 unsigned _player_index, unsigned _stick_index, double _time)
68 : stick_event(_action, _x, _y, _dx, _dy, _player_index,_controller_index,_stick_index,_time),
69 vr_event_extension(_device_handle, _state)
70 {
71 flags = EF_VR;
72 }
74 void vr_stick_event::stream_out(std::ostream& os) const
75 {
77 os << "*" << device_handle << "*";
78 }
80 vr_pose_event::vr_pose_event(void* _device_handle, short _trackable_index, const vr::vr_kit_state& _state,
81 const float *_pose, const float *_last_pose, unsigned short _player_index, double _time)
82 : pose_event(_pose, _last_pose, _player_index, _trackable_index, _time),
83 vr_event_extension(_device_handle, _state)
84 {
85 flags = EF_VR;
86 }
88 void vr_pose_event::stream_out(std::ostream& os) const
89 {
91 os << "*" << device_handle << "*";
92 }
93 }
94}
virtual void stream_out(std::ostream &os) const
write to stream
Definition event.cxx:139
unsigned char flags
store event flags
Definition event.h:64
unsigned char get_modifiers() const
return the active modifiers as values from EventModifier combined with a logical or-operation
Definition event.cxx:237
class to represent all possible keyboard events with the EID_KEY
Definition key_event.h:23
unsigned char get_char() const
return the key as a character
Definition key_event.cxx:61
unsigned char action
store whether
Definition key_event.h:28
void stream_in(std::istream &is)
read from stream
Definition key_event.cxx:45
unsigned short key
store the pressed key
Definition key_event.h:26
class to represent all pose events from tracking systems with the EID_POSE
Definition pose_event.h:16
void stream_out(std::ostream &os) const
write to stream
class to represent stick events with the EID_STICK
Definition stick_event.h:29
void stream_out(std::ostream &os) const
write to stream
class to represent events that inform on a change in a one axis controller with the EID_THROTTLE
void stream_out(std::ostream &os) const
write to stream
interface common to vr events
Definition vr_events.h:24
vr_event_extension(void *_device_handle, const vr::vr_kit_state &_state)
construct extension from device handle and vr state
Definition vr_events.cxx:7
void * device_handle
store device handle
Definition vr_events.h:27
void stream_out(std::ostream &os) const
write to stream
Definition vr_events.cxx:22
unsigned short controller_index
store index of controller (0 .. vr::max_nr_controllers-1), controllers with left and right hand role ...
Definition vr_events.h:43
vr_key_event(void *_device_handle, unsigned _player_index, unsigned _controller_index, const vr::vr_kit_state &_state, unsigned short _key=0, KeyAction _action=KA_PRESS, unsigned char _char=0, unsigned char _modifiers=0, double _time=0)
construct a key event from given parameters
Definition vr_events.cxx:13
void stream_in(std::istream &is)
read from stream
Definition vr_events.cxx:45
unsigned short player_index
store player index
Definition vr_events.h:45
void stream_out(std::ostream &os) const
write to stream
Definition vr_events.cxx:88
vr_pose_event(void *_device_handle, short _trackable_index, const vr::vr_kit_state &_state, const float *_pose, const float *_last_pose, unsigned short _player_index, double _time=0)
construct a pose event from given parameters
Definition vr_events.cxx:80
vr_stick_event(void *_device_handle, unsigned _controller_index, const vr::vr_kit_state &_state, StickAction _action, float _x, float _y, float _dx, float _dy, unsigned _player_index=0, unsigned _stick_index=0, double _time=0)
construct stick event from given parameters
Definition vr_events.cxx:65
void stream_out(std::ostream &os) const
write to stream
Definition vr_events.cxx:74
vr_throttle_event(void *_device_handle, unsigned _controller_index, const vr::vr_kit_state &_state, float _x, float _dx, unsigned _player_index=0, unsigned _throttle_index=0, double _time=0)
construct a throttle event from value and value change
Definition vr_events.cxx:51
void stream_out(std::ostream &os) const
write to stream
Definition vr_events.cxx:59
KeyAction
different actions that a key can perform
Definition key_event.h:12
@ KA_REPEAT
key repeated press action
Definition key_event.h:15
@ KA_PRESS
key press action
Definition key_event.h:14
@ KA_RELEASE
key release action
Definition key_event.h:13
StickAction
different actions that a stick can perform
Definition stick_event.h:15
@ EF_VR
whether event is from VR kit
Definition event.h:35
the cgv namespace
Definition print.h:11
VRButtonStateFlags
one flag for each vr controller button
Definition vr_state.h:62
std::string get_key_string(unsigned short key)
convert key to string
Definition vr_state.cxx:78
std::string get_state_flag_string(VRButtonStateFlags flags)
convert flags to string
Definition vr_state.cxx:110
structure that stores all information describing the state of a VR kit
Definition vr_state.h:139