X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Ftrack.cpp;h=ade3d132bcef669759bff1c6796e14699a9ce177;hb=9ddcd066e37e4c72685817c042c30897786ece05;hp=3241852f1ed32c606ad8c0dd07ea6a97e34684db;hpb=a861c2729a356173059177a0b800de2b31c9b49c;p=r2c2.git diff --git a/source/3d/track.cpp b/source/3d/track.cpp index 3241852..ade3d13 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -11,6 +11,7 @@ Distributed under the GPL #include "libmarklin/tracktype.h" #include "endpoint.h" #include "layout.h" +#include "path.h" #include "track.h" #include "tracktype.h" @@ -22,7 +23,8 @@ namespace Marklin { Track3D::Track3D(Layout3D &l, Track &t): layout(l), track(t), - type(layout.get_catalogue().get_track(track.get_type())) + type(layout.get_catalogue().get_track(track.get_type())), + path(new Path3D(*this)) { layout.add_track(*this); layout.get_scene().add(*this); @@ -63,16 +65,35 @@ void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const minp.z += slope; } -void Track3D::render(const GL::Tag &tag) const +Point Track3D::get_node() const { - GL::PushMatrix push_mat; + const Point &pos = track.get_position(); + Point minp; + Point maxp; + type.get_bounds(0, minp, maxp); + float rot = track.get_rotation(); + float c = cos(rot); + float s = sin(rot); + Point center((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, 0); + return Point(pos.x+c*center.x-s*center.y, pos.y+s*center.x+c*center.y, pos.z+0.02); +} + +void Track3D::apply_matrix() const +{ const Point &pos = track.get_position(); float rot = track.get_rotation(); glTranslatef(pos.x, pos.y, pos.z); glRotatef(rot*180/M_PI, 0, 0, 1); glRotatef(track.get_slope()/track.get_type().get_total_length()*180/M_PI, 0, -1, 0); +} + +void Track3D::render(const GL::Tag &tag) const +{ + GL::PushMatrix push_mat; + + apply_matrix(); glPushName(reinterpret_cast(this));