]> git.mxchange.org Git - flightgear.git/blob - Main/fg_init.c
Shufflin' stuff.
[flightgear.git] / Main / fg_init.c
1 /**************************************************************************
2  * fg_init.c -- Flight Gear top level initialization routines
3  *
4  * Written by Curtis Olson, started August 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 <stdio.h>
28 #include <stdlib.h>
29
30 #include "fg_init.h"
31 #include "views.h"
32
33 #include "../constants.h"
34 #include "../general.h"
35
36 #include "../Aircraft/aircraft.h"
37 #include "../Cockpit/cockpit.h"
38 #include "../Joystick/joystick.h"
39 #include "../Math/fg_random.h"
40 #include "../Scenery/mesh.h"
41 #include "../Scenery/scenery.h"
42 #include "../Scenery/stars.h"
43 #include "../Time/sunpos.h"
44 #include "../Weather/weather.h"
45
46
47 extern int show_hud;             /* HUD state */
48
49
50 /* General house keeping initializations */
51
52 void fgInitGeneral( void ) {
53     struct GENERAL *g;
54
55     g = &general;
56
57     /* seed the random number generater */
58     fg_srandom();
59
60     /* determine the fg root path */
61     if ( (g->root_dir = getenv("FG_ROOT")) == NULL ) {
62         /* environment variable not defined */
63         printf("FG_ROOT needs to be defined!  See the documentation.\n");
64         exit(0);
65     } 
66     printf("FG_ROOT = %s\n", g->root_dir);
67 }
68
69
70 /* This is the top level init routine which calls all the other
71  * initialization routines.  If you are adding a subsystem to flight
72  * gear, its initialization call should located in this routine.*/
73
74 void fgInitSubsystems( void ) {
75     double cur_elev;
76
77     struct FLIGHT *f;
78     struct VIEW *v;
79
80     f = &current_aircraft.flight;
81     v = &current_view;
82
83
84     /****************************************************************
85      * The following section sets up the flight model EOM parameters and 
86      * should really be read in from one or more files.
87      ****************************************************************/
88
89     /* Globe Aiport, AZ */
90     FG_Runway_altitude = 3234.5;
91     FG_Runway_latitude = 120070.41;
92     FG_Runway_longitude = -398391.28;
93     FG_Runway_heading = 102.0 * DEG_TO_RAD;
94
95     /* Initial Position at GLOBE airport */
96     FG_Latitude  = (  120070.41 / 3600.0 ) * DEG_TO_RAD;
97     FG_Longitude = ( -398391.28 / 3600.0 ) * DEG_TO_RAD;
98     FG_Altitude = FG_Runway_altitude + 3.758099;
99     /* FG_Altitude = 20000; */
100     
101     /* Initial Position north of the city of Globe */
102     /* FG_Latitude  = (  120625.64 / 3600.0 ) * DEG_TO_RAD; */
103     /* FG_Longitude = ( -398673.28 / 3600.0 ) * DEG_TO_RAD; */
104     /* FG_Altitude = 0.0 + 3.758099; */
105
106     printf("Initial position is: (%.4f, %.4f, %.2f)\n", 
107            FG_Latitude * RAD_TO_DEG, FG_Longitude * RAD_TO_DEG, 
108            FG_Altitude * FEET_TO_METER);
109
110       /* Initial Velocity */
111     FG_V_north = 0.0 /*  7.287719E+00 */;
112     FG_V_east  = 0.0 /*  1.521770E+03 */;
113     FG_V_down  = 0.0 /* -1.265722E-05 */;
114
115     /* Initial Orientation */
116     FG_Phi   = -2.658474E-06;
117     FG_Theta =  7.401790E-03;
118     FG_Psi   =  270.0 * DEG_TO_RAD;
119     /* FG_Psi   =  0.0 * DEG_TO_RAD; */
120
121     /* Initial Angular B rates */
122     FG_P_body = 7.206685E-05;
123     FG_Q_body = 0.000000E+00;
124     FG_R_body = 9.492658E-05;
125
126     FG_Earth_position_angle = 0.000000E+00;
127
128     /* Mass properties and geometry values */
129     FG_Mass = 8.547270E+01;
130     FG_I_xx = 1.048000E+03;
131     FG_I_yy = 3.000000E+03;
132     FG_I_zz = 3.530000E+03;
133     FG_I_xz = 0.000000E+00;
134
135     /* CG position w.r.t. ref. point */
136     FG_Dx_cg = 0.000000E+00;
137     FG_Dy_cg = 0.000000E+00;
138     FG_Dz_cg = 0.000000E+00;
139
140     /* Set initial position and slew parameters */
141     /* fgSlewInit(-398391.3, 120070.41, 244, 3.1415); */ /* GLOBE Airport */
142     /* fgSlewInit(-335340,162540, 15, 4.38); */
143     /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */
144
145     /* Initialize shared sun position and sun_vec */
146     fgUpdateSunPos(scenery.center);
147
148     /* Initialize view parameters */
149     fgViewInit(v);
150
151     /* Initialize the weather modeling subsystem */
152     fgWeatherInit();
153
154     /* Initialize the Cockpit subsystem */
155     if( fgCockpitInit( current_aircraft ) == NULL )
156     {
157         printf( "Error in Cockpit initialization!\n" );
158         exit( 1 );
159     }
160
161     /* Initialize the Stars subsystem  */
162     fgStarsInit();
163
164     /* Initialize the Scenery Management subsystem */
165     fgSceneryInit();
166
167     /* Tell the Scenery Management system where we are so it can load
168      * the correct scenery data */
169     fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude);
170
171
172     /* I'm just sticking this here for now, it should probably move 
173      * eventually */
174     cur_elev = mesh_altitude(FG_Longitude * RAD_TO_DEG * 3600.0, 
175                              FG_Latitude  * RAD_TO_DEG * 3600.0);
176     printf("Ground elevation is %.2f meters here.\n", cur_elev);
177     if ( cur_elev > -9990.0 ) {
178         FG_Runway_altitude = cur_elev * METER_TO_FEET;
179     }
180
181     if ( FG_Altitude < FG_Runway_altitude ) {
182         FG_Altitude = FG_Runway_altitude + 3.758099;
183     }
184     printf("Updated position is: (%.4f, %.4f, %.2f)\n", 
185            FG_Latitude * RAD_TO_DEG, FG_Longitude * RAD_TO_DEG, 
186            FG_Altitude * FEET_TO_METER);
187     /* end of thing that I just stuck in that I should probably move */
188
189
190     /* Initialize the flight model subsystem data structures base on
191      * above values */
192     fgFlightModelInit( FG_LARCSIM, f, 1.0 / DEFAULT_MODEL_HZ );
193
194     /* To HUD or not to HUD */
195     show_hud = 1;
196
197     /* Joystick support */
198     fgJoystickInit( 0 );
199 }
200
201
202 /* $Log$
203 /* Revision 1.5  1997/09/04 02:17:36  curt
204 /* Shufflin' stuff.
205 /*
206  * Revision 1.4  1997/08/27 21:32:26  curt
207  * Restructured view calculation code.  Added stars.
208  *
209  * Revision 1.3  1997/08/27 03:30:19  curt
210  * Changed naming scheme of basic shared structures.
211  *
212  * Revision 1.2  1997/08/25 20:27:23  curt
213  * Merged in initial HUD and Joystick code.
214  *
215  * Revision 1.1  1997/08/23 01:46:20  curt
216  * Initial revision.
217  *
218  */