]> git.tdb.fi Git - libs/vr.git/blob - source/stereocombiner.cpp
Move some common calculations to base classes
[libs/vr.git] / source / stereocombiner.cpp
1 #include <algorithm>
2 #include "stereocombiner.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace VR {
8
9 StereoCombiner::StereoCombiner():
10         target_width(0),
11         target_height(0),
12         render_aspect(1.0f),
13         frustum_skew(0.0f)
14 { }
15
16 void StereoCombiner::configure_eye_frustums(const Frustum &left_frustum, const Frustum &right_frustum)
17 {
18         float vertical = max(max(left_frustum.top, -left_frustum.bottom), max(right_frustum.top, -right_frustum.bottom));
19         fov = Geometry::atan<float>(vertical)*2.0f;
20
21         float inner = max(left_frustum.right, -right_frustum.left);
22         float outer = max(-left_frustum.left, right_frustum.right);
23         frustum_skew = (inner-outer)/(inner+outer);
24
25         render_aspect = (inner+outer)/(vertical*2);
26 }
27
28
29 StereoCombiner::Frustum::Frustum():
30         left(-1),
31         right(1),
32         bottom(-1),
33         top(1)
34 { }
35
36 StereoCombiner::Frustum::Frustum(float l, float r, float b, float t):
37         left(l),
38         right(r),
39         bottom(b),
40         top(t)
41 { }
42
43 } // namespace VR
44 } // namespace Msp