3 This file is part of R²C²
4 Copyright © 2011 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gl/tests.h>
18 View3D::View3D(Layout3D &l, unsigned w, unsigned h):
22 pipeline.set_camera(&camera);
23 pipeline.add_renderable_for_pass(layout.get_scene(), 0);
25 GL::PipelinePass *pass = &pipeline.add_pass(0);
26 pass->lighting = &layout.get_lighting();
27 pass->depth_test = &GL::DepthTest::lequal();
29 camera.set_up_direction(GL::Vector3(0, 0, 1));
31 camera.set_look_direction(GL::Vector3(0, 0.5, -0.866));
36 void View3D::view_all(bool tight)
41 layout.get_bounds(minp, maxp);
43 float t = tan(camera.get_field_of_view()/2)*2;
44 float size = max((maxp.y-minp.y+0.1), (maxp.x-minp.x+0.1)/camera.get_aspect());
47 dist += sin(camera.get_field_of_view()/2)*size;
48 GL::Vector3 center((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, 0);
49 const GL::Vector3 &look = camera.get_look_direction();
50 camera.set_position(GL::Vector3(center.x-look.x*dist, center.y-look.y*dist, center.z-look.z*dist));
55 pipeline.render_all();