1 #include <msp/core/maputils.h>
2 #include <msp/gl/meshbuilder.h>
4 #include "signaltype.h"
6 #include "vehicletype.h"
13 Catalogue3D::Catalogue3D(Catalogue &c):
16 src.add_directory(".");
17 src.add_directory("data");
21 Catalogue3D::~Catalogue3D()
23 for(map<const ObjectType *, ObjectType3D *>::iterator i=objects.begin(); i!=objects.end(); ++i)
27 const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot)
29 ObjectMap::iterator i = objects.find(&ot);
33 ObjectType3D *ot3d = 0;
34 if(const TrackType *tt = dynamic_cast<const TrackType *>(&ot))
35 ot3d = new TrackType3D(*this, *tt);
36 else if(const SignalType *st = dynamic_cast<const SignalType *>(&ot))
37 ot3d = new SignalType3D(*this, *st);
38 else if(const VehicleType *vt = dynamic_cast<const VehicleType *>(&ot))
39 ot3d = new VehicleType3D(*this, *vt);
47 const ObjectType3D &Catalogue3D::get_3d(const ObjectType &ot) const
49 return *get_item(objects, &ot);
52 const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance)
54 EndpointMap::iterator i = endpoint_meshes.find(&appearance);
55 if(i!=endpoint_meshes.end())
58 const Profile &ballast_profile = appearance.get_ballast_profile();
59 const Vector &ballast_min = ballast_profile.get_min_coords();
60 const Vector &ballast_max = ballast_profile.get_max_coords();
62 const Profile &rail_profile = appearance.get_rail_profile();
63 const Vector &rail_min = rail_profile.get_min_coords();
64 const Vector &rail_max = rail_profile.get_max_coords();
66 float gauge = appearance.get_gauge();
68 float width = max(max(-ballast_min.x, ballast_max.x)*2, gauge+(rail_max.x-rail_min.x)*2)+0.004;
69 float height = ballast_max.y-ballast_min.y+rail_max.y-rail_min.y+0.01;
71 GL::Mesh *mesh = new GL::Mesh((GL::NORMAL3, GL::VERTEX3));
72 GL::MeshBuilder bld(*mesh);
75 bld.vertex(0, width/2, 0);
76 bld.vertex(0, width/2, height);
77 bld.vertex(0, -width/2, height);
78 bld.vertex(0, -width/2, 0);
81 endpoint_meshes[&appearance] = mesh;
85 const GL::Mesh &Catalogue3D::get_endpoint_mesh(const TrackAppearance &appearance) const
87 return *get_item(endpoint_meshes, &appearance);