From: Mikko Rasa Date: Fri, 14 Jan 2011 13:12:58 +0000 (+0000) Subject: Enable Renderer for Endpoint3D and Path3D X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=949b13aae247fa53579ec1cda9142ccc8755acde;p=r2c2.git Enable Renderer for Endpoint3D and Path3D Add signal_link_changed to Track Only create one Endpoint3D per connected endpoint pair Remove the old rendering code from Vehicle3D Use WindingTest to manage face culling --- diff --git a/source/3d/endpoint.cpp b/source/3d/endpoint.cpp index 7e33ced..440d3f7 100644 --- a/source/3d/endpoint.cpp +++ b/source/3d/endpoint.cpp @@ -8,6 +8,7 @@ Distributed under the GPL #include #include #include +#include #include "endpoint.h" #include "layout.h" #include "track.h" @@ -29,24 +30,25 @@ Endpoint3D::~Endpoint3D() track.get_layout().get_endpoint_scene().remove(*this); } -void Endpoint3D::render(const GL::Tag &tag) const +void Endpoint3D::render(GL::Renderer &renderer, const GL::Tag &tag) const { if(tag=="unlit") { Point p = track.get_track().get_endpoint_position(index); float a = track.get_track().get_endpoint_direction(index)+M_PI; - GL::PushMatrix push_mat; - GL::translate(p.x, p.y, p.z); - GL::rotate(a*180/M_PI, 0, 0, 1); + GL::MatrixStack::Push push_mtx(renderer.matrix_stack()); + GL::Matrix matrix; + matrix.translate(p.x, p.y, p.z); + matrix.rotate(a, 0, 0, 1); + renderer.matrix_stack() *= matrix; - GL::set(GL_CULL_FACE, track.get_track().get_link(index)); if(track.get_track().get_link(index)) glColor4f(0.5, 0, 1, 0.5); else glColor4f(1, 0, 0.5, 0.5); - mesh.draw(); + mesh.draw(renderer); } } diff --git a/source/3d/endpoint.h b/source/3d/endpoint.h index e407127..03955cd 100644 --- a/source/3d/endpoint.h +++ b/source/3d/endpoint.h @@ -27,7 +27,7 @@ public: Endpoint3D(const Track3D &, unsigned); ~Endpoint3D(); - virtual void render(const Msp::GL::Tag &) const; + virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const; }; } // namespace R2C2 diff --git a/source/3d/layout.h b/source/3d/layout.h index c64386f..d1ec7c4 100644 --- a/source/3d/layout.h +++ b/source/3d/layout.h @@ -32,7 +32,7 @@ private: VehicleMap vehicles; Msp::GL::InstanceScene scene; Msp::GL::SimpleScene ep_scene; - Msp::GL::SimpleScene path_scene; + Msp::GL::InstanceScene path_scene; public: Layout3D(Layout &); diff --git a/source/3d/path.cpp b/source/3d/path.cpp index bd6b5b1..2e15210 100644 --- a/source/3d/path.cpp +++ b/source/3d/path.cpp @@ -6,6 +6,7 @@ Distributed under the GPL */ #include +#include #include "libr2c2/tracktype.h" #include "layout.h" #include "path.h" @@ -61,7 +62,12 @@ void Path3D::set_layer(float l) z_offs = l*track.get_track().get_layout().get_catalogue().get_gauge()*0.01; } -void Path3D::render(const GL::Tag &tag) const +long Path3D::get_instance_key() const +{ + return reinterpret_cast(&track.get_type()); +} + +void Path3D::render(GL::Renderer &renderer, const GL::Tag &tag) const { if(tag=="unlit") { @@ -70,15 +76,15 @@ void Path3D::render(const GL::Tag &tag) const if(!mask) return; - GL::MatrixStack::Push push_mtx(GL::MatrixStack::modelview()); + GL::MatrixStack::Push push_mtx(renderer.matrix_stack()); GL::Matrix matrix = track.get_matrix(); matrix.translate(0, 0, z_offs); - GL::MatrixStack::modelview() *= matrix; + renderer.matrix_stack() *= matrix; glColor4f(color.r, color.g, color.b, color.a); for(unsigned i=0; mask; ++i, mask>>=1) if(mask&1) - track.get_type().get_path_mesh(i).draw(); + track.get_type().get_path_mesh(i).draw(renderer); } } diff --git a/source/3d/path.h b/source/3d/path.h index cd6ad90..67b5258 100644 --- a/source/3d/path.h +++ b/source/3d/path.h @@ -35,7 +35,9 @@ public: void set_color(const Msp::GL::Color &); void set_layer(float); - virtual void render(const Msp::GL::Tag &) const; + virtual long get_instance_key() const; + + virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const; }; } // namespace R2C2 diff --git a/source/3d/track.cpp b/source/3d/track.cpp index f59e61c..5d31a4d 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -32,8 +32,16 @@ Track3D::Track3D(Layout3D &l, Track &t): layout.get_scene().add(*this); const vector &type_eps = track.get_type().get_endpoints(); + const vector &links = track.get_links(); for(unsigned i=0; i&track) + endpoints.push_back(new Endpoint3D(*this, i)); + else + endpoints.push_back(0); + } + + track.signal_link_changed.connect(sigc::mem_fun(this, &Track3D::link_changed)); } Track3D::~Track3D() @@ -107,4 +115,18 @@ void Track3D::finish_render(Msp::GL::Renderer &, const GL::Tag &) const glPopName(); } +void Track3D::link_changed(unsigned i, Track *trk) +{ + if(!trk || trk>&track) + { + if(!endpoints[i]) + endpoints[i] = new Endpoint3D(*this, i); + } + else if(endpoints[i]) + { + delete endpoints[i]; + endpoints[i] = 0; + } +} + } // namespace R2C2 diff --git a/source/3d/track.h b/source/3d/track.h index e1dd291..9555bff 100644 --- a/source/3d/track.h +++ b/source/3d/track.h @@ -9,6 +9,7 @@ Distributed under the GPL #define R2C2_3D_TRACK_H_ #include +#include #include #include #include "libr2c2/track.h" @@ -22,7 +23,7 @@ class Layout3D; class Path3D; class TrackType3D; -class Track3D: public Object3D, public Msp::GL::ObjectInstance +class Track3D: public Object3D, public Msp::GL::ObjectInstance, public sigc::trackable { private: Layout3D &layout; @@ -47,6 +48,8 @@ public: Msp::GL::Matrix get_matrix() const; virtual void setup_render(Msp::GL::Renderer &, const Msp::GL::Tag &) const; virtual void finish_render(Msp::GL::Renderer &, const Msp::GL::Tag &) const; +private: + void link_changed(unsigned, Track *); }; } // namespace R2C2 diff --git a/source/3d/tracktype.cpp b/source/3d/tracktype.cpp index d76e8eb..1196b32 100644 --- a/source/3d/tracktype.cpp +++ b/source/3d/tracktype.cpp @@ -105,6 +105,7 @@ TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt): build_part(*i, rail_profile, Point(gauge/2-rail_min.x, y), bld, index); } + mesh.set_winding(&GL::WindingTest::counterclockwise()); object.set_mesh(&mesh); object.set_technique(catalogue.get(cat.get_track_technique())); diff --git a/source/3d/vehicle.cpp b/source/3d/vehicle.cpp index ceded8b..78899fd 100644 --- a/source/3d/vehicle.cpp +++ b/source/3d/vehicle.cpp @@ -95,65 +95,6 @@ void Vehicle3D::render(GL::Renderer &renderer, const GL::Tag &tag) const return; ObjectInstance::render(renderer, tag); - - /*if(tag==0) - { - GL::PushMatrix push_mat; - - const Point &pos = vehicle.get_position(); - GL::translate(pos.x, pos.y, pos.z); - GL::rotate(vehicle.get_direction()*180/M_PI, 0, 0, 1); - - if(const GL::Object *obj = type.get_body_object()) - obj->render(tag);*/ - - /*const vector &axles = vehicle.get_type().get_axles(); - for(unsigned i=0; irender(tag); - } - - const vector &bogies = vehicle.get_type().get_bogies(); - for(unsigned i=0; irender(tag); - } - - if(bogies[i].rotate_object) - GL::rotate(180, 0, 0, 1); - if(const GL::Object *obj = type.get_bogie_object(i)) - obj->render(tag); - }*/ - - /*const vector &rods = vehicle.get_type().get_rods(); - for(unsigned i=0; irender(tag); - }*/ - //} } void Vehicle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 5974816..7d23042 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -95,8 +95,6 @@ Designer::Designer(int argc, char **argv): } // Setup OpenGL - GL::enable(GL_CULL_FACE); - pipeline = new GL::Pipeline(window.get_width(), window.get_height(), false); pipeline->set_camera(&camera); pipeline->add_renderable_for_pass(layout_3d->get_scene(), 0); @@ -540,7 +538,6 @@ void Designer::render() else { pipeline->render_all(); - GL::enable(GL_CULL_FACE); { GL::Bind bind_blend(GL::Blend::alpha()); overlay->render(0); @@ -557,8 +554,6 @@ void Designer::render() GL::matrix_mode(GL::MODELVIEW); GL::load_identity(); - GL::disable(GL::DEPTH_TEST); - GL::Bind bind_blend(GL::Blend::alpha()); root.render(); GL::Texture::unbind(); diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index b157b33..c6c1751 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -236,6 +236,9 @@ bool Track::snap_to(Track &other, bool link, float limit) links[i] = &other; other.links[j] = this; layout.create_blocks(*this); + + signal_link_changed.emit(i, &other); + other.signal_link_changed.emit(j, this); } return true; @@ -275,6 +278,7 @@ void Track::break_link(Track &trk) trk.break_link(*this); // XXX Creates the blocks twice layout.create_blocks(*this); + signal_link_changed.emit(i-links.begin(), 0); return; } } diff --git a/source/libr2c2/track.h b/source/libr2c2/track.h index 6747ed7..82365a5 100644 --- a/source/libr2c2/track.h +++ b/source/libr2c2/track.h @@ -33,6 +33,7 @@ public: void turnout_id(unsigned); }; + sigc::signal signal_link_changed; sigc::signal signal_path_changed; private: