[go: up one dir, main page]

Menu

[f338fb]: / body / Gl_Car.h  Maximize  Restore  History

Download this file

208 lines (165 with data), 5.7 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Gl_Car.h - a car that handles graphics, sound and input devices.
//
// Copyright (C) 2001--2002 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos 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 3 of the License, or
// (at your option) any later version.
//
// Vamos 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 Vamos. If not, see <http://www.gnu.org/licenses/>.
#ifndef _GL_CAR_H_
#define _GL_CAR_H_
#include "Car.h"
#include "../media/Sample.h"
#include "../media/Texture_Image.h"
#include <GL/glu.h>
#include <string>
#include <vector>
namespace Vamos_Body
{
class Dashboard;
//* An exception thrown when a sound file can't be found.
class Missing_Sound_File
{
// The requested file.
std::string m_file;
public:
//** Constructor
Missing_Sound_File (std::string file) : m_file (file) {};
// Return the requested file.
std::string file () const { return m_file; }
};
//* Information about rearview mirrors.
class Rear_View_Mirror
{
const Vamos_Geometry::Three_Vector m_position;
const double m_width;
const double m_height;
const double m_direction;
const double m_field;
const double m_near_plane;
const double m_far_plane;
Vamos_Media::Texture_Image* mp_mask;
struct Rectangle
{
Rectangle () : x (0), y (0), width (1), height (1) {};
int x;
int y;
int width;
int height;
double aspect () const { return double (width) / height; }
};
Rectangle m_viewport;
int to_pixels (double range, double factor, double coordinate)
{ return int (0.5 * range * (1.0 - factor * coordinate)); }
void set_viewport (int window_width, int window_height,
const Vamos_Geometry::Three_Vector& driver_position,
double driver_field_of_view,
double pan);
void activate_viewport ();
void transform_view () const;
void draw_mask_shape ();
unsigned char* make_stencil_buffer ();
void set_stencil (int window_width, int window_height);
public:
Rear_View_Mirror (const Vamos_Geometry::Three_Vector& position,
double width, double height,
double direction, double field,
double near_plane, double far_plane,
std::string mask_file);
~Rear_View_Mirror ();
void make_mask (int window_width, int window_height,
const Vamos_Geometry::Three_Vector& driver_position,
double driver_field_of_view,
double pan);
void set_view ();
double get_direction () const { return m_direction; }
Vamos_Geometry::Three_Vector get_center () const;
};
//* A car that handles graphics, sound and input devices.
class Gl_Car : public Car
{
public:
//** Constructor
Gl_Car (const Vamos_Geometry::Three_Vector& position,
const Vamos_Geometry::Three_Matrix& orientation);
//** Destructor
virtual ~Gl_Car ();
// Read the car definition file.
void read (std::string data_dir = "", std::string car_file = "");
// Define a sound for the engine.
virtual void engine_sound (std::string file,
double volume,
double throttle_volume_factor,
double engine_speed_volume_factor,
double pitch);
// Set the 3D models.
virtual void
exterior_model (std::string file, double scale,
const Vamos_Geometry::Three_Vector& translation,
const Vamos_Geometry::Three_Vector& rotation);
virtual void
interior_model (std::string file, double scale,
const Vamos_Geometry::Three_Vector& translation,
const Vamos_Geometry::Three_Vector& rotation);
void set_perspective (double aspect);
void set_view (const Vamos_Geometry::Three_Vector& position,
double field_of_view,
double near_plane, double far_plane,
double pan_angle);
void add_rear_view (const Vamos_Geometry::Three_Vector& position,
double width, double height,
double direction, double field,
double near_plane, double far_plane,
std::string mask_file);
// Set the dashboard.
void dashboard (Dashboard* dash);
// Render the car according to its current position and
// orientation.
void draw ();
void draw_interior ();
void draw_rear_view (double aspect, int index);
void make_rear_view_mask (int window_width, int window_height);
void update_rear_view_mask (int window_width, int window_height);
int get_n_mirrors () const { return m_mirrors.size (); }
// Perform the transformations for the view.
void view (double pan, const Vamos_Geometry::Three_Vector& view_position);
void view ();
virtual void propagate (double time);
virtual void set_paused (bool is_paused);
private:
double m_throttle_volume_factor;
double m_engine_speed_volume_factor;
// The engine sound.
Vamos_Media::Sample* mp_engine_sample;
// The 3D car models.
GLuint m_body_list_id;
GLuint m_interior_list_id;
// The gauges and steering wheel.
Dashboard* mp_dashboard;
std::vector <Rear_View_Mirror*> m_mirrors;
// Clipping planes.
double m_near_plane;
double m_far_plane;
// Draw the gauges and readouts.
void draw_dashboard ();
// Draw detailed information.
void draw_dashboard_extras ();
// Perform the modelview transformations for the car.
void transform_body ();
void delete_mirrors ();
// Return the sound parameters.
virtual double engine_pitch ();
virtual double engine_volume ();
};
}
#endif // not _GL_CAR_H_