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)
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);
}
}
}
VehicleType3D::VehicleType3D(Catalogue3D &, const VehicleType &vt):
body_object(0),
- bogie_objects(vt.get_bogies().size())
+ axle_objects(1)
{
body_object = get_object(vt.get_object());
- for(unsigned i=0; i<bogie_objects.size(); ++i)
- bogie_objects[i] = get_object(vt.get_bogies()[i].object);
+ const vector<VehicleType::Axle> &axles = vt.get_axles();
+ for(vector<VehicleType::Axle>::const_iterator i=axles.begin(); i!=axles.end(); ++i)
+ axle_objects[0].push_back(get_object(i->object));
+
+ const vector<VehicleType::Bogie> &bogies = vt.get_bogies();
+ for(vector<VehicleType::Bogie>::const_iterator i=bogies.begin(); i!=bogies.end(); ++i)
+ {
+ bogie_objects.push_back(get_object(i->object));
+ axle_objects.push_back(vector<GL::Object *>());
+ for(vector<VehicleType::Axle>::const_iterator j=i->axles.begin(); j!=i->axles.end(); ++j)
+ axle_objects.back().push_back(get_object(j->object));
+ }
}
VehicleType3D::~VehicleType3D()
delete i->second;
}
-const GL::Object *VehicleType3D::get_axle_object(unsigned) const
+const GL::Object *VehicleType3D::get_axle_object(unsigned i) const
{
- return 0;
+ if(i>=axle_objects[0].size())
+ throw InvalidParameterValue("Axle index out of range");
+ return axle_objects[0][i];
}
const GL::Object *VehicleType3D::get_bogie_object(unsigned i) const
return bogie_objects[i];
}
-const GL::Object *VehicleType3D::get_bogie_axle_object(unsigned, unsigned) const
+const GL::Object *VehicleType3D::get_bogie_axle_object(unsigned i, unsigned j) const
{
- return 0;
+ if(i>=bogie_objects.size())
+ throw InvalidParameterValue("Bogie index out of range");
+ if(j>=axle_objects[i+1].size())
+ throw InvalidParameterValue("Axle index out of range");
+ return axle_objects[i+1][j];
}
GL::Object *VehicleType3D::get_object(const string &name)
std::map<std::string, Msp::GL::Object *> objects;
Msp::GL::Object *body_object;
std::vector<Msp::GL::Object *> bogie_objects;
+ std::vector<std::vector<Msp::GL::Object *> > axle_objects;
public:
VehicleType3D(Catalogue3D &, const VehicleType &);
delete i->second;
}
+float Catalogue::get_rail_elevation() const
+{
+ return ballast_profile.get_height()+rail_profile.get_height();
+}
+
void Catalogue::add_track(TrackType &track)
{
if(tracks.count(track.get_article_number()))
float get_scale() const { return scale; }
float get_gauge() const { return gauge; }
+ float get_rail_elevation() const;
const Profile &get_rail_profile() const { return rail_profile; }
const Profile &get_ballast_profile() const { return ballast_profile; }
const Profile &get_path_profile() const { return path_profile; }
const Point &get_point(unsigned) const;
const Point &get_min_coords() const { return min_coords; }
const Point &get_max_coords() const { return max_coords; }
+ float get_width() const { return max_coords.x-min_coords.x; }
+ float get_height() const { return max_coords.y-min_coords.y; }
Point get_edge_normal(unsigned) const;
};
check_sensor(type.get_back_axle_offset(), back_sensor);
position = tp.pos;
+ position.z += layout.get_catalogue().get_rail_elevation();
direction = tp.dir;
}
VehicleType::Axle::Loader::Loader(Axle &a):
DataFile::ObjectLoader<Axle>(a)
{
+ add("object", &Axle::object);
add("position", &Loader::position);
add("powered", &Axle::powered);
add("wheel_diameter", &Loader::wheel_diameter);
float position;
float wheel_dia;
bool powered;
+ std::string object;
Axle();
};