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));
23 Catalogue3D::~Catalogue3D()
25 for(map<const ObjectType *, ObjectType3D *>::iterator i=objects.begin(); i!=objects.end(); ++i)
29 const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot)
31 ObjectMap::iterator i = objects.find(&ot);
35 ObjectType3D *ot3d = 0;
36 if(const TrackType *tt = dynamic_cast<const TrackType *>(&ot))
37 ot3d = new TrackType3D(*this, *tt);
38 else if(const SignalType *st = dynamic_cast<const SignalType *>(&ot))
39 ot3d = new SignalType3D(*this, *st);
40 else if(const VehicleType *vt = dynamic_cast<const VehicleType *>(&ot))
41 ot3d = new VehicleType3D(*this, *vt);
49 const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot) const
51 return *get_item(objects, &ot);
54 const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance)
56 EndpointMap::iterator i = endpoint_meshes.find(&appearance);
57 if(i!=endpoint_meshes.end())
60 const Profile &ballast_profile = appearance.get_ballast_profile();
61 const Vector &ballast_min = ballast_profile.get_min_coords();
62 const Vector &ballast_max = ballast_profile.get_max_coords();
64 const Profile &rail_profile = appearance.get_rail_profile();
65 const Vector &rail_min = rail_profile.get_min_coords();
66 const Vector &rail_max = rail_profile.get_max_coords();
68 float gauge = appearance.get_gauge();
70 float width = max(max(-ballast_min.x, ballast_max.x)*2, gauge+(rail_max.x-rail_min.x)*2)+0.004;
71 float height = ballast_max.y-ballast_min.y+rail_max.y-rail_min.y+0.01;
73 GL::Mesh *mesh = new GL::Mesh((GL::NORMAL3, GL::VERTEX3));
74 GL::MeshBuilder bld(*mesh);
77 bld.vertex(0, width/2, 0);
78 bld.vertex(0, width/2, height);
79 bld.vertex(0, -width/2, height);
80 bld.vertex(0, -width/2, 0);
83 endpoint_meshes[&appearance] = mesh;
87 const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance) const
89 return *get_item(endpoint_meshes, &appearance);