1#include <cgv/base/base.h>
2#include "vr_render_helpers.h"
3#include <cgv/math/ftransform.h>
4#include <cgv/base/import.h>
8 bool& ref_vrmesh_outofdate(
VRMeshId id)
10 static std::vector<int> outofdates;
11 if ((
int)outofdates.size() <=
id)
12 outofdates.resize(
id + 1,
true);
13 return reinterpret_cast<bool&
>(outofdates[id]);
15 std::string& ref_vrmesh_file_name(
VRMeshId id)
17 static std::vector<std::string> file_names;
18 if ((
int)file_names.size() <=
id)
19 file_names.resize(
id + 1);
20 return file_names[id];
24 return ref_vrmesh_file_name(
id);
28 ref_vrmesh_file_name(
id) = file_name;
29 ref_vrmesh_outofdate(
id) =
true;
33 static std::vector<cgv::render::mesh_render_info*> mesh_infos;
34 if ((
int)mesh_infos.size() <=
id)
35 mesh_infos.resize(
id + 1, 0);
39 delete mesh_infos[id];
47 mesh_infos[id]->construct(ctx, M);
50 ref_vrmesh_outofdate(
id) =
false;
52 return mesh_infos[id];
81 float camera_to_head[12];
84 return cgv::math::identity4<float>();
100 return cgv::math::identity4<float>();
121 camera_center(0) /= frame_width;
122 camera_center(1) /= frame_height;
129 prog.
set_uniform(ctx,
"extent_texcrd", extent_texcrd) &&
130 prog.
set_uniform(ctx,
"frame_split", frame_split) &&
131 prog.
set_uniform(ctx,
"center_left", camera_center) &&
132 prog.
set_uniform(ctx,
"center_right", camera_center) &&
void set_col(unsigned j, const fvec< T, N > &v)
set column j of the matrix to vector v
T * data()
cast into array. This allows calls like glVertex<N><T>v(p.data()) instead of glVertex<N><T,...
base class for all drawables, which is independent of the used rendering API.
virtual shader_program & ref_surface_shader_program(bool texture_support=false)=0
return a reference to the default shader program used to render surfaces
the mesh_render_info structure manages vertex buffer objects for attribute and element buffers as wel...
void destruct(cgv::render::context &ctx)
destruct render mesh info and free vertex buffer objects
a shader program combines several shader code fragments to a complete definition of the shading pipel...
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
interface for mono or stereo cameras in VR headsets
virtual bool put_projection_matrix(int camera_index, bool undistorted, float z_near, float z_far, float *projection_matrix) const =0
access to 4x4 matrix in column major format for perspective transformation of camera (0....
virtual bool put_camera_intrinsics(int camera_index, bool undistorted, float *focal_length_2d_ptr, float *center_2d_ptr) const =0
write the focal lengths in x- and y-direction to access to focal_length_2d_ptr[0|1] and the texture c...
CameraFrameSplit get_frame_split() const
query stereo frame layout
virtual bool put_camera_to_head_matrix(int camera_index, float *pose_matrix) const =0
access to 3x4 matrix in column major format for transformation from camera (0 .. left,...
uint8_t get_nr_cameras() const
return number of cameras in the headset (1 for mono and 2 for stereo)
a vr kit is composed of headset, two controllers, and two trackers, where all devices can be attached...
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_camera * get_camera() const
return camera or nullptr if not available
virtual void put_projection_matrix(int eye, float z_near, float z_far, float *projection_matrix, const float *hmd_pose=0) const =0
access to 4x4 matrix in column major format for perspective transformation from eye (0....
std::string find_data_file(const std::string &file_name, const std::string &strategy, const std::string &sub_directory, const std::string &master_path)
Find a file with the given strategy and return the file name extended by the necessary path.
the vr namespace for virtual reality support
void set_vrmesh_file_name(VRMeshId id, const std::string &file_name)
set the file name for the given vrmesh type
cgv::mat4 get_eye_projection_transform(const vr_kit *vr_kit_ptr, const vr_kit_state &state, float z_near, float z_far, int eye)
query projection matrix for a given eye (0 ... left, 1 ... right)
bool configure_seethrough_shader_program(cgv::render::context &ctx, cgv::render::shader_program &prog, uint32_t frame_width, uint32_t frame_height, const vr_kit *vr_kit_ptr, const vr_kit_state &state, float z_near, float z_far, int eye, bool undistorted)
set all uniforms of seethrough shader program for a given camera (0 ... left or mono,...
VRMeshId
enumerate for different mesh types
cgv::mat4 get_mat4_from_pose(const float pose_matrix[12])
convert pose to mat4
cgv::render::mesh_render_info * get_vrmesh_render_info(cgv::render::context &ctx, VRMeshId id)
return a pointer to a mesh info structure for the given mesh type (read and construct if necessary); ...
cgv::mat4 get_world_to_eye_transform(const vr_kit *vr_kit_ptr, const vr_kit_state &state, int eye)
compute lookat matrix for a given eye (0 ... left, 1 ... right)
cgv::mat4 get_camera_projection_transform(const vr_kit *vr_kit_ptr, float z_near, float z_far, int eye, bool undistorted)
query projection matrix for a given camera (0 ... left or mono, 1 ... right only for stereo cameras)
cgv::mat4 get_texture_transform(const vr_kit *vr_kit_ptr, const vr_kit_state &state, float z_near, float z_far, int eye, bool undistorted)
query the texture matrix needed for projective texture mapping for a given camera (0 ....
cgv::mat4 get_world_to_camera_transform(const vr_kit *vr_kit_ptr, const vr_kit_state &state, int eye)
compute lookat matrix for a given camera (0 ... left, 1 ... right)
const std::string & get_vrmesh_file_name(VRMeshId id)
return the file name for the given vrmesh type
structure that stores all information describing the state of a VR kit
vr_trackable_state hmd
status and pose of hmd
float pose[12]
pose as 3x4 matrix in column major format, where each column is a vector in world coordinates