X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Flayout.cpp;h=1a557153fda308ce56a18066e281ca2e3e1b8830;hb=9b68c21ebf8ce26d92246ecd4a392d2908b511f7;hp=1b54e4be7509dd487d519d31a14d827557bfb801;hpb=47341c72a70e6cf9d8e963705a50197bbc20a87d;p=r2c2.git diff --git a/source/3d/layout.cpp b/source/3d/layout.cpp index 1b54e4b..1a55715 100644 --- a/source/3d/layout.cpp +++ b/source/3d/layout.cpp @@ -7,6 +7,8 @@ Distributed under the GPL #include #include +#include +#include #include #include #include @@ -20,22 +22,23 @@ namespace Marklin { Layout3D::Layout3D(Layout &l): layout(l), - catalogue(layout.get_catalogue()), - quality(4) + catalogue(layout.get_catalogue()) { layout.signal_track_added.connect(sigc::mem_fun(this, &Layout3D::track_added)); layout.signal_track_removed.connect(sigc::mem_fun(this, &Layout3D::track_removed)); + layout.signal_train_added.connect(sigc::mem_fun(this, &Layout3D::train_added)); + + const set <racks = layout.get_tracks(); + for(set::iterator i=ltracks.begin(); i!=ltracks.end(); ++i) + track_added(**i); } Layout3D::~Layout3D() { while(!tracks.empty()) delete tracks.front(); -} - -void Layout3D::set_quality(unsigned q) -{ - quality = q; + while(!trains.empty()) + delete trains.front(); } void Layout3D::add_track(Track3D &t) @@ -65,41 +68,22 @@ Track3D *Layout3D::pick_track(float x, float y, float size) const GL::select_buffer(select_buf); GL::render_mode(GL::SELECT); - glPushMatrix(); - glLoadIdentity(); - - double clip[4]; - clip[0] = 1; - clip[1] = 0; - clip[2] = x-size; - clip[3] = 0; - glClipPlane(GL_CLIP_PLANE0, clip); - glEnable(GL_CLIP_PLANE0); - - clip[0] = -1; - clip[2] = -(x+size); - glClipPlane(GL_CLIP_PLANE1, clip); - glEnable(GL_CLIP_PLANE1); + { + GL::PushMatrix push_mat; + GL::load_identity(); - clip[0] = 0; - clip[1] = 1; - clip[2] = y-size; - glClipPlane(GL_CLIP_PLANE2, clip); - glEnable(GL_CLIP_PLANE2); - - clip[1] = -1; - clip[2] = -(y+size); - glClipPlane(GL_CLIP_PLANE3, clip); - glEnable(GL_CLIP_PLANE3); - - glPopMatrix(); + GL::ClipPlane(1, 0, x-size, 0).apply_to(0); + GL::ClipPlane(-1, 0, -x-size, 0).apply_to(1); + GL::ClipPlane(0, 1, y-size, 0).apply_to(2); + GL::ClipPlane(0, -1, -y-size, 0).apply_to(3); + } scene.render(0); - glDisable(GL_CLIP_PLANE0); - glDisable(GL_CLIP_PLANE1); - glDisable(GL_CLIP_PLANE2); - glDisable(GL_CLIP_PLANE3); + GL::ClipPlane::disable(0); + GL::ClipPlane::disable(1); + GL::ClipPlane::disable(2); + GL::ClipPlane::disable(3); GL::render_mode(GL::RENDER); Track3D *track = 0; @@ -114,6 +98,27 @@ Track3D *Layout3D::pick_track(float x, float y, float size) const return track; } +void Layout3D::add_train(Train3D &t) +{ + trains.push_back(&t); +} + +void Layout3D::remove_train(Train3D &t) +{ + list::iterator i = find(trains.begin(), trains.end(), &t); + if(i!=trains.end()) + trains.erase(i); +} + +Train3D &Layout3D::get_train(const Train &t) const +{ + for(list::const_iterator i=trains.begin(); i!=trains.end(); ++i) + if(&(*i)->get_train()==&t) + return **i; + + throw KeyError("Unknown train"); +} + void Layout3D::track_added(Track &t) { new Track3D(*this, t); @@ -129,4 +134,9 @@ void Layout3D::track_removed(Track &t) } } +void Layout3D::train_added(Train &t) +{ + new Train3D(*this, t); +} + } // namespace Marklin