]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/view.cpp
Angle must be divided by the correct type
[r2c2.git] / source / 3d / view.cpp
index 002d4800e82baf640b31fdf2dbcda5ea9287f86c..017a526df71b215ca192218116f79b3fd97c7178 100644 (file)
@@ -15,9 +15,9 @@ View3D::View3D(Layout3D &l, unsigned w, unsigned h):
        pipeline.set_camera(&camera);
        pipeline.add_renderable_for_pass(layout.get_scene(), 0);
 
-       GL::PipelinePass *pass = &pipeline.add_pass(0);
-       pass->lighting = &layout.get_lighting();
-       pass->depth_test = &GL::DepthTest::lequal();
+       GL::Pipeline::Pass *pass = &pipeline.add_pass(0);
+       pass->set_lighting(&layout.get_lighting());
+       pass->set_depth_test(&GL::DepthTest::lequal());
 
        camera.set_up_direction(GL::Vector3(0, 0, 1));
        // Y+, 60° down
@@ -28,24 +28,27 @@ View3D::View3D(Layout3D &l, unsigned w, unsigned h):
 
 void View3D::view_all(bool tight)
 {
-       Vector minp;
-       Vector maxp;
+       const set<Track *> &tracks = layout.get_layout().get_all<Track>();
+       Geometry::BoundingBox<float, 3> bbox;
+       for(set<Track *>::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()
 {
-       pipeline.render_all();
+       pipeline.render();
 }
 
 } // namespace R2C2