From: Mikko Rasa Date: Sat, 9 Oct 2010 10:40:50 +0000 (+0000) Subject: Set correct Z coordinate to vehicle position X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=97443d96ff3ce51388d2edd1e0dca8f2cd231346;p=r2c2.git Set correct Z coordinate to vehicle position Render vehicle axles --- diff --git a/source/3d/vehicle.cpp b/source/3d/vehicle.cpp index 37619eb..7e4814b 100644 --- a/source/3d/vehicle.cpp +++ b/source/3d/vehicle.cpp @@ -52,11 +52,20 @@ void Vehicle3D::render(const GL::Tag &tag) const 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 &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); + + for(unsigned j=0; jrender(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); } } } diff --git a/source/3d/vehicletype.cpp b/source/3d/vehicletype.cpp index 91c1238..be6b985 100644 --- a/source/3d/vehicletype.cpp +++ b/source/3d/vehicletype.cpp @@ -17,12 +17,22 @@ namespace Marklin { 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 &axles = vt.get_axles(); + for(vector::const_iterator i=axles.begin(); i!=axles.end(); ++i) + axle_objects[0].push_back(get_object(i->object)); + + const vector &bogies = vt.get_bogies(); + for(vector::const_iterator i=bogies.begin(); i!=bogies.end(); ++i) + { + bogie_objects.push_back(get_object(i->object)); + axle_objects.push_back(vector()); + for(vector::const_iterator j=i->axles.begin(); j!=i->axles.end(); ++j) + axle_objects.back().push_back(get_object(j->object)); + } } VehicleType3D::~VehicleType3D() @@ -31,9 +41,11 @@ 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 @@ -43,9 +55,13 @@ 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) diff --git a/source/3d/vehicletype.h b/source/3d/vehicletype.h index c5c491a..faa34ac 100644 --- a/source/3d/vehicletype.h +++ b/source/3d/vehicletype.h @@ -22,6 +22,7 @@ private: std::map objects; Msp::GL::Object *body_object; std::vector bogie_objects; + std::vector > axle_objects; public: VehicleType3D(Catalogue3D &, const VehicleType &); diff --git a/source/libmarklin/catalogue.cpp b/source/libmarklin/catalogue.cpp index fca6045..beab69a 100644 --- a/source/libmarklin/catalogue.cpp +++ b/source/libmarklin/catalogue.cpp @@ -30,6 +30,11 @@ Catalogue::~Catalogue() 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())) diff --git a/source/libmarklin/catalogue.h b/source/libmarklin/catalogue.h index d529cfc..9a21c5e 100644 --- a/source/libmarklin/catalogue.h +++ b/source/libmarklin/catalogue.h @@ -54,6 +54,7 @@ public: 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; } diff --git a/source/libmarklin/profile.h b/source/libmarklin/profile.h index 92b2dfc..b1082e8 100644 --- a/source/libmarklin/profile.h +++ b/source/libmarklin/profile.h @@ -36,6 +36,8 @@ public: 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; }; diff --git a/source/libmarklin/vehicle.cpp b/source/libmarklin/vehicle.cpp index ac03de1..75afa4b 100644 --- a/source/libmarklin/vehicle.cpp +++ b/source/libmarklin/vehicle.cpp @@ -156,6 +156,7 @@ void Vehicle::update_position() check_sensor(type.get_back_axle_offset(), back_sensor); position = tp.pos; + position.z += layout.get_catalogue().get_rail_elevation(); direction = tp.dir; } diff --git a/source/libmarklin/vehicletype.cpp b/source/libmarklin/vehicletype.cpp index c206108..639415f 100644 --- a/source/libmarklin/vehicletype.cpp +++ b/source/libmarklin/vehicletype.cpp @@ -119,6 +119,7 @@ void VehicleType::Loader::width(float w) VehicleType::Axle::Loader::Loader(Axle &a): DataFile::ObjectLoader(a) { + add("object", &Axle::object); add("position", &Loader::position); add("powered", &Axle::powered); add("wheel_diameter", &Loader::wheel_diameter); diff --git a/source/libmarklin/vehicletype.h b/source/libmarklin/vehicletype.h index 082e3bc..9ef1c5e 100644 --- a/source/libmarklin/vehicletype.h +++ b/source/libmarklin/vehicletype.h @@ -42,6 +42,7 @@ public: float position; float wheel_dia; bool powered; + std::string object; Axle(); };