]> git.mxchange.org Git - flightgear.git/blob - Slew/slew.c
Some initial mods to work better in a timer environment.
[flightgear.git] / Slew / slew.c
1 /**************************************************************************
2  * slew.c -- the "slew" flight model
3  *
4  * Written by Curtis Olson, started May 1997.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #include <math.h>
28
29 #include "slew.h"
30 #include "../flight.h"
31 #include "../../aircraft/aircraft.h"
32 #include "../../controls/controls.h"
33
34
35 #ifndef PI2                                               
36 #define PI2  (M_PI + M_PI)                      
37 #endif        
38
39
40 /* reset flight params to a specific position */
41 void fgSlewInit(double pos_x, double pos_y, double pos_z, double heading) {
42     struct flight_params *f;
43
44     f = &current_aircraft.flight;
45
46     f->pos_x = pos_x;
47     f->pos_y = pos_y;
48     f->pos_z = pos_z;
49
50     f->vel_x = 0.0;
51     f->vel_y = 0.0;
52     f->vel_z = 0.0;
53
54     f->Phi = 0.0;
55     f->Theta = 0.0;
56     f->Psi = 0.0;
57
58     f->vel_Phi = 0.0;
59     f->vel_Theta = 0.0;
60     f->vel_Psi = 0.0;
61
62     f->Psi = heading;
63 }
64
65
66 /* update position based on inputs, positions, velocities, etc. */
67 void fgSlewUpdate() {
68     struct flight_params *f;
69     struct control_params *c;
70
71     f = &current_aircraft.flight;
72     c = &current_aircraft.controls;
73
74     f->Psi += ( c->aileron / 8 );
75     if ( f->Psi > PI2 ) {
76         f->Psi -= PI2;
77     } else if ( f->Psi < 0 ) {
78         f->Psi += PI2;
79     }
80
81     f->vel_x = -c->elev;
82
83     f->pos_x = f->pos_x + (cos(f->Psi) * f->vel_x);
84     f->pos_y = f->pos_y + (sin(f->Psi) * f->vel_x);
85 }
86
87
88 /* $Log$
89 /* Revision 1.2  1997/05/29 12:30:19  curt
90 /* Some initial mods to work better in a timer environment.
91 /*
92  * Revision 1.1  1997/05/29 02:29:42  curt
93  * Moved to their own directory.
94  *
95  * Revision 1.2  1997/05/23 15:40:37  curt
96  * Added GNU copyright headers.
97  *
98  * Revision 1.1  1997/05/16 16:04:45  curt
99  * Initial revision.
100  *
101  */