1 #include <msp/core/maputils.h>
2 #include <msp/gl/meshbuilder.h>
3 #include "libr2c2/trackappearance.h"
5 #include "signaltype.h"
7 #include "vehicletype.h"
14 Catalogue3D::Catalogue3D(Catalogue &c):
17 const list<DataFile::CollectionSource *> &src = catalogue.get_sources();
18 for(list<DataFile::CollectionSource *>::const_iterator i=src.begin(); i!=src.end(); ++i)
20 catalogue.signal_source_added.connect(sigc::mem_fun(static_cast<DataFile::Collection *>(this), &Catalogue3D::add_source));
22 set_srgb_conversion(true);
25 Catalogue3D::~Catalogue3D()
27 for(map<const ObjectType *, ObjectType3D *>::iterator i=objects.begin(); i!=objects.end(); ++i)
31 const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot)
33 ObjectMap::iterator i = objects.find(&ot);
37 ObjectType3D *ot3d = 0;
38 if(const TrackType *tt = dynamic_cast<const TrackType *>(&ot))
39 ot3d = new TrackType3D(*this, *tt);
40 else if(const SignalType *st = dynamic_cast<const SignalType *>(&ot))
41 ot3d = new SignalType3D(*this, *st);
42 else if(const VehicleType *vt = dynamic_cast<const VehicleType *>(&ot))
43 ot3d = new VehicleType3D(*this, *vt);
51 const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot) const
53 return *get_item(objects, &ot);
56 const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance)
58 EndpointMap::iterator i = endpoint_meshes.find(&appearance);
59 if(i!=endpoint_meshes.end())
62 const Profile &ballast_profile = appearance.get_ballast_profile();
63 const Vector &ballast_min = ballast_profile.get_min_coords();
64 const Vector &ballast_max = ballast_profile.get_max_coords();
66 const Profile &rail_profile = appearance.get_rail_profile();
67 const Vector &rail_min = rail_profile.get_min_coords();
68 const Vector &rail_max = rail_profile.get_max_coords();
70 float gauge = appearance.get_gauge();
72 float width = max(max(-ballast_min.x, ballast_max.x)*2, gauge+(rail_max.x-rail_min.x)*2)+0.004;
73 float height = ballast_max.y-ballast_min.y+rail_max.y-rail_min.y+0.01;
75 GL::Mesh *mesh = new GL::Mesh((GL::NORMAL3, GL::VERTEX3));
76 GL::MeshBuilder bld(*mesh);
79 bld.vertex(0, width/2, 0);
80 bld.vertex(0, width/2, height);
81 bld.vertex(0, -width/2, height);
82 bld.vertex(0, -width/2, 0);
85 endpoint_meshes[&appearance] = mesh;
89 const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance) const
91 return *get_item(endpoint_meshes, &appearance);