]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/track.cpp
Keep UI better in sync with the clock
[r2c2.git] / source / 3d / track.cpp
index bd148a7c3f307cb65ede9c21d341bec7b979137a..549bc156ba6dce2de6babcb6db4889441ce4b221 100644 (file)
@@ -14,13 +14,11 @@ using namespace Msp;
 namespace R2C2 {
 
 Track3D::Track3D(Layout3D &l, Track &t):
-       GL::ObjectInstance(l.get_catalogue().get_track(t.get_type()).get_object()),
-       layout(l),
+       Object3D(l, t),
+       GL::ObjectInstance(l.get_catalogue().get_3d(t.get_type()).get_object()),
        track(t),
-       type(layout.get_catalogue().get_track(track.get_type())),
-       path(new Path3D(*this))
+       type(layout.get_catalogue().get_3d(track.get_type()))
 {
-       layout.add_track(*this);
        layout.get_scene().add(*this);
 
        const vector<TrackType::Endpoint> &type_eps = track.get_type().get_endpoints();
@@ -38,52 +36,24 @@ Track3D::Track3D(Layout3D &l, Track &t):
 
 Track3D::~Track3D()
 {
-       delete path;
-
-       layout.remove_track(*this);
        layout.get_scene().remove(*this);
 
        for(vector<Endpoint3D *>::iterator i=endpoints.begin(); i!=endpoints.end(); ++i)
                delete *i;
 }
 
-void Track3D::get_bounds(const Angle &angle, Vector &minp, Vector &maxp) const
-{
-       type.get_bounds(angle-track.get_rotation(), minp, maxp);
-
-       Vector pos = rotated_vector(track.get_position(), -angle);
-       minp += pos;
-       maxp += pos;
-
-       float slope = track.get_slope();
-       if(slope>0)
-               maxp.z += slope;
-       else
-               minp.z += slope;
-}
-
 Vector Track3D::get_node() const
 {
-       Vector minp;
-       Vector maxp;
-       type.get_bounds(Angle::zero(), minp, maxp);
-
-       return track.get_position()+rotated_vector((minp+maxp)/2.0f, track.get_rotation())+Vector(0, 0, 0.02);
-}
-
-GL::Matrix Track3D::create_matrix() const
-{
-       GL::Matrix matrix;
-       matrix.translate(track.get_position());
-       matrix.rotate(track.get_rotation(), 0, 0, 1);
-       matrix.rotate(track.get_slope()/track.get_type().get_total_length(), 0, -1, 0);
+       Geometry::BoundingBox<float, 3> bbox = track.get_type().get_shape()->get_axis_aligned_bounding_box();
+       const Vector &minp = bbox.get_minimum_point();
+       const Vector &maxp = bbox.get_maximum_point();
 
-       return matrix;
+       return matrix*((minp+maxp)/2.0f+Vector(0, 0, 0.02));
 }
 
 void Track3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const
 {
-       renderer.matrix_stack() *= create_matrix();
+       renderer.matrix_stack() *= matrix;
 }
 
 void Track3D::link_changed(unsigned i, Track *trk)