Use matrices for eye offsets instead of a simple spacing
[libs/vr.git] / source / stereoview.h
1 #ifndef MSP_VR_STEREOVIEW_H_
2 #define MSP_VR_STEREOVIEW_H_
3
4 #include <msp/geometry/angle.h>
5 #include <msp/gl/camera.h>
6 #include <msp/gl/framebuffer.h>
7 #include <msp/gl/renderable.h>
8 #include <msp/gl/renderbuffer.h>
9 #include <msp/gl/texture2d.h>
10
11 namespace Msp {
12 namespace VR {
13
14 class HeadTrackingCamera;
15 class StereoCombiner;
16
17 class StereoView
18 {
19 private:
20         struct RenderTarget
21         {
22                 GL::Framebuffer fbo;
23                 GL::Texture2D color;
24                 GL::Renderbuffer depth;
25
26                 RenderTarget(unsigned, unsigned);
27         };
28
29         struct EyeParams
30         {
31                 Geometry::Angle<float> fov;
32                 float aspect;
33                 float near_clip;
34                 float far_clip;
35         };
36
37         struct Eye
38         {
39                 mutable GL::Camera camera;
40                 GL::Matrix offset_matrix;
41                 RenderTarget *target;
42
43                 Eye();
44
45                 void create_target(unsigned, unsigned);
46                 void setup_frame(const GL::Camera &, float, const EyeParams &) const;
47                 void render(const GL::Renderable &) const;
48         };
49
50         const StereoCombiner &combiner;
51         const GL::Camera &base_camera;
52         HeadTrackingCamera *head_camera;
53         const GL::Renderable *content;
54         Eye left;
55         Eye right;
56         Geometry::Angle<float> strabismus;
57
58 public:
59         StereoView(const StereoCombiner &, const GL::Camera &);
60         StereoView(const StereoCombiner &, HeadTrackingCamera &);
61 private:
62         void init();
63
64 public:
65         void set_content(const GL::Renderable *);
66         void set_eye_spacing(float);
67         void set_eye_matrices(const GL::Matrix &, const GL::Matrix &);
68         void set_strabismus(const Geometry::Angle<float> &);
69
70 private:
71         void setup_frame() const;
72 public:
73         void render() const;
74 };
75
76 } // namespace VR
77 } // namespace Msp
78
79 #endif