00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _GL_CAR_H_
00022 #define _GL_CAR_H_
00023
00024 #include <vamos/body/Car.h>
00025 #include <vamos/geometry/Sample.h>
00026
00027 #include <GL/glu.h>
00028
00029 #include "model.h"
00030 #include "font.h"
00031 #include "sound.h"
00032 #include "settings.h"
00033 #include "globals.h"
00034
00035 #include <string>
00036 #include <vector>
00037
00038 namespace Vamos_Body
00039 {
00040 class Dashboard;
00041
00042
00043 class Missing_Sound_File
00044 {
00045
00046 std::string m_file;
00047
00048 public:
00049
00050 Missing_Sound_File (std::string file) : m_file (file) {};
00051
00052
00053 std::string file () const { return m_file; }
00054 };
00055
00056
00057
00058
00059 class Rear_View_Mirror
00060 {
00061 const Vamos_Geometry::Three_Vector m_position;
00062 const double m_width;
00063 const double m_height;
00064 const double m_direction;
00065 const double m_field;
00066 const double m_near_plane;
00067 const double m_far_plane;
00068 Vamos_Geometry::Gl_Texture_Image* mp_mask;
00069
00070 struct Rectangle
00071 {
00072 Rectangle () : x (0), y (0), width (1), height (1) {};
00073 int x;
00074 int y;
00075 int width;
00076 int height;
00077 double aspect () const { return double (width) / height; }
00078 };
00079
00080 Rectangle m_viewport;
00081
00082 int to_pixels (double range, double factor, double coordinate)
00083 { return int (0.5 * range * (1.0 - factor * coordinate)); }
00084
00085 void set_viewport (int window_width, int window_height,
00086 const Vamos_Geometry::Three_Vector& driver_position,
00087 double driver_field_of_view);
00088 void activate_viewport ();
00089 void transform_view () const;
00090 void draw_mask_shape ();
00091 unsigned char* make_stencil_buffer ();
00092 void set_stencil (int window_width, int window_height);
00093
00094 public:
00095 Rear_View_Mirror (const Vamos_Geometry::Three_Vector& position,
00096 double width, double height,
00097 double direction, double field,
00098 double near_plane, double far_plane,
00099 std::string mask_file);
00100 ~Rear_View_Mirror ();
00101
00102 void make_mask (int window_width, int window_height,
00103 const Vamos_Geometry::Three_Vector& driver_position,
00104 double driver_field_of_view);
00105 void set_view ();
00106
00107 double get_direction () const { return m_direction; }
00108 Vamos_Geometry::Three_Vector get_center () const;
00109 };
00110
00111
00112 class Gl_Car : public Car
00113 {
00114 double m_throttle_volume_factor;
00115 double m_engine_speed_volume_factor;
00116
00117
00118 Vamos_Geometry::Sample* mp_engine_sample;
00119
00120 int real_engine_sample;
00121 int tire_source[4];
00122
00123
00124 JOEMODEL joeinterior;
00125 JOEMODEL joeglass;
00126 JOEMODEL joeexterior;
00127 JOEMODEL joecollision;
00128 TEXTURE_HANDLE shadowtex;
00129
00130
00131 Dashboard* mp_dashboard;
00132
00133 std::vector <Rear_View_Mirror*> m_mirrors;
00134
00135
00136 double m_near_plane;
00137 double m_far_plane;
00138
00139
00140 void draw_dashboard ();
00141
00142
00143 void draw_dashboard_extras ();
00144
00145
00146 void transform_body ();
00147
00148 int num_paintjobs;
00149
00150 protected:
00151
00152
00153 void draw_string (const std::string& str, double x, double y);
00154
00155 public:
00156
00157 Gl_Car (const Vamos_Geometry::Three_Vector& pos);
00158
00159
00160 virtual ~Gl_Car ();
00161
00162
00163
00164 virtual void engine_sound (std::string file,
00165 double volume,
00166 double throttle_volume_factor,
00167 double engine_speed_volume_factor,
00168 double pitch);
00169
00170
00171 virtual void
00172 exterior_model (std::string file, double scale,
00173 const Vamos_Geometry::Three_Vector& translation,
00174 const Vamos_Geometry::Three_Vector& rotation);
00175 virtual void
00176 interior_model (std::string file, double scale,
00177 const Vamos_Geometry::Three_Vector& translation,
00178 const Vamos_Geometry::Three_Vector& rotation);
00179
00180 void set_perspective (double aspect);
00181
00182 void set_view (const Vamos_Geometry::Three_Vector& position,
00183 double field_of_view,
00184 double near_plane, double far_plane,
00185 double pan_angle);
00186
00187 void add_rear_view (const Vamos_Geometry::Three_Vector& position,
00188 double width, double height,
00189 double direction, double field,
00190 double near_plane, double far_plane,
00191 std::string mask_file);
00192
00193
00194 void dashboard (Dashboard* dash);
00195
00196
00197
00198 void draw (bool transform) {draw(transform, 1.0);}
00199 void draw (bool transform, float opacity);
00200
00201 int GetSoundSource();
00202 int GetTireSoundSource(int i);
00203
00204 void draw_interior ();
00205 void draw_rear_view (double aspect, int index);
00206 void make_rear_view_mask (int window_width, int window_height);
00207 int get_n_mirrors () const { return m_mirrors.size (); }
00208
00209
00210 void view (double pan, const Vamos_Geometry::Three_Vector& view_position);
00211 void view (double pan) { view (pan, m_driver_view); }
00212
00213
00214 Vamos_Geometry::Sample* engine_sound () { return mp_engine_sample; }
00215
00216 TEXTURE_HANDLE * shadow_texture();
00217
00218
00219 virtual double engine_pitch ();
00220 virtual double engine_volume ();
00221
00222 int GetNumPaintjobs() { return num_paintjobs; }
00223 void SetPaint(int pid);
00224 void SetReflectionTexture(TEXTURE_HANDLE * reftid) {joeexterior.ReflectionTextureID(reftid, 2);joeglass.ReflectionTextureID(reftid, 2);}
00225
00226 JOEMODEL * GetCollisionModel() {return &joecollision;}
00227 };
00228 }
00229
00230 #endif // not _GL_CAR_H_