X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Flayout.cpp;h=70c55096cfa91eed259b6be9ebd99ef701dfd88c;hb=9ddcd066e37e4c72685817c042c30897786ece05;hp=f3fe3795fa909a1e3cc4d5d259cbe9c31df61ca0;hpb=38fb8d56efde037a71c46a58bda314655e68ab6c;p=r2c2.git diff --git a/source/3d/layout.cpp b/source/3d/layout.cpp index f3fe379..70c5509 100644 --- a/source/3d/layout.cpp +++ b/source/3d/layout.cpp @@ -1,18 +1,21 @@ /* $Id$ This file is part of the MSP Märklin suite -Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ #include -#include #include +#include +#include #include #include #include #include #include "layout.h" +#include "track.h" +#include "vehicle.h" using namespace std; using namespace Msp; @@ -21,40 +24,35 @@ namespace Marklin { Layout3D::Layout3D(Layout &l): layout(l), - 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_vehicle_added.connect(sigc::mem_fun(this, &Layout3D::vehicle_added)); + + const set <racks = layout.get_tracks(); + for(set::iterator i=ltracks.begin(); i!=ltracks.end(); ++i) + track_added(**i); } Layout3D::~Layout3D() { - for(list::iterator i=tracks.begin(); i!=tracks.end(); ++i) - delete *i; + while(!tracks.empty()) + delete tracks.front(); + while(!vehicles.empty()) + delete vehicles.front(); } -void Layout3D::set_quality(unsigned q) +void Layout3D::add_track(Track3D &t) { - quality = q; - for(list::iterator i=tracks.begin(); i!=tracks.end(); ++i) - (*i)->set_quality(quality); + tracks.push_back(&t); } -void Layout3D::render(bool endpoints) const +void Layout3D::remove_track(Track3D &t) { - GL::Texture::unbind(); - glEnable(GL_DEPTH_TEST); - - for(list::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) - (*i)->render(); - - if(endpoints) - { - glDepthMask(false); - for(list::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) - (*i)->render_endpoints(); - glDepthMask(true); - } + list::iterator i = find(tracks.begin(), tracks.end(), &t); + if(i!=tracks.end()) + tracks.erase(i); } Track3D &Layout3D::get_track(const Track &t) const @@ -62,7 +60,7 @@ Track3D &Layout3D::get_track(const Track &t) const for(list::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) if(&(*i)->get_track()==&t) return **i; - + throw KeyError("Unknown track"); } @@ -72,47 +70,28 @@ 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); - - 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); + { + GL::PushMatrix push_mat; + GL::load_identity(); - 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); + } - render(); + 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; unsigned track_depth = numeric_limits::max(); for(vector::iterator i=select_buf.begin(); i!=select_buf.end(); ++i) - if(i->min_depthmin_depthnames.empty()) { track = reinterpret_cast(i->names.back()); track_depth = i->min_depth; @@ -121,9 +100,30 @@ Track3D *Layout3D::pick_track(float x, float y, float size) const return track; } +void Layout3D::add_vehicle(Vehicle3D &v) +{ + vehicles.push_back(&v); +} + +void Layout3D::remove_vehicle(Vehicle3D &v) +{ + list::iterator i = find(vehicles.begin(), vehicles.end(), &v); + if(i!=vehicles.end()) + vehicles.erase(i); +} + +Vehicle3D &Layout3D::get_vehicle(const Vehicle &v) const +{ + for(list::const_iterator i=vehicles.begin(); i!=vehicles.end(); ++i) + if(&(*i)->get_vehicle()==&v) + return **i; + + throw KeyError("Unknown vehicle"); +} + void Layout3D::track_added(Track &t) { - tracks.push_back(new Track3D(t, quality)); + new Track3D(*this, t); } void Layout3D::track_removed(Track &t) @@ -132,9 +132,13 @@ void Layout3D::track_removed(Track &t) if(&(*i)->get_track()==&t) { delete *i; - tracks.erase(i); return; } } +void Layout3D::vehicle_added(Vehicle &v) +{ + new Vehicle3D(*this, v); +} + } // namespace Marklin