]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/vehicle.cpp
Fix a stupid comparison mistake in Route
[r2c2.git] / source / 3d / vehicle.cpp
index 41bb26259da3b2a769c7a93e427acfb76ab1fe0b..f14f3c2c238df933943cc938fabffdf6231241f2 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$
 
-This file is part of the MSP Märklin suite
+This file is part of R²C²
 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
@@ -14,7 +14,7 @@ Distributed under the GPL
 using namespace std;
 using namespace Msp;
 
-namespace Marklin {
+namespace R2C2 {
 
 Vehicle3D::Vehicle3D(Layout3D &l, Vehicle &v):
        layout(l),
@@ -37,18 +37,35 @@ Point Vehicle3D::get_node() const
        return Point(p.x, p.y, p.z+0.01+vehicle.get_type().get_height());
 }
 
+bool Vehicle3D::is_visible() const
+{
+       return vehicle.get_track();
+}
+
 void Vehicle3D::render(const GL::Tag &tag) const
 {
+       if(!vehicle.get_track())
+               return;
+
        if(tag==0)
        {
                GL::PushMatrix push_mat;
 
                const Point &pos = vehicle.get_position();
-               GL::translate(pos.x, pos.y, pos.z+0.01);
+               GL::translate(pos.x, pos.y, pos.z);
                GL::rotate(vehicle.get_direction()*180/M_PI, 0, 0, 1);
 
-               if(type.get_body_object())
-                       type.get_body_object()->render(tag);
+               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);
+                               obj->render(tag);
+                       }
 
                const vector<VehicleType::Bogie> &bogies = vehicle.get_type().get_bogies();
                for(unsigned i=0; i<bogies.size(); ++i)
@@ -56,13 +73,22 @@ void Vehicle3D::render(const GL::Tag &tag) const
                        GL::PushMatrix push_mat2;
                        GL::translate(bogies[i].position, 0, 0);
                        float angle = vehicle.get_bogie_direction(i)*180/M_PI;
-                       if(bogies[i].rotate_object)
-                               angle += 180;
                        GL::rotate(angle, 0, 0, 1);
-                       if(type.get_bogie_object(i))
-                               type.get_bogie_object(i)->render(tag);
+
+                       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);
+                                       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);
                }
        }
 }
 
-} // namespace Marklin
+} // namespace R2C2