2 #include <msp/gl/matrix.h>
3 #include <msp/gl/renderer.h>
4 #include "libr2c2/tracktype.h"
16 Track3D::Track3D(Layout3D &l, Track &t):
17 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.add_track(*this);
24 layout.get_scene().add(*this);
26 const vector<TrackType::Endpoint> &type_eps = track.get_type().get_endpoints();
27 const vector<Track *> &links = track.get_links();
28 for(unsigned i=0; i<type_eps.size(); ++i)
30 if(!links[i] || links[i]>&track)
31 endpoints.push_back(new Endpoint3D(*this, i));
33 endpoints.push_back(0);
36 track.signal_link_changed.connect(sigc::mem_fun(this, &Track3D::link_changed));
43 layout.remove_track(*this);
44 layout.get_scene().remove(*this);
46 for(vector<Endpoint3D *>::iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
50 Vector Track3D::get_node() const
52 Geometry::BoundingBox<float, 3> bbox = track.get_type().get_shape()->get_axis_aligned_bounding_box();
53 const Vector &minp = bbox.get_minimum_point();
54 const Vector &maxp = bbox.get_maximum_point();
56 return track.get_position()+rotated_vector((minp+maxp)/2.0f, track.get_rotation())+Vector(0, 0, 0.02);
59 GL::Matrix Track3D::create_matrix() const
62 matrix.translate(track.get_position());
63 matrix.rotate(track.get_rotation(), 0, 0, 1);
64 matrix.rotate(track.get_slope()/track.get_type().get_total_length(), 0, -1, 0);
69 void Track3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const
71 renderer.matrix_stack() *= create_matrix();
74 void Track3D::link_changed(unsigned i, Track *trk)
76 if(!trk || trk>&track)
79 endpoints[i] = new Endpoint3D(*this, i);