1 // World.h - handles interactions between a car and its environment. 2 // 3 // Vamos Automotive Simulator 4 // Copyright (C) 2001--2004 Sam Varner 5 // 6 // This program is free software; you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation; either version 2 of the License, or 9 // (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 20 #ifndef _WORLD_H_ 21 #define _WORLD_H_ 22 23 #include "../body/Car.h" 24 #include "../geometry/Circular_Buffer.h" 25 #include "../geometry/Material.h" 26 #include "../geometry/Three_Vector.h" 27 #include "../track/Strip_Track.h" 28 #include "../track/Road_Segment.h" 29 #include "Atmosphere.h" 30 #include "Timing_Info.h" 31 32 #include <vector> 33 34 namespace Vamos_World 35 { 36 class Driver; 37 38 struct Car_Information 39 { 40 Car_Information (Vamos_Body::Car* car_in, Driver* driver_in); 41 42 size_t road_index; 43 size_t segment_index; 44 Vamos_Body::Car* car; 45 Driver* driver; 46 47 void reset (); 48 void propagate (double time_step, 49 double total_time, 50 const Vamos_Geometry::Three_Vector& track_position); 51 52 struct Record 53 { RecordCar_Information::Record54 Record () {}; 55 Record (double time, 56 Vamos_Body::Car* car, 57 const Vamos_Geometry::Three_Vector& track_position); 58 59 double m_time; 60 Vamos_Geometry::Three_Vector m_track_position; 61 Vamos_Geometry::Three_Vector m_position; 62 Vamos_Geometry::Three_Matrix m_orientation; 63 }; 64 65 Vamos_Geometry::Circular_Buffer <Record> m_record; 66 }; 67 68 struct Interaction_Info 69 { 70 typedef Vamos_Geometry::Material::Material_Type Mat_Type; 71 Interaction_InfoInteraction_Info72 Interaction_Info (Vamos_Body::Car* car_in, 73 Mat_Type car_material_type, 74 Mat_Type track_material_type, 75 double par_speed, double perp_speed) 76 : car (car_in), 77 car_material (car_material_type), 78 track_material (track_material_type), 79 parallel_speed (par_speed), 80 perpendicular_speed (perp_speed) 81 {} 82 83 Vamos_Body::Car* car; 84 Mat_Type car_material; 85 Mat_Type track_material; 86 double parallel_speed; 87 double perpendicular_speed; 88 }; 89 90 class World 91 { 92 public: 93 World (Vamos_Track::Strip_Track* track, Atmosphere* atmosphere); 94 virtual ~World (); 95 96 void interact (Vamos_Body::Car* car, 97 size_t road_index, 98 size_t segment_index); 99 void collide (Car_Information* car1_info, Car_Information* car2_info); 100 void gravity (double g); get_gravity()101 double get_gravity () const { return m_gravity; } 102 virtual void add_car (Vamos_Body::Car* car, 103 Driver* driver, 104 const Vamos_Track::Road& road, 105 bool controlled = false); 106 virtual void set_focused_car (size_t car_index); 107 void focus_other_car (int delta); cars_can_interact(bool can)108 void cars_can_interact (bool can) { m_cars_can_interact = can; } 109 void propagate_cars (double time_step); number_of_cars()110 size_t number_of_cars () const { return m_cars.size (); } 111 112 protected: 113 Vamos_Track::Strip_Track* mp_track; 114 Atmosphere* mp_atmosphere; 115 double m_gravity; 116 117 std::vector <Car_Information> m_cars; 118 /// The times for all cars. 119 Timing_Info* mp_timing; 120 std::vector <Interaction_Info> m_interaction_info; 121 size_t m_focused_car_index; 122 123 virtual void start (size_t laps); 124 void reset (); 125 void restart (); 126 127 Car_Information* focused_car (); 128 Car_Information* controlled_car (); 129 130 private: 131 void place_car (Vamos_Body::Car* car, 132 const Vamos_Geometry::Three_Vector& pos, 133 const Vamos_Track::Road& Road); 134 void set_controlled_car (size_t car_index); 135 136 bool m_cars_can_interact; 137 bool m_has_controlled_car; 138 size_t m_controlled_car_index; 139 140 double slipstream_air_density_factor (Car_Information& car1, Car_Information& car2); 141 }; 142 } 143 144 #endif // not _WORLD_H_ 145