[go: up one dir, main page]

File: fltobj.h

package info (click to toggle)
sabre 0.2.3-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 4,876 kB
  • ctags: 5,106
  • sloc: cpp: 25,581; ansic: 7,439; sh: 2,063; makefile: 92
file content (511 lines) | stat: -rw-r--r-- 17,296 bytes parent folder | download
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
/*
    SABRE Fighter Plane Simulator 
    Copyright (c) 1997 Dan Hammer
    Portions Donated By Antti Barck

    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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*************************************************
 *           SABRE Fighter Plane Simulator       *
 * File   : fltobj.h                             *
 * Date   : February, 1998                       *
 * Author : Dan Hammer                           *
 * Some support classes for the flight modeling  *
 * Originally in flight.h                        *
 *************************************************/
#ifndef __fltobj_h
#define __fltobj_h

#include "dvmath.h"

class C_3DObject_Base;
extern float time_frame;
extern const float nz;
extern const float wb_damp;
extern float p_height;
extern const float g;
extern float time_factor;
extern float world_scale;

/* engine types */
#define PROP_TYPE       0
#define JET_TYPE        1
#define JET_AB_TYPE     2
#define TURBO_JET_TYPE  3
/* radar type mask */
#define RADAR_TYPE_MASK 0x07L
/* Default minimum & maximum values for controls */
#define AILERON_MIN    -30     
#define AILERON_MAX     30
#define ELEVATOR_MIN   -30
#define ELEVATOR_MAX    30
#define RUDDER_MIN     -30
#define RUDDER_MAX      30
#define FLAPS_MIN        0
#define FLAPS_MAX       20
#define FLAPS_STEP       5
#define TRIM_MIN       -30
#define TRIM_MAX        30
/* enums for view */
typedef enum flight_view { front, left, right, back, satellite,
			   outside_1, outside_2, outside_3, outside_4 };

/******************************************************************
 * specifications class                                           *
 * Units are fps (feet-pounds-seconds), angles in radians         *
 ******************************************************************/
class Flight_Specs
{
public:
  float weight;                        /* takeoff weight in pounds */
  float max_thrust;                    /* maximum thrust in lbs/ft */
  float max_speed;                     /* maximum speed in kts */
  float corner_speed;                  /* "corner" speed */
  float drag_factor;                   /* drag coefficient */
  float idrag_factor;                  /* induced drag coefficient */
  float lift_factor;                   /* lift coefficient */
  float wing_aoa;	               /* angle-of-attack of wing */
  float max_aoa;                       /* maximum angle-of-attack before stall */
  float max_aoa_factor;                /* max_aoa before stall relative to velocity */
  /*****************************
   * Additional sources of drag
   *****************************/
  float drag_aoa;                      /* additional drag from angle-of-attack */
  float drag_yaw;                      /* additional drag from yaw */
  float drag_wb;                       /* drag produced by engaged wheel-brakes */
  float drag_gr;                       /* drag produced by lowered landing gear */
  float drag_sb;                       /* drag produced by speed-brakes */
  float drag_whls;                     /* drag from wheels on ground */
  /*****************************
   * Rotational parameters     
   *****************************/
  float control_pitch;	               /* pitching moment produced by elevator position */
  float control_yaw;                   /* yawing moment produced by rudder position */
  float control_roll;	               /* rolling moment produced by aileron positions */
  float return_pitch;	               /* pitching moment towards flight path produced by horiz. stab. */
  float return_yaw;		       /* yawing moment towards flight path produced by vert. stab. */ 
  float pitch_drag;                    /* drag factor for pitching */
  float yaw_drag;                      /* drag factor for yawing */
  float roll_drag;                     /* drag factor for rolling */
  float pitch_damp;                    /* damp on pitching */
  float yaw_damp;                      /* damp on yawing */
  float roll_damp;                     /* damp on rolling */
  /*****************************
   * landing parameters        *
   *****************************/
  float lspeed;  		       /* maximum landing speed */
  float l_z;     		       /* minimum vertical velocity */
  float l_aoa_max;                     /* angle-of-attack */
  float max_wb;			       /* speed at which wheel-brakes become effective */
  /****************************
   * adverse yaw and roll     *
   ****************************/
  float adv_yaw;		       /* yawing moment produced by ailerons */
  float adv_roll;		       /* rolling moment produced by rudder */
  /****************************
   * more aeorodynamically    *
   * suspicious stuff         *
   ****************************/
  float g_height;                      /* height of fuselage when on ground w gear down */
  float flap_lift;   		       /* how much flaps contribute to lift */
  float flap_drag;		       /* how much flaps contribute to drag */
  float fuel_cap;		       /* capacity in lbs of internal fuel tank */
  float wb_damp;		       /* damping factor for wheel brakes */
  float load_limit;		       /* limit on load (lift / weight) */
  float stall_spin;		       /* rolling moment from stall */
  int max_damage;		       /* maximum amount of abuse the poor plane can stand */
  R_3DPoint view_point;		       /* pilot's head position in cockpit ("port" coords") */
  int engine_type;		       /* 0 = prop, 1 = jet, 2 = jet with afterburner */
  long flags;			       /* general-purpose flags */
  char model[32];                      /* model */

