2 #include <msp/gl/matrix.h>
3 #include <msp/gl/renderer.h>
4 #include "libr2c2/tracktype.h"
16 Track3D::Track3D(Layout3D &l, Track &t):
18 GL::ObjectInstance(l.get_catalogue().get_track(t.get_type()).get_object()),
20 type(layout.get_catalogue().get_track(track.get_type())),
21 path(new Path3D(*this))
23 layout.get_scene().add(*this);
25 const vector<TrackType::Endpoint> &type_eps = track.get_type().get_endpoints();
26 const vector<Track *> &links = track.get_links();
27 for(unsigned i=0; i<type_eps.size(); ++i)
29 if(!links[i] || links[i]>&track)
30 endpoints.push_back(new Endpoint3D(*this, i));
32 endpoints.push_back(0);
35 track.signal_link_changed.connect(sigc::mem_fun(this, &Track3D::link_changed));
42 layout.get_scene().remove(*this);
44 for(vector<Endpoint3D *>::iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
48 Vector Track3D::get_node() const
50 Geometry::BoundingBox<float, 3> bbox = track.get_type().get_shape()->get_axis_aligned_bounding_box();
51 const Vector &minp = bbox.get_minimum_point();
52 const Vector &maxp = bbox.get_maximum_point();
54 return matrix*((minp+maxp)/2.0f+Vector(0, 0, 0.02));
57 void Track3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const
59 renderer.matrix_stack() *= matrix;
62 void Track3D::link_changed(unsigned i, Track *trk)
64 if(!trk || trk>&track)
67 endpoints[i] = new Endpoint3D(*this, i);