3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
9 #include <msp/gl/matrix.h>
10 #include <msp/gl/misc.h>
11 #include "libmarklin/tracktype.h"
15 #include "tracktype.h"
22 Track3D::Track3D(Layout3D &l, Track &t):
25 type(layout.get_catalogue().get_track(track.get_type())),
28 layout.add_track(*this);
29 layout.get_scene().add(*this);
31 const vector<Endpoint> &type_eps = track.get_type().get_endpoints();
32 for(unsigned i=0; i<type_eps.size(); ++i)
33 endpoints.push_back(new Endpoint3D(*this, i));
38 layout.remove_track(*this);
39 layout.get_scene().remove(*this);
41 for(vector<Endpoint3D *>::iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
45 void Track3D::set_color(const Msp::GL::Color &c)
50 void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const
52 type.get_bounds(angle-track.get_rotation(), minp, maxp);
54 float c = cos(-angle);
55 float s = sin(-angle);
57 const Point &pos = track.get_position();
58 minp.x += c*pos.x-s*pos.y;
59 maxp.x += c*pos.x-s*pos.y;
60 minp.y += s*pos.x+c*pos.y;
61 maxp.y += s*pos.x+c*pos.y;
65 float slope = track.get_slope();
72 void Track3D::render(const GL::Tag &tag) const
74 GL::PushMatrix push_mat;
76 const Point &pos = track.get_position();
77 float rot = track.get_rotation();
79 glTranslatef(pos.x, pos.y, pos.z);
80 glRotatef(rot*180/M_PI, 0, 0, 1);
81 glRotatef(track.get_slope()/track.get_type().get_total_length()*180/M_PI, 0, -1, 0);
83 glPushName(reinterpret_cast<unsigned>(this));
90 } // namespace Marklin