  Flight_Specs()
  {
    weight = 0.0;
    max_thrust = 0.0;
    max_speed = 0.0;
    corner_speed = 0.0;
    drag_factor = 0.0;
    idrag_factor = 0.0;
    lift_factor = 0.0;
    wing_aoa = 0.0;
    max_aoa = 0.0;
    drag_aoa = 0.0;
    drag_yaw = 0.0;
    drag_wb = 0.0;
    drag_gr = 0.0;
    drag_sb = 0.0;
    drag_whls = 0.0;
    control_pitch = 0.0;
    control_yaw = 0.0;
    control_roll = 0.0;
    return_pitch = 0.0;
    return_yaw = 0.0;
    pitch_drag = 0.0;
    yaw_drag = 0.0;
    roll_drag = 0.0;
    pitch_damp = 0.0;
    yaw_damp = 0.0;
    roll_damp = 0.0;
    lspeed = 0.0;
    l_z = 0.0;
    max_wb = 0.0;
    l_aoa_max = 0.0;
    adv_yaw = 0.0;
    adv_roll = 0.0;
    g_height = 0.0;
    flap_lift = 0.01;
    flap_drag = 0.003;
    fuel_cap = 100.0;
    wb_damp = 2.0;
    load_limit = 9.9;
    stall_spin = 0.5;
    max_damage = 100;
    max_aoa_factor = 0.03;
    engine_type = JET_TYPE;
    flags = 0;
  }
  void read(istream &);
  void write(ostream &);
  friend istream &operator >>(istream &is, Flight_Specs &fs)
    {
      fs.read(is);
      return(is);
    }
  friend ostream &operator <<(ostream &os, Flight_Specs &fs)
    {
      fs.write(os);
      return(os);
    }
  int read_file(char *);
  int write_file(char *);
  static Flight_Specs **g_specs;
  static int nspecs;
  static Flight_Specs *getSpecs(char *model);
};


/******************************************************************
 * controls class                                                 *
 ******************************************************************/
class Flight_Controls
{
public:
  /* Local min & max control values */
  float aileron_min,aileron_max;
  float elevator_min, elevator_max;
  float rudder_min, rudder_max;
  float flaps_min, flaps_max, flaps_step;
  float trim_min, trim_max;
public:
  float ailerons;                 /* aileron position */	
  float elevators;    	          /* elevator position */
  float throttle;    	          /* throttle percentage (0 ... 100%) */
  float rudder;                   /* rudder position */
  float flaps;                    /* degree of flaps */
  float trim;                     /* trim-tab position */
  
  /* Toggle (on/off) controls */
  int speed_brakes;       
  int wheel_brakes;
  int landing_gear;
  int engine_on;
  int bang_bang;                  /* fire weapon */
  int autopilot;
  int radar;
  int armed_w;                    /* arm weapon */

  int a_burner;                   /* after burner stage */
  int s_weapon;                   /* selected weapon index */

  /* display flags */
  int cockpit;                    /* display cockpit graphic if available */
  int vextern;                    /* display exterior */
  int hud_on;                     /* display hud */
  int vect_on;                    /* display flight-path vector */
  int show_controls;              /* display yoke position, rudder position etc */
  /* outside viewing params */
  REAL_TYPE vdist;                /* distance from aircraft */                 
  REAL_TYPE vtheta;               /* horiz. rotation */
  REAL_TYPE vphi;                 /* vert. rotation */
  /* current view */
  int view;

