From 0475ca7507c793b3f1046f5877265a938341a132 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 8 Sep 2012 15:22:19 +0100 Subject: [PATCH] Rename tank engine model --- engines/{pclass/pclass.mtl => tank/tank.mtl} | 0 engines/{pclass/pclass.obj => tank/tank.obj} | 2 +- .../{pclass/pclass.wings => tank/tank.wings} | Bin engines/{pclass/pclass.xml => tank/tank.xml} | 4 +- include/ITrain.hpp | 2 +- src/Engine.cpp | 34 ++++----- src/Train.cpp | 68 +++++++++--------- 7 files changed, 53 insertions(+), 57 deletions(-) rename engines/{pclass/pclass.mtl => tank/tank.mtl} (100%) rename engines/{pclass/pclass.obj => tank/tank.obj} (97%) rename engines/{pclass/pclass.wings => tank/tank.wings} (100%) rename engines/{pclass/pclass.xml => tank/tank.xml} (50%) diff --git a/engines/pclass/pclass.mtl b/engines/tank/tank.mtl similarity index 100% rename from engines/pclass/pclass.mtl rename to engines/tank/tank.mtl diff --git a/engines/pclass/pclass.obj b/engines/tank/tank.obj similarity index 97% rename from engines/pclass/pclass.obj rename to engines/tank/tank.obj index 64510a9..6d4232c 100644 --- a/engines/pclass/pclass.obj +++ b/engines/tank/tank.obj @@ -1,5 +1,5 @@ # Exported from Wings 3D 1.2 -mtllib pclass.mtl +mtllib tank.mtl o right bar #8 vertices, 12 faces v -1.05139919 0.34160749 0.69743006 diff --git a/engines/pclass/pclass.wings b/engines/tank/tank.wings similarity index 100% rename from engines/pclass/pclass.wings rename to engines/tank/tank.wings diff --git a/engines/pclass/pclass.xml b/engines/tank/tank.xml similarity index 50% rename from engines/pclass/pclass.xml rename to engines/tank/tank.xml index 9552b46..760eae3 100644 --- a/engines/pclass/pclass.xml +++ b/engines/tank/tank.xml @@ -1,5 +1,5 @@ - SECR P Class - pclass.obj + Tank Engine + tank.obj diff --git a/include/ITrain.hpp b/include/ITrain.hpp index 53a8386..3441197 100644 --- a/include/ITrain.hpp +++ b/include/ITrain.hpp @@ -32,7 +32,7 @@ struct ITrain { // Return a vector of the absolute position of the front of // the train - virtual Vector front() const = 0; + virtual VectorF front() const = 0; // Return the track segment occupied by the front of the train virtual ITrackSegmentPtr track_segment() const = 0; diff --git a/src/Engine.cpp b/src/Engine.cpp index 44847bf..53cb784 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -24,10 +24,6 @@ #include -// -// READ THIS FIRST: physics model used by the steam engine -// -// Note: everything here uses SI units unless otherwise stated // // The "tractive effort" is a measure of the power of a steam engine // at a given velocity: P(v). Note: the value usually quoted on the @@ -65,13 +61,13 @@ public: // IRollingStock interface void render() const; void update(int delta, double gravity); - + double speed() const { return my_speed; } double mass() const { return my_mass; } IControllerPtr controller() { return shared_from_this(); } float length() const { return model->dimensions().x; } ICargoPtr cargo() const; - + // IController interface void act_on(Action an_action); int throttle() const { return my_throttle; } @@ -87,7 +83,7 @@ private: double tractive_effort() const; double resistance() const; double brake_force() const; - + IModelPtr model; double my_speed, my_mass, my_boiler_pressure, my_fire_temp; @@ -101,7 +97,7 @@ private: MovingAverage my_boiler_delay; IResourcePtr resource; - + static const float MODEL_SCALE; static const double TRACTIVE_EFFORT_KNEE; @@ -142,7 +138,7 @@ void Engine::text(const string& local_name, const string& a_string) // Draw the engine model void Engine::render() const -{ +{ model->render(); } @@ -150,7 +146,7 @@ void Engine::render() const double Engine::tractive_effort() const { const double dir = reverse ? -1.0 : 1.0; - + if (abs(my_speed) < TRACTIVE_EFFORT_KNEE) return stat_tractive_effort * dir; else @@ -163,13 +159,13 @@ double Engine::tractive_effort() const double Engine::resistance() const { const double sign = my_speed < 0.0 ? -1.0 : 1.0; - + const double a = 4.0; const double b = 0.05; const double c = 0.006; const double abs_speed = abs(my_speed); - + return sign * (a + b*abs_speed + c*abs_speed*abs_speed); } @@ -188,7 +184,7 @@ double Engine::brake_force() const if (abs(my_speed) < STOP_SPEED) return 0.0; - else + else return my_mass * g * beta * dir; } @@ -199,12 +195,12 @@ void Engine::update(int delta, double gravity) // The fire temperature is delayed and then used to increase it my_boiler_delay << my_fire_temp; my_boiler_pressure = my_boiler_delay.value(); - + const double P = tractive_effort(); const double Q = resistance(); const double B = is_brake_on ? brake_force() : 0.0; - const double G = gravity; - + const double G = gravity; + // The applied tractive effort is controlled by the throttle const double netP = P * static_cast(my_throttle) / 10.0; @@ -218,9 +214,9 @@ void Engine::update(int delta, double gravity) } else have_stopped = false; - + my_speed += a; - + #if 0 debug() << "P=" << netP << ", Q=" << Q << ", B=" << B @@ -262,7 +258,7 @@ void Engine::act_on(Action an_action) static Engine* load_engine_xml(IResourcePtr a_res) { log() << "Loading engine from " << a_res->xml_file_name(); - + return new Engine(a_res); } diff --git a/src/Train.cpp b/src/Train.cpp index 1d8d7f0..514b035 100644 --- a/src/Train.cpp +++ b/src/Train.cpp @@ -1,5 +1,5 @@ // -// Copyright (C) 2009-2010 Nick Gasson +// Copyright (C) 2009-2012 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,13 +20,13 @@ #include "ILogger.hpp" #include "TrackCommon.hpp" #include "ISmokeTrail.hpp" +#include "OpenGLHelper.hpp" #include #include #include #include -#include #include // Concrete implementation of trains @@ -37,20 +37,20 @@ public: // ITrain interface void render() const; void update(int a_delta); - Vector front() const; + VectorF front() const; ITrackSegmentPtr track_segment() const; track::Direction direction() const; track::Position tile() const { return engine().travel_token.position; } double speed() const { return parts.front().vehicle->speed(); } IControllerPtr controller() { return parts.front().vehicle->controller(); } - + private: // The different parts of the train are on different track segments struct Part : boost::equality_comparable { explicit Part(IRollingStockPtr a_vehicle) : vehicle(a_vehicle), segment_delta(0.0), movement_sign(1.0) {} - + IRollingStockPtr vehicle; // The length of a track segment can be found by calling @@ -59,7 +59,7 @@ private: ITrackSegmentPtr segment; float segment_delta; track::TravelToken travel_token; - + // Direction train part is travelling along the track Vector direction; @@ -77,21 +77,21 @@ private: Part& engine(); void move(double a_distance); void add_part(IRollingStockPtr a_vehicle); - Vector part_position(const Part& a_part) const; + VectorF part_position(const Part& a_part) const; void update_smoke_position(int a_delta); void move_part(Part& part, double distance); static track::Connection reverse_token(const track::TravelToken& token); static void transform_to_part(const Part& p); - + IMapPtr map; ISmokeTrailPtr smoke_trail; - - Vector velocity_vector; + + VectorF velocity_vector; // Move part of the train across a connection void enter_segment(Part& a_part, const track::Connection& a_connection); - + // Seperation between waggons static const double SEPARATION; }; @@ -101,8 +101,8 @@ const double Train::SEPARATION(0.15); Train::Train(IMapPtr a_map) : map(a_map), velocity_vector(make_vector(0.0f, 0.0f, 0.0f)) { - parts.push_front(Part(load_engine("pclass"))); - + parts.push_front(Part(load_engine("tank"))); + enter_segment(engine(), a_map->start()); // Bit of a hack to put the engine in the right place @@ -120,10 +120,10 @@ void Train::add_part(IRollingStockPtr a_vehicle) { Part part(a_vehicle); enter_segment(part, map->start()); - + // Push the rest of the train along some move(part.vehicle->length() + SEPARATION); - + parts.push_back(part); } @@ -145,13 +145,13 @@ void Train::move_part(Part& part, double distance) double d = abs(distance); double sign = (distance >= 0.0 ? 1.0 : -1.0) * part.movement_sign; const double step = 0.25; - + //debug() << "move d=" << distance << " s=" << sign // << " ms=" << part.movement_sign; - + do { part.segment_delta += min(step, d) * sign; - + const double segment_length = part.segment->segment_length(part.travel_token); if (part.segment_delta >= segment_length) { @@ -166,7 +166,7 @@ void Train::move_part(Part& part, double distance) part.segment_delta *= -1.0; part.movement_sign *= -1.0; } - + d -= step; } while (d > 0.0); } @@ -175,7 +175,7 @@ void Train::move_part(Part& part, double distance) void Train::move(double a_distance) { using namespace placeholders; - + for (list::iterator it = parts.begin(); it != parts.end(); ++it) move_part(*it, a_distance); @@ -192,7 +192,7 @@ void Train::update_smoke_position(int a_delta) const float smoke_offX = 0.63f; const float smoke_offY = 1.04f; glTranslatef(smoke_offX, smoke_offY, 0.0f); - + float matrix[16]; glGetFloatv(GL_MODELVIEW_MATRIX, matrix); @@ -234,12 +234,12 @@ void Train::update(int delta) (*it).vehicle->update(delta, gravity_sum); update_smoke_position(delta); - + // How many metres does a tile correspond to? const double M_PER_UNIT = 5.0; - const Vector old_pos = part_position(engine()); - + const VectorF old_pos = part_position(engine()); + const double delta_seconds = static_cast(delta) / 1000.0f; move(engine().vehicle->speed() * delta_seconds / M_PER_UNIT); @@ -250,7 +250,7 @@ void Train::update(int delta) // Resets the delta and gets the length of the new segment void Train::enter_segment(Part& a_part, const track::Connection& a_connection) { - Point pos; + PointI pos; tie(pos, a_part.direction) = a_connection; #if 0 @@ -269,7 +269,7 @@ void Train::enter_segment(Part& a_part, const track::Connection& a_connection) void Train::transform_to_part(const Part& p) { p.travel_token.transform(p.segment_delta); - + // If we're going backwards, flip the train around if (p.movement_sign < 0.0) glRotatef(180.0f, 0.0f, 1.0f, 0.0f); @@ -280,12 +280,12 @@ void Train::render() const for (list::const_iterator it = parts.begin(); it != parts.end(); ++it) { glPushMatrix(); - + transform_to_part(*it); glTranslatef(0.0f, track::RAIL_HEIGHT, 0.0f); - + (*it).vehicle->render(); - + glPopMatrix(); } @@ -297,7 +297,7 @@ ITrackSegmentPtr Train::track_segment() const return engine().segment; } -Vector Train::front() const +VectorF Train::front() const { return part_position(engine()); } @@ -308,17 +308,17 @@ track::Direction Train::direction() const } // Calculate the position of any train part -Vector Train::part_position(const Part& a_part) const +VectorF Train::part_position(const Part& a_part) const { // Call the transformer to compute the world location glPushMatrix(); glLoadIdentity(); - + a_part.travel_token.transform(a_part.segment_delta); float matrix[16]; glGetFloatv(GL_MODELVIEW_MATRIX, matrix); - + glPopMatrix(); return make_vector(matrix[12], matrix[13], matrix[14]); @@ -334,7 +334,7 @@ track::Connection Train::reverse_token(const track::TravelToken& token) track::Direction dir = -token.direction; - return make_pair(pos, dir); + return make_pair(pos, dir); } // Make an empty train -- 2.39.2