/* $Id$
This file is part of R²C²
-Copyright © 2010 Mikkosoft Productions, Mikko Rasa
+Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
front_sensor(0),
back_sensor(0)
{
- layout.add_vehicle(*this);
-
- 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());
+
+ layout.add_vehicle(*this);
}
Vehicle::~Vehicle()
propagate_position();
}
+const Vehicle::Axle &Vehicle::get_fixed_axle(unsigned i) const
+{
+ if(i>=axles.size())
+ throw InvalidParameterValue("Axle index out of range");
+ return axles[i];
+}
+
const Vehicle::Bogie &Vehicle::get_bogie(unsigned i) const
{
if(i>=bogies.size())
return bogies[i];
}
-const Vehicle::Axle &Vehicle::get_axle(unsigned i) const
-{
- if(i>=axles.size())
- throw InvalidParameterValue("Axle index out of range");
- return axles[i];
-}
-
const Vehicle::Axle &Vehicle::get_bogie_axle(unsigned i, unsigned j) const
{
if(i>=bogies.size())
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;