X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fvehicle.cpp;h=1699fd8eeef1cf0b89618cb806d3c6623aabc07b;hb=64340dad429ba4040538fc06b6882aabdb489925;hp=3fdc7a44c7a2722b7afa763dbf87aea182062a8f;hpb=4b7008978ce5b67e7e1db14b4a359e4ab1881bbd;p=r2c2.git diff --git a/source/libr2c2/vehicle.cpp b/source/libr2c2/vehicle.cpp index 3fdc7a4..1699fd8 100644 --- a/source/libr2c2/vehicle.cpp +++ b/source/libr2c2/vehicle.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #include "catalogue.h" #include "driver.h" @@ -29,7 +22,7 @@ Vehicle::Vehicle(Layout &l, const VehicleType &t): front_sensor(0), back_sensor(0) { - axles.assign(type.get_axles().begin(), type.get_axles().end()); + axles.assign(type.get_fixed_axles().begin(), type.get_fixed_axles().end()); bogies.assign(type.get_bogies().begin(), type.get_bogies().end()); rods.assign(type.get_rods().begin(), type.get_rods().end()); @@ -48,7 +41,7 @@ Vehicle::~Vehicle() void Vehicle::attach_back(Vehicle &veh) { if(next || veh.prev) - throw InvalidState("Already attached"); + throw attachment_error("already attached"); next = &veh; veh.prev = this; @@ -60,7 +53,7 @@ void Vehicle::attach_back(Vehicle &veh) void Vehicle::attach_front(Vehicle &veh) { if(prev || veh.next) - throw InvalidState("Already attached"); + throw attachment_error("already attached"); prev = &veh; veh.next = this; @@ -72,7 +65,7 @@ void Vehicle::attach_front(Vehicle &veh) void Vehicle::detach_back() { if(!next) - throw InvalidState("Not attached"); + throw attachment_error("not attached"); next->prev = 0; next = 0; @@ -81,7 +74,7 @@ void Vehicle::detach_back() void Vehicle::detach_front() { if(!prev) - throw InvalidState("Not attached"); + throw attachment_error("not attached"); prev->next = 0; prev = 0; @@ -125,33 +118,33 @@ void Vehicle::advance(float d) propagate_position(); } -const Vehicle::Bogie &Vehicle::get_bogie(unsigned i) const +const Vehicle::Axle &Vehicle::get_fixed_axle(unsigned i) const { - if(i>=bogies.size()) - throw InvalidParameterValue("Bogie index out of range"); - return bogies[i]; + if(i>=axles.size()) + throw out_of_range("Vehicle::get_fixed_axle"); + return axles[i]; } -const Vehicle::Axle &Vehicle::get_axle(unsigned i) const +const Vehicle::Bogie &Vehicle::get_bogie(unsigned i) const { - if(i>=axles.size()) - throw InvalidParameterValue("Axle index out of range"); - return axles[i]; + if(i>=bogies.size()) + throw out_of_range("Vehicle::get_bogie"); + return bogies[i]; } const Vehicle::Axle &Vehicle::get_bogie_axle(unsigned i, unsigned j) const { if(i>=bogies.size()) - throw InvalidParameterValue("Bogie index out of range"); + throw out_of_range("Vehicle::get_bogie_axle"); if(j>=bogies[i].axles.size()) - throw InvalidParameterValue("Axle index out of range"); + throw out_of_range("Vehicle::get_bogie_axle"); return bogies[i].axles[j]; } const Vehicle::Rod &Vehicle::get_rod(unsigned i) const { if(i>=rods.size()) - throw InvalidParameterValue("Rod index out of range"); + throw out_of_range("Vehicle::get_rod"); return rods[i]; } @@ -290,20 +283,20 @@ void Vehicle::update_rods() i->position = i->type->pivot_point; else if(i->type->pivot==VehicleType::Rod::AXLE) { - const Axle &axle = get_axle(i->type->pivot_index); + const Axle &axle = get_fixed_axle(i->type->pivot_index); float c = cos(axle.angle); float s = sin(axle.angle); - const Point &pp = i->type->pivot_point; - i->position = Point(axle.type->position+pp.x*c+pp.z*s, pp.y, axle.type->wheel_dia/2+pp.z*c-pp.x*s); + const Vector &pp = i->type->pivot_point; + i->position = Vector(axle.type->position+pp.x*c+pp.z*s, pp.y, axle.type->wheel_dia/2+pp.z*c-pp.x*s); } else if(i->type->pivot==VehicleType::Rod::ROD) { const Rod &prod = get_rod(i->type->pivot_index); float c = cos(prod.angle); float s = sin(prod.angle); - const Point &pos = prod.position; - const Point &off = i->type->pivot_point; - i->position = Point(pos.x+off.x*c-off.z*s, pos.y+off.y, pos.z+off.z*c+off.x*s); + const Vector &pos = prod.position; + const Vector &off = i->type->pivot_point; + i->position = Vector(pos.x+off.x*c-off.z*s, pos.y+off.y, pos.z+off.z*c+off.x*s); } if(i->type->connect_index>=0) @@ -346,8 +339,8 @@ void Vehicle::adjust_for_distance(TrackPosition &front, TrackPosition &back, flo int adjust_dir = 0; while(1) { - Point front_point = front.get_point().pos; - Point back_point = back.get_point().pos; + Vector front_point = front.get_point().pos; + Vector back_point = back.get_point().pos; float dx = front_point.x-back_point.x; float dy = front_point.y-back_point.y; @@ -373,14 +366,14 @@ void Vehicle::adjust_for_distance(TrackPosition &front, TrackPosition &back, flo } } -TrackPoint Vehicle::get_point(const Point &front, const Point &back, float ratio) const +TrackPoint Vehicle::get_point(const Vector &front, const Vector &back, float ratio) const { float dx = front.x-back.x; float dy = front.y-back.y; float dz = front.z-back.z; TrackPoint tp; - tp.pos = Point(back.x+dx*ratio, back.y+dy*ratio, back.z+dz*ratio); + tp.pos = Vector(back.x+dx*ratio, back.y+dy*ratio, back.z+dz*ratio); tp.dir = atan2(dy, dx); return tp;