namespace Msp {
namespace VR {
-StereoView::StereoView(const GL::Camera &c, const GL::Renderable &r, const StereoCombiner &m):
- base_camera(c),
- renderable(r),
- combiner(0)
+StereoView::StereoView(const StereoCombiner &c, const GL::Camera &a):
+ combiner(c),
+ base_camera(a),
+ content(0)
{
- set_combiner(m);
+ unsigned w = combiner.get_target_width();
+ unsigned h = combiner.get_target_height();
+ left.create_target(w, h);
+ right.create_target(w, h);
+
set_eye_spacing(0.064);
set_strabismus(Geometry::Angle<float>::zero());
}
-void StereoView::set_combiner(const StereoCombiner &c)
+void StereoView::set_content(const GL::Renderable *r)
{
- combiner = &c;
-
- unsigned w = combiner->get_target_width();
- unsigned h = combiner->get_target_height();
- left.create_target(w, h);
- right.create_target(w, h);
+ content = r;
}
void StereoView::set_eye_spacing(float s)
GL::Vector3 offset_axis = normalize(cross(base_camera.get_look_direction(), base_camera.get_up_direction()))*0.5f;
EyeParams params;
- params.fov = combiner->get_field_of_view();
+ params.fov = combiner.get_field_of_view();
if(params.fov==Geometry::Angle<float>::zero())
params.fov = base_camera.get_field_of_view();
- params.aspect = combiner->get_render_aspect();
+ params.aspect = combiner.get_render_aspect();
params.near_clip = base_camera.get_near_clip();
params.far_clip = base_camera.get_far_clip();
- float frustum_skew = combiner->get_frustum_skew();
+ float frustum_skew = combiner.get_frustum_skew();
float halfw = tan(params.fov/2.0f)*params.aspect;
frustum_skew = tan(Geometry::atan<float>(frustum_skew*halfw)+strabismus)/halfw;
void StereoView::render() const
{
setup_frame();
- renderable.setup_frame();
- left.render(renderable);
- right.render(renderable);
- renderable.finish_frame();
- combiner->render(left.target->color, right.target->color);
+ if(content)
+ {
+ content->setup_frame();
+ left.render(*content);
+ right.render(*content);
+ content->finish_frame();
+ }
+ combiner.render(left.target->color, right.target->color);
}
void render(const GL::Renderable &) const;
};
+ const StereoCombiner &combiner;
const GL::Camera &base_camera;
- const GL::Renderable &renderable;
- const StereoCombiner *combiner;
+ const GL::Renderable *content;
Eye left;
Eye right;
float eye_spacing;
Geometry::Angle<float> strabismus;
public:
- StereoView(const GL::Camera &, const GL::Renderable &, const StereoCombiner &);
+ StereoView(const StereoCombiner &, const GL::Camera &);
- void set_combiner(const StereoCombiner &);
+ void set_content(const GL::Renderable *);
void set_eye_spacing(float);
void set_strabismus(const Geometry::Angle<float> &);