  Flight_Controls()
  {
    aileron_min = AILERON_MIN;
    aileron_max = AILERON_MAX;
    elevator_min = ELEVATOR_MIN;
    elevator_max = ELEVATOR_MAX;
    rudder_min = RUDDER_MIN;
    rudder_max = RUDDER_MAX;
    flaps_min = FLAPS_MIN;
    flaps_max = FLAPS_MAX;
    flaps_step = FLAPS_STEP;
    trim_min = TRIM_MIN;
    trim_max = TRIM_MAX;

    elevators = 0;
    ailerons = 0;
    throttle = 0;
    rudder = 0;
    speed_brakes = 0;
    flaps = 0;
    trim = 0;
    wheel_brakes = 0;
    landing_gear = 0;
    view = front;
    engine_on = 0;
    bang_bang = 0;
    autopilot = 0;
    s_weapon = 0;
    a_burner = 0;
    radar = 0;
    armed_w = 0;
    cockpit = 1;
    vextern = 1;
    hud_on = 1;
    vect_on = 0;
    vdist = 100;
    vtheta = 0.6;
    vphi = 0.2;
    show_controls = 1;
  }
  void read(istream &is);
  void write(ostream &os);
  friend istream & operator >>(istream &is, Flight_Controls &fc)
    {
      fc.read(is);
      return(is);
    }
  friend ostream & operator <<(ostream &os, Flight_Controls &fc)
    {
      fc.write(os);
      return(os);
    }
};

/***************************************************************
  A way of representing 'vector' quantities in two parts - a
  float scalar value, representing the magnitude, and
  normalized vector representing the direction. The magnitude
  is always positive.
  *************************************************************/
class Vector_Q
{
public:
  float magnitude;
  DVector direction;
  Vector_Q()
    : magnitude(0),
      direction(0,0,0)
  {}
  Vector_Q(float &mag, const DVector &v)
    : magnitude(mag),direction(v)
  {}
  Vector_Q(const Vector_Q &vq)
    : magnitude(vq.magnitude),
      direction(vq.direction)
  {}
  Vector_Q &operator =(const Vector_Q &vq)
  {
    magnitude = vq.magnitude; direction = vq.direction;
    return *this;
  }
  friend DVector to_vector(Vector_Q &vq);
  friend Vector_Q operator +(Vector_Q &, Vector_Q &);
  friend DVector operator +(DVector &, Vector_Q &);

  friend ostream &operator <<(ostream &os, Vector_Q &vq)
  {
    os << '(' << vq.magnitude << ' ' << vq.direction << ')';
    return os;
  }

  friend istream &operator >>(istream &is, Vector_Q &vq);
};

/***********************************************************
 * current forces in effect                                *
 ***********************************************************/
class Flight_Forces
{
public:
  /* "Vector" forces */
  Vector_Q thrust;			  /* thrust of engine */
  Vector_Q drag;	                  /* opposing drag */
  Vector_Q lift;                          /* lift */
  Vector_Q g;                             /* weight */
  /* rotational accelerations */
  float pitch_acc;                        /* net pitching acceleration */
  float yaw_acc;                          /* net yawing acceleration */
  float roll_acc;                         /* net rolling acceleration */
  Flight_Forces()
  {
    pitch_acc = yaw_acc = roll_acc = 0.0;
  }
};

/***********************************************************
 * current state of flight                                 *
 ***********************************************************/
