cgv
|
server for vr events More...
#include <vr_server.h>
Public Member Functions | |
vr_server () | |
construct server with default configuration | |
VREventTypeFlags | get_event_type_flags () const |
query the currently set event type flags | |
void | set_event_type_flags (VREventTypeFlags flags) |
set the event type flags of to be emitted events | |
void | set_device_scan_interval (double duration) |
set time interval in seconds to check for device connection changes | |
double | get_device_scan_interval () const |
return the time interval in seconds to check for device connection changes | |
void | check_device_changes (double time) |
check which vr_kits are present and emit on_device_change events | |
void | check_and_emit_events (double time) |
check which vr_kits are present, query their current states and dispatch events through on_event, on_status_change and on_device_change signals | |
bool | check_new_state (void *kit_handle, const vr::vr_kit_state &new_state, double time) |
in case the current vr state of a kit had been queried somewhere else, use this function to communicate the new state to the server; return whether kit_handle had been seen by server before | |
bool | check_new_state (void *kit_handle, const vr::vr_kit_state &new_state, double time, VREventTypeFlags flags) |
same as previous function but with overwrite of flags | |
bool | grab_focus (VRFocus focus, event_handler *handler) |
grab the event focus to the given event handler and return whether this was possible | |
bool | release_focus (event_handler *handler) |
release focus of handler and return whether handler had the focus | |
bool | dispatch (cgv::gui::event &e) |
dispatch an event to focus handler and or signal attachments | |
void | enable_log (const std::string fn="", const bool in_memory_log=true, const int filter=vr::vr_log::F_ALL, const int kit_index=0) |
void | disable_log (const int kit_index=0) |
disable logging and close log file | |
vr::vr_log & | ref_log (const int kit_index=0) |
return a reference to the used vr_log object | |
cgv::data::ref_ptr< vr::vr_log > | get_log (const int kit_index=0) |
returns a pointer to the active log data container, meant for extending the lifetime of the log data beyond a new enable_log call | |
Public Attributes | |
cgv::signal::bool_signal< cgv::gui::event & > | on_event |
signal emitted to dispatch events | |
cgv::signal::signal< void *, bool > | on_device_change |
signal emitted to notify about device changes, first argument is handle and second a flag telling whether device got connected or if false disconnected | |
cgv::signal::signal< void *, int, vr::VRStatus, vr::VRStatus > | on_status_change |
signal emitted to notify about status changes of trackables, first argument is handle, second -1 for hmd + 0|1 for left|right controller, third is old status and fourth new status | |
Protected Member Functions | |
void | emit_events_and_update_state (void *kit_handle, const vr::vr_kit_state &new_state, int kit_index, VREventTypeFlags flags, double time) |
float | correct_deadzone_and_precision (float value, const vr::controller_input_config &IC) |
vec2 | correct_deadzone_and_precision (const vec2 &position, const vr::controller_input_config &IC) |
Protected Attributes | |
double | last_device_scan |
double | device_scan_interval |
std::vector< void * > | vr_kit_handles |
std::vector< vr::vr_kit_state > | last_states |
std::vector< unsigned > | last_time_stamps |
VREventTypeFlags | event_type_flags |
VRFocus | focus_type |
event_handler * | focus |
std::unordered_map< int, cgv::data::ref_ptr< vr::vr_log > > | log_data |
server for vr events
It keeps the previous state of each vr kit and compares it with current state. In case of state changes, the server can emit device change, status change, key, throttle, stick and pose events. For key, throttle, stick and pose events, the classes cgv::gui::vr_key_event, cgv::gui::vr_throttle_event, cgv::gui::vr_stick_event, and cgv::gui::vr_pose_event are used and the event flag cgv::gui::EF_VR is set to mark it as vr event. To process for example a stick event in the cgv::gui::event_handler::handle() function, the following shows a code sample:
Which events are emitted by the server can be configured with the set_event_type_flags() function. Device change events are emitted with the vr_server::on_device_change signal, status change events with the vr_server::on_status_change signal and all others via the vr_server::on_event signal.
There is a singleton vr_server instance provided with cgv::gui::ref_vr_server(). The current vr_kit states are polled with the check_and_emit_events() or in case some other class has queried the states with the check_new_state() functions for each vr_kit separately. In an interval of get_device_scan_interval() seconds the vr_kits are scanned again to detect device changes.
The vr_server can be used in three ways. In all cases you have to connect directly to the vr_server::on_device_change or vr_server::on_status_change signals in order to receive device change or status change events.
Definition at line 135 of file vr_server.h.
cgv::gui::vr_server::vr_server | ( | ) |
construct server with default configuration
Definition at line 21 of file vr_server.cxx.
References cgv::gui::VRE_ALL.
void cgv::gui::vr_server::check_and_emit_events | ( | double | time | ) |
check which vr_kits are present, query their current states and dispatch events through on_event, on_status_change and on_device_change signals
check enabled gamepad devices for new events and dispatch them through the on_event signal
Definition at line 320 of file vr_server.cxx.
References check_device_changes(), emit_events_and_update_state(), vr::get_vr_kit(), and vr::vr_kit::query_state().
Referenced by cgv::gui::connect_vr_server().
void cgv::gui::vr_server::check_device_changes | ( | double | time | ) |
check which vr_kits are present and emit on_device_change events
Definition at line 282 of file vr_server.cxx.
References get_event_type_flags(), on_device_change, vr::scan_vr_kits(), and cgv::gui::VRE_DEVICE.
Referenced by check_and_emit_events(), and cgv::gui::connect_vr_server().
bool cgv::gui::vr_server::check_new_state | ( | void * | kit_handle, |
const vr::vr_kit_state & | new_state, | ||
double | time | ||
) |
in case the current vr state of a kit had been queried somewhere else, use this function to communicate the new state to the server; return whether kit_handle had been seen by server before
in case the current vr state of a kit had been queried outside, use this function to communicate the new state to the server
Definition at line 337 of file vr_server.cxx.
References check_new_state().
Referenced by check_new_state().
bool cgv::gui::vr_server::check_new_state | ( | void * | kit_handle, |
const vr::vr_kit_state & | new_state, | ||
double | time, | ||
VREventTypeFlags | flags | ||
) |
same as previous function but with overwrite of flags
Definition at line 342 of file vr_server.cxx.
References emit_events_and_update_state().
|
protected |
Definition at line 89 of file vr_server.cxx.
|
protected |
Definition at line 77 of file vr_server.cxx.
void cgv::gui::vr_server::disable_log | ( | const int | kit_index = 0 | ) |
disable logging and close log file
Definition at line 381 of file vr_server.cxx.
bool cgv::gui::vr_server::dispatch | ( | cgv::gui::event & | e | ) |
dispatch an event to focus handler and or signal attachments
Definition at line 351 of file vr_server.cxx.
References cgv::gui::event_handler::handle(), and on_event.
Referenced by emit_events_and_update_state().
|
protected |
construct a throttle event from value and value change
Definition at line 100 of file vr_server.cxx.
References vr::vr_controller_state::axes, vr::vr_kit_info::controller, vr::vr_kit_state::controller, dispatch(), vr::vr_kit::get_controller_input_config(), vr::vr_kit::get_device_info(), vr::get_vr_kit(), vr::vr_kit_state::hmd, vr::vr_controller_info::input_type, cgv::gui::KA_PRESS, cgv::gui::KA_RELEASE, vr::max_nr_controller_inputs, vr::max_nr_controllers, on_status_change, vr::vr_trackable_state::pose, cgv::gui::SA_DRAG, cgv::gui::SA_MOVE, cgv::gui::SA_PRESS, cgv::gui::SA_RELEASE, cgv::gui::SA_TOUCH, cgv::gui::SA_UNPRESS, vr::vr_trackable_state::status, vr::controller_input_config::threshold, vr::VR_A, vr::VR_DPAD_DOWN, vr::VR_DPAD_LEFT, vr::VR_DPAD_RIGHT, vr::VR_DPAD_UP, vr::VR_GRIP, vr::VR_INPUT0, vr::VR_INPUT0_TOUCH, vr::VR_INPUT1, vr::VR_INPUT1_TOUCH, vr::VR_INPUT2, vr::VR_INPUT2_TOUCH, vr::VR_INPUT3, vr::VR_INPUT3_TOUCH, vr::VR_INPUT4, vr::VR_INPUT4_TOUCH, vr::VR_MENU, vr::VR_PROXIMITY, vr::VR_SYSTEM, cgv::gui::VRE_KEY, cgv::gui::VRE_ONE_AXIS, cgv::gui::VRE_ONE_AXIS_GENERATES_KEY, cgv::gui::VRE_POSE, cgv::gui::VRE_STATUS, cgv::gui::VRE_TWO_AXES, cgv::gui::VRE_TWO_AXES_GENERATES_DPAD, vr::VRF_A, vr::VRF_DPAD_DOWN, vr::VRF_DPAD_LEFT, vr::VRF_DPAD_RIGHT, vr::VRF_DPAD_UP, vr::VRF_GRIP, vr::VRF_INPUT0, vr::VRF_INPUT0_TOUCH, vr::VRF_INPUT1, vr::VRF_INPUT1_TOUCH, vr::VRF_INPUT2, vr::VRF_INPUT2_TOUCH, vr::VRF_INPUT3, vr::VRF_INPUT3_TOUCH, vr::VRF_INPUT4, vr::VRF_INPUT4_TOUCH, vr::VRF_MENU, vr::VRF_PROXIMITY, vr::VRF_SYSTEM, vr::VRS_DETACHED, and vr::VRS_TRACKED.
Referenced by check_and_emit_events(), and check_new_state().
void cgv::gui::vr_server::enable_log | ( | const std::string | fn = "" , |
const bool | in_memory_log = true , |
||
const int | filter = vr::vr_log::F_ALL , |
||
const int | kit_index = 0 |
||
) |
creates a logfile and activates logging of vr .
fn | path to logfile. pass an empty string to disable writing to a log file |
Definition at line 361 of file vr_server.cxx.
References vr::vr_log::enable_in_memory_log(), vr::vr_log::enable_ostream_log(), vr::vr_log::lock_settings(), and vr::vr_log::set_filter().
|
inline |
return the time interval in seconds to check for device connection changes
Definition at line 163 of file vr_server.h.
VREventTypeFlags cgv::gui::vr_server::get_event_type_flags | ( | ) | const |
query the currently set event type flags
Definition at line 67 of file vr_server.cxx.
Referenced by check_device_changes().
cgv::data::ref_ptr< vr::vr_log > cgv::gui::vr_server::get_log | ( | const int | kit_index = 0 | ) |
returns a pointer to the active log data container, meant for extending the lifetime of the log data beyond a new enable_log call
Definition at line 392 of file vr_server.cxx.
bool cgv::gui::vr_server::grab_focus | ( | VRFocus | focus, |
event_handler * | handler | ||
) |
grab the event focus to the given event handler and return whether this was possible
Definition at line 39 of file vr_server.cxx.
References cgv::gui::EF_VR, cgv::gui::trigger::get_current_time(), cgv::gui::event_handler::handle(), cgv::gui::event::set_flags(), and cgv::gui::choice_event::set_type().
vr::vr_log & cgv::gui::vr_server::ref_log | ( | const int | kit_index = 0 | ) |
return a reference to the used vr_log object
Definition at line 388 of file vr_server.cxx.
bool cgv::gui::vr_server::release_focus | ( | event_handler * | handler | ) |
release focus of handler and return whether handler had the focus
Definition at line 58 of file vr_server.cxx.
void cgv::gui::vr_server::set_device_scan_interval | ( | double | duration | ) |
set time interval in seconds to check for device connection changes
Definition at line 29 of file vr_server.cxx.
void cgv::gui::vr_server::set_event_type_flags | ( | VREventTypeFlags | flags | ) |
set the event type flags of to be emitted events
Definition at line 72 of file vr_server.cxx.
|
protected |
Definition at line 139 of file vr_server.h.
|
protected |
Definition at line 143 of file vr_server.h.
|
protected |
Definition at line 145 of file vr_server.h.
|
protected |
Definition at line 144 of file vr_server.h.
|
protected |
Definition at line 138 of file vr_server.h.
|
protected |
Definition at line 141 of file vr_server.h.
|
protected |
Definition at line 142 of file vr_server.h.
|
protected |
Definition at line 146 of file vr_server.h.
cgv::signal::signal<void*, bool> cgv::gui::vr_server::on_device_change |
signal emitted to notify about device changes, first argument is handle and second a flag telling whether device got connected or if false disconnected
Definition at line 181 of file vr_server.h.
Referenced by check_device_changes().
cgv::signal::bool_signal<cgv::gui::event&> cgv::gui::vr_server::on_event |
signal emitted to dispatch events
Definition at line 179 of file vr_server.h.
Referenced by dispatch().
cgv::signal::signal<void*, int, vr::VRStatus, vr::VRStatus> cgv::gui::vr_server::on_status_change |
signal emitted to notify about status changes of trackables, first argument is handle, second -1 for hmd + 0|1 for left|right controller, third is old status and fourth new status
Definition at line 183 of file vr_server.h.
Referenced by emit_events_and_update_state().
|
protected |
Definition at line 140 of file vr_server.h.