1 #include <msp/gl/blend.h>
2 #include <msp/gl/tests.h>
12 View3D::View3D(Layout3D &l, unsigned w, unsigned h):
17 sky(layout.get_catalogue())
19 pipeline.set_camera(&camera);
20 pipeline.add_renderable(sky);
21 pipeline.add_renderable_for_pass(layout.get_scene(), 0);
22 pipeline.add_renderable_for_pass(layout.get_scene(), "translucent");
24 GL::Pipeline::Pass *pass = &pipeline.add_pass("sky");
26 pass = &pipeline.add_pass(0);
27 pass->set_lighting(&layout.get_lighting());
28 pass->set_depth_test(&GL::DepthTest::lequal());
30 pass = &pipeline.add_pass("translucent");
31 pass->set_lighting(&layout.get_lighting());
32 pass->set_depth_test(&GL::DepthTest::lequal());
33 pass->set_blend(&GL::Blend::alpha());
35 camera.set_up_direction(GL::Vector3(0, 0, 1));
37 camera.set_look_direction(GL::Vector3(0, 0.5, -0.866));
38 camera.set_aspect(float(width)/height);
43 Ray View3D::create_ray(int x, int y) const
45 return create_ray(x*2.0f/width-1.0f, y*2.0f/height-1.0f);
48 Ray View3D::create_ray(float x, float y) const
50 const GL::Vector3 &start = camera.get_position();
51 GL::Vector4 ray = camera.unproject(GL::Vector4(x, y, 0, 0));
52 return Ray(start, Vector(ray));
55 void View3D::view_all(bool tight)
57 const set<Track *> &tracks = layout.get_layout().get_all<Track>();
58 Geometry::BoundingBox<float, 3> bbox;
59 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
60 bbox = bbox|(*i)->get_bounding_box();
62 const Vector &minp = bbox.get_minimum_point();
63 const Vector &maxp = bbox.get_maximum_point();
65 float t = tan(camera.get_field_of_view()/2.0f)*2.0f;
66 float size = max((maxp.y-minp.y+0.1), (maxp.x-minp.x+0.1)/camera.get_aspect());
69 dist += sin(camera.get_field_of_view()/2.0f)*size;
70 GL::Vector3 center = (minp+maxp)/2.0f;
71 const GL::Vector3 &look = camera.get_look_direction();
72 camera.set_position(center-look*dist);