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 More... | |
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 More... | |
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) |
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.
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
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
|
protected |
construct a throttle event from value and value change
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 |