]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/engineer.cpp
Make use of the geometry part of libmspmath
[r2c2.git] / source / engineer / engineer.cpp
index ad26e50c46ea087d99175f73a525089ee2b5fd0c..69dc47bc98832a080180c99c510fc649971a9f55 100644 (file)
@@ -315,22 +315,16 @@ void Engineer::view_all()
        GL::Vector3 up;
        for(Angle angle; angle<Angle::half_turn(); angle+=Angle::from_radians(0.01))
        {
-               float min_x = 0;
-               float max_x = 0;
-               float min_y = 0;
-               float max_y = 0;
+               Transform trans = Transform::rotation(-angle, Vector(0, 0, 1));
+               BoundingBox bbox;
                for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
-               {
-                       Vector minp, maxp;
-                       i->second->get_bounds(angle, minp, maxp);
-                       min_x = min(min_x, minp.x);
-                       max_x = max(max_x, maxp.x);
-                       min_y = min(min_y, minp.y);
-                       max_y = max(max_y, maxp.y);
-               }
+                       bbox = bbox|trans.transform(i->second->get_track().get_bounding_box());
+
+               const Vector &minp = bbox.get_minimum_point();
+               const Vector &maxp = bbox.get_maximum_point();
 
-               float width = max_x-min_x;
-               float height = max_y-min_y;
+               float width = maxp.x-minp.x;
+               float height = maxp.y-minp.y;
                float aspect = width/height;
                float score = min(aspect/view_aspect, view_aspect/aspect);
 
@@ -341,8 +335,8 @@ void Engineer::view_all()
                        float size = max(width/view_aspect, height);
                        float c = cos(angle);
                        float s = sin(angle);
-                       float x = (min_x+max_x)/2-size*105/window.get_height();
-                       float y = (min_y+max_y)/2;
+                       float x = (minp.x+maxp.x)/2-size*105/window.get_height();
+                       float y = (minp.y+maxp.y)/2;
                        float z = max(size*1.05/view_height, 0.15);
 
                        pos = GL::Vector3(c*x-s*y, s*x+c*y, z);
@@ -391,7 +385,7 @@ Track *Engineer::pick_track(const Vector &p)
        const GL::Vector3 &start = camera.get_position();
        GL::Vector4 ray = camera.unproject(GL::Vector4(p.x, p.y, 0, 0));
 
-       return layout.pick_track(Vector(start.x, start.y, start.z), Vector(ray.x, ray.y, ray.z));
+       return layout.pick_track(Ray(start, Vector(ray)));
 }
 
 void Engineer::process_new_train(Train &train)