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_3d(t.get_type()).get_object()),
20 type(layout.get_catalogue().get_3d(track.get_type()))
22 layout.get_scene().add(*this);
24 const vector<TrackType::Endpoint> &type_eps = track.get_type().get_endpoints();
25 const vector<Track *> &links = track.get_links();
26 for(unsigned i=0; i<type_eps.size(); ++i)
28 if(!links[i] || links[i]>&track)
29 endpoints.push_back(new Endpoint3D(*this, i));
31 endpoints.push_back(0);
34 track.signal_link_changed.connect(sigc::mem_fun(this, &Track3D::link_changed));
39 layout.get_scene().remove(*this);
41 for(vector<Endpoint3D *>::iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
45 Vector Track3D::get_node() const
47 Geometry::BoundingBox<float, 3> bbox = track.get_type().get_shape()->get_axis_aligned_bounding_box();
48 const Vector &minp = bbox.get_minimum_point();
49 const Vector &maxp = bbox.get_maximum_point();
51 return matrix*((minp+maxp)/2.0f+Vector(0, 0, 0.02));
54 void Track3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const
56 renderer.matrix_stack() *= matrix;
59 void Track3D::link_changed(unsigned i, Track *trk)
61 if(!trk || trk>&track)
64 endpoints[i] = new Endpoint3D(*this, i);