X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fvehicleplacement.cpp;h=273a9cc32e43091396bb04ab5b7ee3cf2e1a84f5;hb=d6213fa0f35a06182a7d3e88959c67ff019713b6;hp=9f9001fb0b7562c073b5c99634d5b98793d40a93;hpb=18c529dfdd34e07f4f6021151ddce29fa85437bc;p=r2c2.git diff --git a/source/libr2c2/vehicleplacement.cpp b/source/libr2c2/vehicleplacement.cpp index 9f9001f..273a9cc 100644 --- a/source/libr2c2/vehicleplacement.cpp +++ b/source/libr2c2/vehicleplacement.cpp @@ -51,6 +51,9 @@ VehiclePlacement::VehiclePlacement(const VehicleType &t): void VehiclePlacement::place(const TrackOffsetIter &p, Anchor a) { + if(!p) + return unplace(); + float anchor = get_anchor_position(a); for(vector::iterator i=axles.begin(); i!=axles.end(); ++i) @@ -178,7 +181,7 @@ OrientedPoint VehiclePlacement::create_point(const Vector &front, const Vector & OrientedPoint result; result.position = front*(1-ratio)+back*ratio; result.rotation = Geometry::atan2(front.y-back.y, front.x-back.x); - result.tilt = Geometry::atan2(front.z-back.z, LinAl::Vector(front-back).norm()); + result.tilt = Geometry::atan2(front.z-back.z, (front-back).slice<2>(0).norm()); return result; } @@ -246,9 +249,9 @@ float VehiclePlacement::compute_adjustment(const Vector &p1, const Vector &p2, f float span = distance(p1, p2); float adjust = target-span; - /* If the adjustment is larger than the last one, we've hit a gap or + /* If the adjustment is not smaller than the last one, we've hit a gap or other oddity in the track. Terminate to avoid an infinite loop. */ - if(last>0 && abs(adjust)>last) + if(last>0 && abs(adjust)>=last) return 0; if(abs(adjust)*10000