]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/layout.cpp
Rename Track3D::get_matrix to create_matrix to avoid a conflict
[r2c2.git] / source / 3d / layout.cpp
index 0a9ee2d2b4c5362888c7d9996ef965e91f2da3a5..7fd0d4ddac4b112073374fc25f6d4f96284f29c1 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #include "layout.h"
 #include "track.h"
 #include "vehicle.h"
@@ -18,6 +11,10 @@ Layout3D::Layout3D(Layout &l):
        layout(l),
        catalogue(layout.get_catalogue())
 {
+       // South, 15° from zenith
+       sun.set_position(0, -0.259, 0.966, 0);
+       lighting.attach(0, sun);
+
        layout.signal_track_added.connect(sigc::mem_fun(this, &Layout3D::track_added));
        layout.signal_track_removed.connect(sigc::mem_fun(this, &Layout3D::track_removed));
        layout.signal_vehicle_added.connect(sigc::mem_fun(this, &Layout3D::vehicle_added));
@@ -36,12 +33,25 @@ Layout3D::~Layout3D()
                delete vehicles.begin()->second;
 }
 
-void Layout3D::add_track(Track3D &t)
+void Layout3D::get_bounds(Vector &minp, Vector &maxp) const
 {
-       if(tracks.count(&t.get_track()))
-               throw KeyError("Duplicate track");
+       minp = maxp = Vector();
+
+       for(TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+       {
+               Vector tmin;
+               Vector tmax;
+               i->second->get_bounds(0, tmin, tmax);
+               minp.x = min(minp.x, tmin.x);
+               minp.y = min(minp.y, tmin.y);
+               maxp.x = max(maxp.x, tmax.x);
+               maxp.y = max(maxp.y, tmax.y);
+       }
+}
 
-       tracks[&t.get_track()] = &t;
+void Layout3D::add_track(Track3D &t)
+{
+       insert_unique(tracks, &t.get_track(), &t);
 }
 
 void Layout3D::remove_track(Track3D &t)
@@ -51,19 +61,12 @@ void Layout3D::remove_track(Track3D &t)
 
 Track3D &Layout3D::get_track(Track &t) const
 {
-       TrackMap::const_iterator i = tracks.find(&t);
-       if(i==tracks.end())
-               throw KeyError("Unknown track");
-
-       return *i->second;
+       return *get_item(tracks, &t);
 }
 
 void Layout3D::add_vehicle(Vehicle3D &v)
 {
-       if(vehicles.count(&v.get_vehicle()))
-               throw KeyError("Duplicate vehicle");
-
-       vehicles[&v.get_vehicle()] = &v;
+       insert_unique(vehicles, &v.get_vehicle(), &v);
 }
 
 void Layout3D::remove_vehicle(Vehicle3D &v)
@@ -73,11 +76,7 @@ void Layout3D::remove_vehicle(Vehicle3D &v)
 
 Vehicle3D &Layout3D::get_vehicle(Vehicle &v) const
 {
-       VehicleMap::const_iterator i = vehicles.find(&v);
-       if(i==vehicles.end())
-               throw KeyError("Unknown vehicle");
-
-       return *i->second;
+       return *get_item(vehicles, &v);
 }
 
 void Layout3D::track_added(Track &t)