]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/view.cpp
Make use of View3D in engineer
[r2c2.git] / source / 3d / view.cpp
index 6b5115d1ed79a2fd143b40cce34ac3e3d8bfd39a..8943abce36e7e2c0307fca0b4f9bea6ce24ab11f 100644 (file)
@@ -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,13 +24,14 @@ 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)
 {
-       const set<Track *> &tracks = layout.get_layout().get_tracks();
+       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();
@@ -36,11 +39,11 @@ void View3D::view_all(bool tight)
        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;
+               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(center-look*dist);