X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Fview.cpp;h=b833605c87227951e798de68983bbaac46eead27;hb=c796e17cef61ad2e3f476b6037892d7bc6c52680;hp=017a526df71b215ca192218116f79b3fd97c7178;hpb=1251ba0141983481181d8260523ff07f2cf200a0;p=r2c2.git diff --git a/source/3d/view.cpp b/source/3d/view.cpp index 017a526..b833605 100644 --- a/source/3d/view.cpp +++ b/source/3d/view.cpp @@ -1,3 +1,4 @@ +#include #include #include "layout.h" #include "track.h" @@ -10,22 +11,47 @@ namespace R2C2 { View3D::View3D(Layout3D &l, unsigned w, unsigned h): layout(l), - pipeline(w, h) + width(w), + height(h), + pipeline(w, h), + sky(layout.get_catalogue()) { pipeline.set_camera(&camera); + pipeline.add_renderable(sky); pipeline.add_renderable_for_pass(layout.get_scene(), 0); + pipeline.add_renderable_for_pass(layout.get_scene(), "translucent"); - GL::Pipeline::Pass *pass = &pipeline.add_pass(0); + GL::Pipeline::Pass *pass = &pipeline.add_pass("sky"); + + pass = &pipeline.add_pass(0); pass->set_lighting(&layout.get_lighting()); pass->set_depth_test(&GL::DepthTest::lequal()); + pass = &pipeline.add_pass("translucent"); + pass->set_lighting(&layout.get_lighting()); + pass->set_depth_test(&GL::DepthTest::lequal()); + pass->set_blend(&GL::Blend::alpha()); + camera.set_up_direction(GL::Vector3(0, 0, 1)); // Y+, 60° down camera.set_look_direction(GL::Vector3(0, 0.5, -0.866)); + camera.set_aspect(float(width)/height); view_all(); } +Ray View3D::create_ray(int x, int y) const +{ + return create_ray(x*2.0f/width-1.0f, y*2.0f/height-1.0f); +} + +Ray View3D::create_ray(float x, float y) const +{ + const GL::Vector3 &start = camera.get_position(); + GL::Vector4 ray = camera.unproject(GL::Vector4(x, y, 0, 0)); + return Ray(start, Vector(ray)); +} + void View3D::view_all(bool tight) { const set &tracks = layout.get_layout().get_all();