[go: up one dir, main page]

Menu

[485645]: / world / World.h  Maximize  Restore  History

Download this file

149 lines (125 with data), 4.6 kB

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