X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Ftrack.cpp;h=a5c5dbf62a166904a5e3203d28b53af8a637284c;hb=47bff0c8939de3ae20b5ced1ee2f6a264397dcee;hp=c3eb388dc8bb4a96b35a4a797319cf53db8dd949;hpb=7e382cc3cad8c4f6945b0c9d89e2ca917b42b740;p=r2c2.git diff --git a/source/3d/track.cpp b/source/3d/track.cpp index c3eb388..a5c5dbf 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -6,9 +6,10 @@ Distributed under the GPL */ #include -#include +#include #include #include "libmarklin/tracktype.h" +#include "endpoint.h" #include "layout.h" #include "track.h" #include "tracktype.h" @@ -21,13 +22,23 @@ namespace Marklin { Track3D::Track3D(Layout3D &l, Track &t): layout(l), track(t), - type(layout.get_catalogue().get_track(track.get_type())), - color(1, 1, 1) -{ } + type(layout.get_catalogue().get_track(track.get_type())) +{ + layout.add_track(*this); + layout.get_scene().add(*this); + + const vector &type_eps = track.get_type().get_endpoints(); + for(unsigned i=0; i::iterator i=endpoints.begin(); i!=endpoints.end(); ++i) + delete *i; } void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const @@ -42,6 +53,8 @@ void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const maxp.x += c*pos.x-s*pos.y; minp.y += s*pos.x+c*pos.y; maxp.y += s*pos.x+c*pos.y; + minp.z += pos.z; + maxp.z += pos.z; float slope = track.get_slope(); if(slope>0) @@ -50,96 +63,36 @@ void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const minp.z += slope; } -void Track3D::render() const +Point Track3D::get_node() const { - prepare_render(true); - - glPushName(reinterpret_cast(this)); - - type.render(); + 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); - glPopName(); - glPopMatrix(); + 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::render_endpoints() const +void Track3D::render(const GL::Tag &tag) const { - prepare_render(false); - - const vector &endpoints = track.get_type().get_endpoints(); - for(unsigned i=0; i1e-4) - { - Point p; - if(track.get_slope()>0) - { - p = endpoints[1].pos; - p.z += track.get_slope(); - } - else - p = endpoints[0].pos; - glBegin(GL_TRIANGLE_STRIP); - for(unsigned i=0; i<=16; ++i) - { - float c = cos(i*M_PI/8); - float s = sin(i*M_PI/8); - glNormal3f(c, s, 0); - glVertex3f(p.x+c*0.01, p.y+s*0.01, p.z); - glVertex3f(p.x+c*0.01, p.y+s*0.01, -track.get_position().z); - } - glEnd(); - } - - glPopMatrix(); -} + GL::PushMatrix push_mat; -void Track3D::render_path(int path) const -{ - prepare_render(true); - - (void)path; - /*varray.apply(); - if(path>=0 && static_cast(path)(this)); + + type.render(tag); + + glPopName(); } } // namespace Marklin