X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Fvehicletype.cpp;h=34f2be630a9bc587680aaf2b4691888b6941eaf0;hb=a7ccbae5d5efd647a7f0c84f7e665e28c2892336;hp=2ddd34db08cc4515753f1eeb3171acee973e57d2;hpb=37af7970d9cefcf40ae58ca06ca8469f56b0cc13;p=r2c2.git diff --git a/source/3d/vehicletype.cpp b/source/3d/vehicletype.cpp index 2ddd34d..34f2be6 100644 --- a/source/3d/vehicletype.cpp +++ b/source/3d/vehicletype.cpp @@ -1,10 +1,4 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - +#include #include #include #include @@ -31,26 +25,20 @@ T get(const map ¶ms, const string &key, T def = T()) namespace R2C2 { -VehicleType3D::VehicleType3D(const Catalogue3D &c, const VehicleType &t): - catalogue(c), +VehicleType3D::VehicleType3D(Catalogue3D &c, const VehicleType &t): + ObjectType3D(c), type(t), - body_object(0), - axle_objects(1) + body_object(0) { body_object = get_object(type.get_object()); const vector &axles = type.get_axles(); for(vector::const_iterator i=axles.begin(); i!=axles.end(); ++i) - axle_objects[0].push_back(get_object(i->object)); + axle_objects.push_back(get_object(i->object)); const vector &bogies = type.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)); - } const vector &rods = type.get_rods(); for(vector::const_iterator i=rods.begin(); i!=rods.end(); ++i) @@ -65,31 +53,22 @@ VehicleType3D::~VehicleType3D() const GL::Object *VehicleType3D::get_axle_object(unsigned i) const { - if(i>=axle_objects[0].size()) - throw InvalidParameterValue("Axle index out of range"); - return axle_objects[0][i]; + if(i>=axle_objects.size()) + throw out_of_range("VehicleType3D::get_fixed_axle_object"); + return axle_objects[i]; } const GL::Object *VehicleType3D::get_bogie_object(unsigned i) const { if(i>=bogie_objects.size()) - throw InvalidParameterValue("Bogie index out of range"); + throw out_of_range("VehicleType3D::get_bogie_object"); return bogie_objects[i]; } -const GL::Object *VehicleType3D::get_bogie_axle_object(unsigned i, unsigned j) const -{ - 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]; -} - const GL::Object *VehicleType3D::get_rod_object(unsigned i) const { if(i>=rod_objects.size()) - throw InvalidParameterValue("Rod index out of range"); + throw out_of_range("VehicleType3D::get_rod_object"); return rod_objects[i]; } @@ -107,9 +86,9 @@ GL::Object *VehicleType3D::get_object(const string &name) string kind = name.substr(1, colon-1); map params; - params["length"] = lexical_cast(type.get_length()*1000); - params["width"] = lexical_cast(type.get_width()*1000); - params["height"] = lexical_cast(type.get_height()*1000); + params["length"] = lexical_cast(type.get_length()*1000); + params["width"] = lexical_cast(type.get_width()*1000); + params["height"] = lexical_cast(type.get_height()*1000); if(colon!=string::npos) { string::size_type start = colon+1; @@ -144,10 +123,7 @@ GL::Object *VehicleType3D::get_object(const string &name) } } else - { - ptr = new GL::Object; - DataFile::load(*ptr, name); - } + return &catalogue.get(name); } return ptr; } @@ -168,7 +144,9 @@ GL::Technique *VehicleType3D::create_technique(const map ¶ms tex->storage(GL::RGB, 2, 1); tex->set_min_filter(GL::NEAREST); tex->set_mag_filter(GL::NEAREST); - unsigned char data[6] = { color>>16, color>>8, color, color2>>16, color2>>8, color2 }; + unsigned char data[6]; + data[0] = color>>16; data[1] = color>>8; data[2] = color; + data[3] = color2>>16; data[4] = color2>>8; data[5] = color2; tex->image(0, GL::RGB, GL::UNSIGNED_BYTE, data); pass.set_texture(0, tex);