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()))
27 layout.add_track(*this);
28 layout.get_scene().add(*this);
30 const vector<Endpoint> &type_eps = track.get_type().get_endpoints();
31 for(unsigned i=0; i<type_eps.size(); ++i)
32 endpoints.push_back(new Endpoint3D(*this, i));
37 layout.remove_track(*this);
38 layout.get_scene().remove(*this);
40 for(vector<Endpoint3D *>::iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
44 void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const
46 type.get_bounds(angle-track.get_rotation(), minp, maxp);
48 float c = cos(-angle);
49 float s = sin(-angle);
51 const Point &pos = track.get_position();
52 minp.x += c*pos.x-s*pos.y;
53 maxp.x += c*pos.x-s*pos.y;
54 minp.y += s*pos.x+c*pos.y;
55 maxp.y += s*pos.x+c*pos.y;
59 float slope = track.get_slope();
66 void Track3D::render(const GL::Tag &tag) const
68 GL::PushMatrix push_mat;
70 const Point &pos = track.get_position();
71 float rot = track.get_rotation();
73 glTranslatef(pos.x, pos.y, pos.z);
74 glRotatef(rot*180/M_PI, 0, 0, 1);
75 glRotatef(track.get_slope()/track.get_type().get_total_length()*180/M_PI, 0, -1, 0);
77 glPushName(reinterpret_cast<unsigned>(this));
84 } // namespace Marklin