]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/vehicle.cpp
Strip Id tags and copyright notices from files
[r2c2.git] / source / libr2c2 / vehicle.cpp
index 3fdc7a44c7a2722b7afa763dbf87aea182062a8f..6b89fa8743b604036ccab17c7a42a48e94e8c208 100644 (file)
@@ -1,10 +1,3 @@
-/* $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"
@@ -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());
 
@@ -125,6 +118,13 @@ void Vehicle::advance(float d)
        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())
@@ -132,13 +132,6 @@ const Vehicle::Bogie &Vehicle::get_bogie(unsigned i) const
        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())
@@ -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;