00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _CAR_H_
00022 #define _CAR_H_
00023
00024 #define USE_XML false
00025 #define USE_CAR true
00026
00027 #include <vamos/geometry/Three_Vector.h>
00028 #include <vamos/geometry/Two_Point.h>
00029
00030 #include <vamos/body/Rigid_Body.h>
00031 #include <vamos/body/Drivetrain.h>
00032
00033 #include <vector>
00034 #include <utility>
00035
00036 #include "settings.h"
00037 #include "configfile.h"
00038 #include "model.h"
00039 #include "globals.h"
00040
00041 class BEZIER;
00042
00043 class slSample;
00044 namespace Vamos_Geometry
00045 {
00046 class Sample;
00047 }
00048
00049 namespace Vamos_Body
00050 {
00051
00052 class Dashboard;
00053 class Fuel_Tank;
00054 class Particle;
00055 class Wheel;
00056
00057
00058
00059
00060
00061 class Key_Control
00062 {
00063
00064
00065 bool m_block;
00066
00067
00068 bool m_target_pending;
00069
00070
00071 double m_value;
00072
00073
00074 double m_target;
00075 double m_next_target;
00076
00077
00078 double m_rate;
00079 double m_next_rate;
00080
00081
00082 double m_delay;
00083 double m_next_delay;
00084
00085
00086 double m_time;
00087 double m_next_time;
00088
00089 public:
00090
00091 Key_Control (bool block = false);
00092
00093
00094
00095
00096
00097 void target (double new_target, double time = 0.0, double delay = 0.0);
00098
00099
00100
00101 double update (double time);
00102
00103
00104 double value () const { return m_value; }
00105
00106
00107 void end ();
00108
00109 bool target_pending() {return m_target_pending;}
00110 };
00111
00112
00113
00114 class Car
00115 {
00116
00117
00118 private:
00119 std::string m_data_dir;
00120
00121 struct Crash_Box
00122 {
00123 double front;
00124 double back;
00125 double left;
00126 double right;
00127 double top;
00128 double bottom;
00129
00130
00131 bool within (const Vamos_Geometry::Three_Vector& position) const;
00132 };
00133 Crash_Box m_crash_box;
00134
00135 CONFIGFILE m_car_definition;
00136 bool LoadCarDefinition(string carfile);
00137 bool LoadParts();
00138 bool LoadPart(string partfile);
00139 std::vector <Vamos_Geometry::Two_Point> m_tpoints;
00140
00141 protected:
00142 std::string m_car_file;
00143 Rigid_Body m_chassis;
00144
00145
00146 Drivetrain* mp_drivetrain;
00147
00148
00149 Fuel_Tank* mp_fuel_tank;
00150
00151
00152 double m_front_brake_bias;
00153
00154
00155 double m_max_steer_angle;
00156
00157
00158 double m_steer_exponent;
00159
00160
00161 double m_steer_speed_sensitivity;
00162
00163
00164 double m_slide;
00165
00166
00167
00168 bool m_shift_pending;
00169
00170
00171 double m_shift_timer;
00172
00173
00174
00175 double m_shift_delay;
00176
00177
00178
00179 int m_new_gear;
00180
00181
00182 int m_last_gear;
00183
00184
00185
00186 Key_Control m_steer_key_control;
00187
00188
00189
00190 Key_Control m_gas_key_control;
00191
00192
00193
00194 Key_Control m_brake_key_control;
00195
00196
00197
00198 Key_Control m_handbrake_key_control;
00199
00200
00201
00202 Key_Control m_clutch_key_control;
00203
00204
00205 Key_Control m_pan_key_control;
00206
00207
00208 Particle* mp_front_particle;
00209
00210
00211 double m_distance_traveled;
00212
00213
00214 Vamos_Geometry::Three_Vector m_driver_view;
00215
00216
00217 double m_field_of_view;
00218
00219
00220 double m_pan_angle;
00221
00222
00223 bool m_show_dashboard_extras;
00224
00225
00226 void private_reset ();
00227
00228 std::vector <Wheel*> m_wheels;
00229
00230 int controller;
00231
00232 int m_sector;
00233 BEZIER * m_colpatches[4];
00234
00235 public:
00236
00237 Vamos_Geometry::Three_Vector car_lastpos;
00238
00239 int get_controller() {return controller;}
00240 void set_controller(int newc) {controller = newc;}
00241
00242
00243 Car (const Vamos_Geometry::Three_Vector& pos);
00244
00245 float brakesetting;
00246
00247
00248 virtual ~Car ();
00249
00250 virtual void SetReflectionTexture(TEXTURE_HANDLE * reftid) {cout << "warning: Car::SetReflectionTexture called instead of Gl_Car::SetReflectionTexture" << endl;}
00251
00253 Rigid_Body& chassis () { return m_chassis; }
00254
00255
00256 void read (std::string data_dir = "", std::string car_file = "");
00257
00258
00259 virtual void engine_sound (std::string file,
00260 double volume,
00261 double throttle_volume_factor,
00262 double engine_speed_volume_factor,
00263 double pitch) = 0;
00264
00265
00266 virtual void
00267 exterior_model (std::string file, double scale,
00268 const Vamos_Geometry::Three_Vector& translation,
00269 const Vamos_Geometry::Three_Vector& rotation) = 0;
00270 virtual void
00271 interior_model (std::string file, double scale,
00272 const Vamos_Geometry::Three_Vector& translation,
00273 const Vamos_Geometry::Three_Vector& rotation) = 0;
00274
00275
00276 virtual void dashboard (Dashboard* dash) = 0;
00277
00278
00279 virtual void propagate (double time);
00280
00281
00282 void pan (double factor, double time = 0.0);
00283
00284
00285 void steer (double angle, double time = 0.0);
00286
00287
00288 void gas (double factor, double time = 0.0);
00289
00290
00291 void brake (double factor, double time = 0.0);
00292
00293
00294 double steer() { return m_steer_key_control.value(); }
00295
00296
00297 double gas() { return m_gas_key_control.value(); }
00298
00299
00300 double brake() { return m_brake_key_control.value(); }
00301
00302
00303 double max_steer_angle() { return m_max_steer_angle; }
00304
00305 void handbrake (double factor, double time = 0.0);
00306
00307
00308 int shift_down ();
00309
00310
00311 int shift_up ();
00312
00313
00314 int shift (int gear);
00315
00316 void clutch (double factor, double time = 0.0);
00317
00318 void engage_clutch (double time);
00319 void disengage_clutch (double time);
00320 void start_engine ();
00321
00322
00323 void brake_bias (double bias);
00324
00325
00326 void max_steer_angle (double degree_angle)
00327 { m_max_steer_angle = degree_angle; }
00328
00329
00330 void steer_exponent (double exponent) { m_steer_exponent = exponent; }
00331
00332
00333 void steer_speed_sensitivity (double sensitivity)
00334 { m_steer_speed_sensitivity = sensitivity; }
00335
00336
00337 void shift_delay (double time) { m_shift_delay = time; }
00338
00339
00340
00341 void clutch_time (double from_neutral, double others);
00342
00343
00344 double slide () const { return m_slide; }
00345
00346
00347 Wheel* wheel (int wheel_index) const;
00348
00349
00350 Particle* front_particle () const { return mp_front_particle; }
00351
00352
00353 Engine* engine () { return mp_drivetrain->engine (); }
00354
00355
00356 Transmission* transmission () { return mp_drivetrain->transmission (); }
00357
00358
00359 Fuel_Tank* fuel_tank () { return mp_fuel_tank; }
00360
00361
00362
00363
00364 int gear () const { return m_new_gear; }
00365
00366
00367 int last_gear () const { return m_last_gear; }
00368
00369
00370
00371
00372
00373 void reset ();
00374
00375
00376
00377 void reset (const Vamos_Geometry::Three_Vector& position,
00378 const Vamos_Geometry::Three_Matrix& orientation);
00379
00380
00381
00382 double distance_traveled () const { return m_distance_traveled; }
00383
00384 void drivetrain (Drivetrain* drive);
00385
00386
00387 void view_position (const Vamos_Geometry::Three_Vector& driver_view)
00388 { m_driver_view = driver_view; }
00389
00390
00391 void field_of_view (double field) { m_field_of_view = field; }
00392
00393 virtual void set_view (const Vamos_Geometry::Three_Vector& position,
00394 double field_of_view,
00395 double near_plane, double far_plane,
00396 double pan_angle) {};
00397
00398 virtual void set_perspective (double aspect) {};
00399
00400
00401 virtual void add_rear_view (const Vamos_Geometry::Three_Vector& position,
00402 double width, double height,
00403 double direction, double field,
00404 double near_plane, double far_plane,
00405 std::string mask_file) {};
00406
00407
00408 double field_of_view () const { return m_field_of_view; }
00409
00410
00411 double pan () const { return m_pan_key_control.value (); }
00412
00413
00414 Vamos_Geometry::Three_Vector view_position () const;
00415
00416
00417
00418
00419
00420 virtual TEXTURE_HANDLE * shadow_texture() {cerr << "ERROR: virtual call to shadow_texture!" << endl; return NULL;}
00421 virtual void draw (bool transform) {};
00422 virtual void draw_interior () {};
00423 virtual void draw_rear_view (double aspect, int index) {};
00424 virtual void make_rear_view_mask (int window_width,
00425 int window_height) {};
00426 virtual int get_n_mirrors () const { return 0; }
00427
00428
00429 virtual void view (double pan,
00430 const Vamos_Geometry::Three_Vector& view_position) {};
00431 virtual void view (double pan) {};
00432
00433
00434 virtual Vamos_Geometry::Sample* engine_sound () = 0;
00435
00436
00437 virtual double engine_pitch () { return 0.0; }
00438 virtual double engine_volume () { return 0.0; }
00439
00440 virtual int GetSoundSource() {return -12337;}
00441 virtual int GetTireSoundSource(int i) {return -1337;}
00442
00443
00444 bool fast_shift () const { return m_shift_delay <= 0.0; }
00445
00446 void show_dashboard_extras (bool show) { m_show_dashboard_extras = show; }
00447
00448
00449 bool collision (const Vamos_Geometry::Three_Vector& position) const;
00450
00451
00452 bool ShiftPending() {return (m_shift_pending || m_clutch_key_control.target_pending());}
00453
00454 void GetState(Vamos_Geometry::Three_Vector &chassispos,
00455 Vamos_Geometry::Three_Matrix &chassisorientation,
00456 Vamos_Geometry::Three_Vector &chassisvel,
00457 Vamos_Geometry::Three_Vector &chassisangvel,
00458 double *suspdisp,
00459 double *suspcompvel,
00460 Vamos_Geometry::Three_Vector *whlangvel,
00461 int &gear,
00462 double &enginespeed,
00463 double &clutchspeed,
00464 double &enginedrag,
00465 double *tirespeed
00466 );
00467
00468 void SetState(Vamos_Geometry::Three_Vector chassispos,
00469 Vamos_Geometry::Three_Matrix chassisorientation,
00470 Vamos_Geometry::Three_Vector chassisvel,
00471 Vamos_Geometry::Three_Vector chassisangvel,
00472 double *suspdisp,
00473 double *suspcompvel,
00474 Vamos_Geometry::Three_Vector *whlangvel,
00475 int gear,
00476 double enginespeed,
00477 double clutchspeed,
00478 double enginedrag,
00479 double * tirespeed
00480 );
00481
00482 virtual JOEMODEL * GetCollisionModel() {return NULL;}
00483
00484 void SetSector(int newsector) {m_sector = newsector;}
00485 int GetSector() {return m_sector;}
00486 void SetColPatch(int i, BEZIER * newcolpatch) {if (i < 4 && i >= 0) m_colpatches[i] = newcolpatch;}
00487 BEZIER * GetColPatch(int i) {if (i < 4 && i >= 0) return m_colpatches[i]; else return NULL;}
00488
00489 void SetColParams(int i, double f1, double f2, double rr, double rd);
00490 };
00491
00492 class Facade;
00493 class Gauge;
00494 class Gear_Indicator;
00495 class Steering_Wheel;
00496
00497 struct Model_Info
00498 {
00499 std::string file;
00500 double scale;
00501 Vamos_Geometry::Three_Vector translate;
00502 Vamos_Geometry::Three_Vector rotate;
00503
00504 Model_Info (std::string file_in, double scale_in,
00505 const Vamos_Geometry::Three_Vector& translate_in,
00506 const Vamos_Geometry::Three_Vector& rotate_in)
00507 : file (file_in),
00508 scale (scale_in),
00509 translate (translate_in),
00510 rotate (rotate_in)
00511 {};
00512 };
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571 }
00572
00573 #endif // not _CAR_H_