-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#include <cmath>
#include "catalogue.h"
#include "driver.h"
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());
void Vehicle::attach_back(Vehicle &veh)
{
if(next || veh.prev)
- throw InvalidState("Already attached");
+ throw attachment_error("already attached");
next = &veh;
veh.prev = this;
void Vehicle::attach_front(Vehicle &veh)
{
if(prev || veh.next)
- throw InvalidState("Already attached");
+ throw attachment_error("already attached");
prev = &veh;
veh.next = this;
void Vehicle::detach_back()
{
if(!next)
- throw InvalidState("Not attached");
+ throw attachment_error("not attached");
next->prev = 0;
next = 0;
void Vehicle::detach_front()
{
if(!prev)
- throw InvalidState("Not attached");
+ throw attachment_error("not attached");
prev->next = 0;
prev = 0;
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];
}
float margin = layout.get_catalogue().get_scale();
float dist = distance(veh.position, position);
- if(dist<tdist-margin || dist>tdist+margin)
+ if(!track_pos.track || dist<tdist-margin || dist>tdist+margin)
{
track_pos = veh.track_pos;
track_pos.advance(sign*tdist);
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)
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;
}
}
-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;