]> git.tdb.fi Git - r2c2.git/commitdiff
Enable Renderer for Endpoint3D and Path3D
authorMikko Rasa <tdb@tdb.fi>
Fri, 14 Jan 2011 13:12:58 +0000 (13:12 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 14 Jan 2011 13:12:58 +0000 (13:12 +0000)
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

12 files changed:
source/3d/endpoint.cpp
source/3d/endpoint.h
source/3d/layout.h
source/3d/path.cpp
source/3d/path.h
source/3d/track.cpp
source/3d/track.h
source/3d/tracktype.cpp
source/3d/vehicle.cpp
source/designer/designer.cpp
source/libr2c2/track.cpp
source/libr2c2/track.h

index 7e33ced696d92cc2abb3da7b54ddfbcaa0606ed6..440d3f7d7e8a0362fabee8f1673bd12f1662fcc3 100644 (file)
@@ -8,6 +8,7 @@ Distributed under the GPL
 #include <cmath>
 #include <msp/gl/matrix.h>
 #include <msp/gl/misc.h>
+#include <msp/gl/renderer.h>
 #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);
        }
 }
 
index e4071278d1f9efa817801a9b8003695772234008..03955cd17fc39f5c8132def723ec69fa8b898a8f 100644 (file)
@@ -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
index c64386fcc1ca91e57f6a6f7d0478c3bdb37c70dc..d1ec7c49f457b472b52adc1359f776ac8a156423 100644 (file)
@@ -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 &);
index bd6b5b18715eb68d596d084f1d1c3daa37323cd8..2e1521087da8e36ab10121ea512834d35fd23740 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the GPL
 */
 
 #include <msp/gl/matrix.h>
+#include <msp/gl/renderer.h>
 #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<long>(&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);
        }
 }
 
index cd6ad90b8cb996643d15240d39c9e34a74e1ef4a..67b525839d23b43f0adaff946409154c794e22fe 100644 (file)
@@ -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
index f59e61c236926dab6669849b061192ef556488f5..5d31a4de93294f1c2ec46b815ad804aa09767c3b 100644 (file)
@@ -32,8 +32,16 @@ Track3D::Track3D(Layout3D &l, Track &t):
        layout.get_scene().add(*this);
 
        const vector<TrackType::Endpoint> &type_eps = track.get_type().get_endpoints();
+       const vector<Track *> &links = track.get_links();
        for(unsigned i=0; i<type_eps.size(); ++i)
-               endpoints.push_back(new Endpoint3D(*this, i));
+       {
+               if(!links[i] || links[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
index e1dd29196e3146b36462c7a9bd271d135bb0572f..9555bff7a67083edb30f991cdbcdd7e8d46eb549 100644 (file)
@@ -9,6 +9,7 @@ Distributed under the GPL
 #define R2C2_3D_TRACK_H_
 
 #include <list>
+#include <sigc++/trackable.h>
 #include <msp/gl/matrix.h>
 #include <msp/gl/objectinstance.h>
 #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
index d76e8ebe6bfcb136b54c965ce593abf9bba01cfe..1196b32ce18b7eb161f87e4c64487fcf45207378 100644 (file)
@@ -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<GL::Technique>(cat.get_track_technique()));
  
index ceded8bc04c8012af255f399763ada36074270cb..78899fd371d07a25f3f8046c7411974daedcf179 100644 (file)
@@ -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<VehicleType::Axle> &axles = vehicle.get_type().get_axles();
-               for(unsigned i=0; i<axles.size(); ++i)
-                       if(const GL::Object *obj = type.get_axle_object(i))
-                       {
-                               GL::PushMatrix push_mat2;
-                               GL::translate(axles[i].position, 0, axles[i].wheel_dia/2);
-                               GL::rotate(vehicle.get_axle(i).angle*180/M_PI, 0, 1, 0);
-                               obj->render(tag);
-                       }
-
-               const vector<VehicleType::Bogie> &bogies = vehicle.get_type().get_bogies();
-               for(unsigned i=0; i<bogies.size(); ++i)
-               {
-                       GL::PushMatrix push_mat2;
-                       GL::translate(bogies[i].position, 0, 0);
-                       float angle = vehicle.get_bogie(i).direction*180/M_PI;
-                       GL::rotate(angle, 0, 0, 1);
-
-                       for(unsigned j=0; j<bogies[i].axles.size(); ++j)
-                               if(const GL::Object *obj = type.get_bogie_axle_object(i, j))
-                               {
-                                       GL::PushMatrix push_mat3;
-                                       GL::translate(bogies[i].axles[j].position, 0, bogies[i].axles[j].wheel_dia/2);
-                                       GL::rotate(vehicle.get_bogie_axle(i, j).angle*180/M_PI, 0, 1, 0);
-                                       obj->render(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<VehicleType::Rod> &rods = vehicle.get_type().get_rods();
-               for(unsigned i=0; i<rods.size(); ++i)
-                       if(const GL::Object *obj = type.get_rod_object(i))
-                       {
-                               GL::PushMatrix push_mat2;
-                               const Point &rpos = vehicle.get_rod(i).position;
-                               float angle = vehicle.get_rod(i).angle;
-                               GL::translate(rpos.x, rpos.y, rpos.z);
-                               if(rods[i].mirror_object)
-                                       GL::scale(1, -1, 1);
-                               GL::rotate(angle*180/M_PI, 0, -1, 0);
-                               obj->render(tag);
-                       }*/
-       //}
 }
 
 void Vehicle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
index 5974816c65c1e2f4cff15df134d0e9f36c2f3e67..7d230429262fd24da9a93da33cbf77dc77e6d2d5 100644 (file)
@@ -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();
index b157b331a12dc9a8106f1720aceeecaddc549e02..c6c1751d7b2388cdadeb78e9824a1fcb6fb544b5 100644 (file)
@@ -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;
                }
 }
index 6747ed7f082281865a2ac31551c3978b86d9b416..82365a5ab02127ed5a0742e567bae153bf546cbd 100644 (file)
@@ -33,6 +33,7 @@ public:
                void turnout_id(unsigned);
        };
 
+       sigc::signal<void, unsigned, Track *> signal_link_changed;
        sigc::signal<void, unsigned> signal_path_changed;
 
 private: