3#include <cgv/math/fmat.h>
39 vr_kit::vr_kit(
vr_driver* _driver,
void* _handle,
const std::string& _name,
unsigned _width,
unsigned _height,
unsigned _nr_multi_samples) :
40 gl_vr_display(_width, _height, _nr_multi_samples), driver(_driver), handle(_handle), name(_name), camera(nullptr), skip_calibration(false) {}
56 float dot(
int n,
const float* a,
const float* b,
int step_a = 1,
int step_b=1)
59 for (
int i = 0; i < n; ++i)
60 res += a[i*step_a] * b[i*step_b];
63 void homogenize_matrix(
float* A,
int n,
const float* B = 0)
67 for (
int j = n; j >= 0; --j) {
68 A[j*(n + 1) + n] = (j == n ? 1.0f : 0.0f);
69 for (
int i = n - 1; i >= 0; --i)
70 A[j*(n + 1) + i] = B[j*n + i];
73 void invert_rigid_body_transformation(
float* T)
77 for (i = 0; i < 3; ++i)
78 t[i] = -dot(3, T + 4 * i, T + 12);
79 for (i = 0; i < 3; ++i) {
81 for (
int j = i + 1; j < 3; ++j)
82 std::swap(T[4 * j + i], T[4 * i + j]);
85 void matrix_multiplication(
const float* A,
const float* B,
float* C)
87 for (
int i = 0; i < 4; ++i)
88 for (
int j = 0; j < 4; ++j)
89 C[4 * j + i] = dot(4, A + i, B + 4 * j, 4);
94 float eye_to_head[16];
96 homogenize_matrix(eye_to_head, 3);
97 invert_rigid_body_transformation(eye_to_head);
98 float head_to_world[16];
99 homogenize_matrix(head_to_world, 3, hmd_pose);
100 invert_rigid_body_transformation(head_to_world);
101 matrix_multiplication(eye_to_head, head_to_world, modelview_matrix);
implements offscreen rendering
interface for mono or stereo cameras in VR headsets
bool stop()
stop streaming of frames
interface class for vr drivers.
void clear_tracking_reference_states()
remove all tracking reference states
void mark_tracking_references_as_untracked()
mark all tracking reference states as untracked
void calibrate_pose(float(&pose)[12]) const
in case calibration matrix is enabled, transform given pose in place
vr_tracking_system_info tracking_system_info
store tracking system info to be filled by driver implementations
bool is_calibration_transformation_enabled() const
check whether calibration transformation is enabled; false after construction and typically set to tr...
vr_trackable_state & ref_tracking_reference_state(const std::string &serial_nummer)
provide reference to tracking reference states
virtual void put_world_to_eye_transform(int eye, const float *hmd_pose, float *modelview_matrix) const
access to 4x4 modelview transformation matrix of given eye in column major format,...
vr_kit(vr_driver *_driver, void *_handle, const std::string &_name, unsigned _width, unsigned _height, unsigned _nr_multi_samples=4)
construct
vr_trackable_state & ref_tracking_reference_state(const std::string &serial_nummer)
write access to the state of the tracking reference with given serial number
vr_camera * get_camera() const
return camera or nullptr if not available
vr_kit_info info
store vr kit info to be filled and updated by driver implementations
controller_input_config input_configs[4][5]
store controller input configs per controller and input
void destruct_camera()
destruct camera
const controller_input_config & get_controller_input_config(int controller_index, int input_index) const
query the configuration of a controller input
bool query_state(vr_kit_state &state, int pose_query=2)
query current state of vr kit and return whether this was successful
const vr_kit_info & get_device_info() const
return information on the currently attached devices
void * get_handle() const
return handle of vr kit
const vr_driver * get_driver() const
return driver
const std::string & get_name() const
return name of vr_kit
virtual void set_controller_input_config(int controller_index, int input_index, const controller_input_config &cic)
set the configuration of a controller input
void * handle
handle for internal use
bool skip_calibration
whether to skip driver calibration - defaults to false
vr_driver * driver
pointer to driver that created the vr kit
void clear_tracking_reference_states()
remove all reference states
virtual bool query_state_impl(vr_kit_state &state, int pose_query)=0
derived kits implement this without caring about calibration; vr_kit::query_state() will apply driver...
virtual ~vr_kit()
declare virtual destructor
virtual void put_eye_to_head_matrix(int eye, float *pose_matrix) const =0
access to 3x4 matrix in column major format for transformation from eye (0..left, 1....
vr_camera * camera
pointer to camera
void mark_tracking_references_as_untracked()
mark all reference states as untracked
std::string name
name in case driver provides this information (not reliable)
vr_tracking_system_info & ref_tracking_system_info()
write access to tracking system info
the vr namespace for virtual reality support
@ VRS_TRACKED
trackable is connected and tracked
const unsigned max_nr_controllers
maximum number of attachable controller and tracker devices
information provided for a vr kit
structure that stores all information describing the state of a VR kit
vr_controller_state controller[max_nr_controllers]
status, pose, button, axes, and vibration information of up to vr::max_nr_controllers controller and ...
vr_trackable_state hmd
status and pose of hmd
a trackable knows whether it is tracked and its 6d pose stored as 3x4 matrix in column major format
VRStatus status
whether trackable is currently tracked, only in case of true, the pose member contains useful informa...
float pose[12]
pose as 3x4 matrix in column major format, where each column is a vector in world coordinates
information provided for tracking system
defines the class vr::vr_driver class and gives access to the driver registry with the functions vr::...