class Flight_State
{
public:
  Vector_Q velocity;		 /* velocity in feet-per-second, in world coordinants */
  DVector vel_pv;		 /* direction of velocity in port coordinants */
  float z_vel;			 /* magnitude of velocity along z-axis ("air speed") */
  float delta_z_vel;		 /* rate of change in above */
  float climb_vel;               /* climb rate in feet-per-second */
  float delta_climb_vel;         /* rate of change of rate of climb (whew!) */
  float angle_of_attack;         /* also known as "angle of incidence", the flight-path v fuselage */
  float yaw;			 /* actually, the cos of the yaw (1 ... -1) */
  DVector h_direction;		 /* Vector representing movement on xy plane */
  float heading;		 /* the heading for above, in radians */
  Port_3D flight_port;		 /* gives position and orientation */
  int inverted;			 /* true if inverted */
  int negative_roll;		 /* true if rolled into negative angle */
  int negative_phi;              /* true if pitched into negative angle */
  int crashed;			 /* true if aerodynamically challenged */
  int stalled;			 /* true if stalled */
  float near_stall;		 /* how far from stall angle (radians) */
  float pitch_rate;		 /* angular rate of pitch (radians per second) */
  float d_pitch_rate;            /* rate of change for above */
  float yaw_rate;		 /* angular rate of yaw (radians per second) */
  float d_yaw_rate;              /* rate of change for above */
  float roll_rate;		 /* angular rate of roll (radians per second) */
  float d_roll_rate;             /* rate of change for above */
  int on_ground;		 /* true if on ground */
  /* landing parameters */
  float landing_z;		 /* vertical velocity upon landing */
  float landing_velocity;	 /* speed upon landing */
  float landing_aoa;		 /* aoa on landing */
  float landing_pitch;           /* pitch relative to ground on landing */
  float landing_roll;		 /* roll on landing */
  int was_airborne;  		 /* flag indicating we were at one time airborne */
  int landing_recorded;		 /* landing data recorded */
  /* more stuff */
  float load;		         /* load (lift / weight); */
  float d_load;                  /* change in */
  float air_density;		 /* air density factor */
  float vel_factor;		 /* velocity factor in determining roll rates */
  float ground_height;           /* height-of-terrain below us */
  float d_ground_height;	 /* change in */
  float agl;                     /* Altitude above Ground Level */
  float d_agl;                   /* change in */
  float weight;                  /* current weight */
  float fuel;                    /* current lbs of fuel */
  float elapsed_time;            /* elapsed time in seconds */
  Flight_State()
  {
    z_vel = 0.0;
    delta_z_vel = 0.0;
    climb_vel = 0.0;
    delta_climb_vel = 0.0;
    angle_of_attack = 0.0;
    yaw = 0.0;
    heading = 0.0;
    inverted = 0;
    negative_roll = 0;
    negative_phi = 0;
    crashed = 0;
    stalled = 0;
    near_stall = 0;
    pitch_rate = d_pitch_rate = 0.0;
    yaw_rate = d_yaw_rate = 0.0;
    roll_rate = d_roll_rate = 0.0;
    landing_z = 0.0;
    landing_velocity = 0.0;
    landing_aoa = 0.0;
    landing_pitch = 0.0;
    load = d_load = 0.0;
    was_airborne = 0;
    landing_recorded = 0;
    vel_factor = 0.0;
    ground_height = 0.0;
    d_ground_height = 0.0;
    agl = 0.0;
    d_agl = 0.0;
    weight = 0.0;
    fuel = 0.0;
    elapsed_time = 0.0;
  }
  void read(istream &is);
  void write(ostream &os)
    {
      os << velocity.magnitude << flight_port;
    }
  friend istream &operator >>(istream &is, Flight_State &fp)
    {
      fp.read(is);
      return(is);
    }
  friend ostream &operator <<(ostream &os, Flight_State &fp)
    {
      fp.write(os);
      return(os);
    }
};

// This class will be used to modify the performance of the flight
// due to variations such as altitude & air speed. It will also keep track of
// battle damage
class Flight_Mods
{
public:
  // Total amount of battle damage : 100 == kaput!
  int battle_damage;
  // The following vars modify the forces generated
  // by the various aircraft components
  float engine_e;
  float wing_e;
  float elevators_e;
  float ailerons_e;
  float rudder_e;
  float h_stab_e;
  float v_stab_e;
  float flaps_e;
  float speed_brakes_e;
  float wheel_brakes_e;
  // out-of-control spin factor
  float spin_out;
  float yaw_out;
  float pitch_out;
  // drag modifier
  float drag_e;
  // fuel loss modifier
  float fuel_e;
  Flight_Mods()
  {
    battle_damage = 0;
    engine_e = 1.0;
    wing_e = 1.0;
    elevators_e = 1.0;
    ailerons_e = 1.0;
    rudder_e = 1.0;
    h_stab_e= 1.0;
    v_stab_e= 1.0;
    flaps_e = 1.0;
    speed_brakes_e = 1.0;
    wheel_brakes_e = 1.0;
    drag_e = 1.0;
    spin_out = 0.0;
    yaw_out = 0.0;
    pitch_out = 0.0;
    fuel_e = 0.0;
  }
};

#endif