3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gl/meshbuilder.h>
10 #include "tracktype.h"
17 Catalogue3D::Catalogue3D(const Catalogue &c):
19 endpoint_mesh((GL::NORMAL3, GL::VERTEX3))
21 const map<unsigned, TrackType *> &trks = catalogue.get_tracks();
22 for(map<unsigned, TrackType *>::const_iterator i=trks.begin(); i!=trks.end(); ++i)
23 tracks[i->second] = new TrackType3D(*this, *i->second);
25 ballast_material.set_diffuse(GL::Color(0.25, 0.25, 0.25));
26 rail_material.set_diffuse(GL::Color(0.85, 0.85, 0.85));
28 build_endpoint_mesh();
31 Catalogue3D::~Catalogue3D()
33 for(map<const TrackType *, TrackType3D *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
37 const TrackType3D &Catalogue3D::get_track(const TrackType &tt) const
39 map<const TrackType *, TrackType3D *>::const_iterator i = tracks.find(&tt);
41 throw KeyError("Unknown track type");
46 void Catalogue3D::build_endpoint_mesh()
48 const Profile &ballast_profile = catalogue.get_ballast_profile();
49 const Point &ballast_min = ballast_profile.get_min_coords();
50 const Point &ballast_max = ballast_profile.get_max_coords();
52 const Profile &rail_profile = catalogue.get_rail_profile();
53 const Point &rail_min = rail_profile.get_min_coords();
54 const Point &rail_max = rail_profile.get_max_coords();
56 float gauge = catalogue.get_gauge();
58 float width = max(max(-ballast_min.x, ballast_max.x)*2, gauge+(rail_max.x-rail_min.x)*2)+0.004;
59 float height = ballast_max.y-ballast_min.y+rail_max.y-rail_min.y+0.01;
61 GL::MeshBuilder bld(endpoint_mesh);
64 bld.vertex(0, width/2, 0);
65 bld.vertex(0, width/2, height);
66 bld.vertex(0, -width/2, height);
67 bld.vertex(0, -width/2, 0);
71 } // namespace Marklin