X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Fview.cpp;h=8943abce36e7e2c0307fca0b4f9bea6ce24ab11f;hb=18c529dfdd34e07f4f6021151ddce29fa85437bc;hp=4cd553d48575accca0ddcae31b83044dfd83e9aa;hpb=ff6a2d7146e9e8981ae0f53815b71aabec31f063;p=r2c2.git diff --git a/source/3d/view.cpp b/source/3d/view.cpp index 4cd553d..8943abc 100644 --- a/source/3d/view.cpp +++ b/source/3d/view.cpp @@ -10,6 +10,8 @@ namespace R2C2 { View3D::View3D(Layout3D &l, unsigned w, unsigned h): layout(l), + width(w), + height(h), pipeline(w, h) { pipeline.set_camera(&camera); @@ -22,25 +24,29 @@ View3D::View3D(Layout3D &l, unsigned w, unsigned h): 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(); } void View3D::view_all(bool tight) { - Vector minp; - Vector maxp; + const set &tracks = layout.get_layout().get_all(); + Geometry::BoundingBox bbox; + for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + bbox = bbox|(*i)->get_bounding_box(); - layout.get_bounds(minp, maxp); + const Vector &minp = bbox.get_minimum_point(); + const Vector &maxp = bbox.get_maximum_point(); - float t = tan(camera.get_field_of_view()/2)*2; + float t = tan(camera.get_field_of_view()/2.0f)*2.0f; float size = max((maxp.y-minp.y+0.1), (maxp.x-minp.x+0.1)/camera.get_aspect()); float dist = size/t; if(!tight) - dist += sin(camera.get_field_of_view()/2)*size; - GL::Vector3 center((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, 0); + dist += sin(camera.get_field_of_view()/2.0f)*size; + GL::Vector3 center = (minp+maxp)/2.0f; const GL::Vector3 &look = camera.get_look_direction(); - camera.set_position(GL::Vector3(center.x-look.x*dist, center.y-look.y*dist, center.z-look.z*dist)); + camera.set_position(center-look*dist); } void View3D::render()