1 #include <msp/gl/blend.h>
2 #include <msp/gl/tests.h>
12 View3D::View3D(Layout3D &l, unsigned w, unsigned h):
18 pipeline.set_camera(&camera);
19 pipeline.add_renderable_for_pass(layout.get_scene(), 0);
20 pipeline.add_renderable_for_pass(layout.get_scene(), "translucent");
22 GL::Pipeline::Pass *pass = &pipeline.add_pass(0);
23 pass->set_lighting(&layout.get_lighting());
24 pass->set_depth_test(&GL::DepthTest::lequal());
26 pass = &pipeline.add_pass("translucent");
27 pass->set_lighting(&layout.get_lighting());
28 pass->set_depth_test(&GL::DepthTest::lequal());
29 pass->set_blend(&GL::Blend::alpha());
31 camera.set_up_direction(GL::Vector3(0, 0, 1));
33 camera.set_look_direction(GL::Vector3(0, 0.5, -0.866));
34 camera.set_aspect(float(width)/height);
39 Ray View3D::create_ray(int x, int y) const
41 return create_ray(x*2.0f/width-1.0f, y*2.0f/height-1.0f);
44 Ray View3D::create_ray(float x, float y) const
46 const GL::Vector3 &start = camera.get_position();
47 GL::Vector4 ray = camera.unproject(GL::Vector4(x, y, 0, 0));
48 return Ray(start, Vector(ray));
51 void View3D::view_all(bool tight)
53 const set<Track *> &tracks = layout.get_layout().get_all<Track>();
54 Geometry::BoundingBox<float, 3> bbox;
55 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
56 bbox = bbox|(*i)->get_bounding_box();
58 const Vector &minp = bbox.get_minimum_point();
59 const Vector &maxp = bbox.get_maximum_point();
61 float t = tan(camera.get_field_of_view()/2.0f)*2.0f;
62 float size = max((maxp.y-minp.y+0.1), (maxp.x-minp.x+0.1)/camera.get_aspect());
65 dist += sin(camera.get_field_of_view()/2.0f)*size;
66 GL::Vector3 center = (minp+maxp)/2.0f;
67 const GL::Vector3 &look = camera.get_look_direction();
68 camera.set_position(center-look*dist);