]> git.mxchange.org Git - flightgear.git/blob - Main/fg_init.c
Integrated new event manager with subsystem initializations.
[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 "../Include/constants.h"
34 #include "../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/moon.h"
42 #include "../Scenery/scenery.h"
43 #include "../Scenery/sky.h"
44 #include "../Scenery/stars.h"
45 #include "../Scenery/sun.h"
46 #include "../Time/event.h"
47 #include "../Time/fg_time.h"
48 #include "../Time/sunpos.h"
49 #include "../Weather/weather.h"
50
51
52 extern int show_hud;             /* HUD state */
53 extern int displayInstruments;
54
55
56 /* General house keeping initializations */
57
58 void fgInitGeneral( void ) {
59     struct fgGENERAL *g;
60
61     g = &general;
62
63     printf("General Initialization\n");
64     printf("======= ==============\n");
65
66     /* seed the random number generater */
67     fg_srandom();
68
69     /* determine the fg root path */
70     if ( (g->root_dir = getenv("FG_ROOT")) == NULL ) {
71         /* environment variable not defined */
72         printf("FG_ROOT needs to be defined!  See the documentation.\n");
73         exit(0);
74     } 
75     printf("FG_ROOT = %s\n", g->root_dir);
76
77     printf("\n");
78 }
79
80
81 /* This is the top level init routine which calls all the other
82  * initialization routines.  If you are adding a subsystem to flight
83  * gear, its initialization call should located in this routine.*/
84
85 void fgInitSubsystems( void ) {
86     double cur_elev;
87
88     struct fgFLIGHT *f;
89     struct fgTIME *t;
90     struct fgVIEW *v;
91
92     f = &current_aircraft.flight;
93     t = &cur_time_params;
94     v = &current_view;
95
96     printf("Initialize Subsystems\n");
97     printf("========== ==========\n");
98
99     /****************************************************************
100      * The following section sets up the flight model EOM parameters and 
101      * should really be read in from one or more files.
102      ****************************************************************/
103
104     /* Globe Aiport, AZ */
105     FG_Runway_longitude = -398391.28;
106     FG_Runway_latitude = 120070.41;
107     FG_Runway_altitude = 3234.5;
108     FG_Runway_heading = 102.0 * DEG_TO_RAD;
109
110     /* Initial Position at GLOBE airport */
111     FG_Longitude = ( -398391.28 / 3600.0 ) * DEG_TO_RAD;
112     FG_Latitude  = (  120070.41 / 3600.0 ) * DEG_TO_RAD;
113     FG_Altitude = FG_Runway_altitude + 3.758099;
114     
115     /* Initial Position north of the city of Globe */
116     /* FG_Longitude = ( -398673.28 / 3600.0 ) * DEG_TO_RAD; */
117     /* FG_Latitude  = (  120625.64 / 3600.0 ) * DEG_TO_RAD; */
118     /* FG_Longitude = ( -397867.44 / 3600.0 ) * DEG_TO_RAD; */
119     /* FG_Latitude  = (  119548.21 / 3600.0 ) * DEG_TO_RAD; */
120     /* FG_Altitude = 0.0 + 3.758099; */
121
122     /* Initial Position: 10125 Jewell St. NE */
123     /* FG_Longitude = ( -93.15 ) * DEG_TO_RAD; */
124     /* FG_Latitude  = (  45.15 ) * DEG_TO_RAD; */
125     /* FG_Altitude = FG_Runway_altitude + 3.758099; */
126
127     /* A random test position */
128     /* FG_Longitude = ( 88128.00 / 3600.0 ) * DEG_TO_RAD; */
129     /* FG_Latitude  = ( 93312.00 / 3600.0 ) * DEG_TO_RAD; */
130     FG_Runway_altitude = 4000.0;
131     FG_Altitude = FG_Runway_altitude + 3.758099;
132
133     printf("Initial position is: (%.4f, %.4f, %.2f)\n", 
134            FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, 
135            FG_Altitude * FEET_TO_METER);
136
137       /* Initial Velocity */
138     FG_V_north = 0.0 /*  7.287719E+00 */;
139     FG_V_east  = 0.0 /*  1.521770E+03 */;
140     FG_V_down  = 0.0 /* -1.265722E-05 */;
141
142     /* Initial Orientation */
143     FG_Phi   = -2.658474E-06;
144     FG_Theta =  7.401790E-03;
145     FG_Psi   =  270.0 * DEG_TO_RAD;
146
147     /* Initial Angular B rates */
148     FG_P_body = 7.206685E-05;
149     FG_Q_body = 0.000000E+00;
150     FG_R_body = 9.492658E-05;
151
152     FG_Earth_position_angle = 0.000000E+00;
153
154     /* Mass properties and geometry values */
155     FG_Mass = 8.547270E+01;
156     FG_I_xx = 1.048000E+03;
157     FG_I_yy = 3.000000E+03;
158     FG_I_zz = 3.530000E+03;
159     FG_I_xz = 0.000000E+00;
160
161     /* CG position w.r.t. ref. point */
162     FG_Dx_cg = 0.000000E+00;
163     FG_Dy_cg = 0.000000E+00;
164     FG_Dz_cg = 0.000000E+00;
165
166     /* Set initial position and slew parameters */
167     /* fgSlewInit(-398391.3, 120070.41, 244, 3.1415); */ /* GLOBE Airport */
168     /* fgSlewInit(-335340,162540, 15, 4.38); */
169     /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */
170
171     /* Initialize the event manager */
172     fgEventInit();
173
174     /* Dump event stats every 60 seconds */
175     fgEventRegister( "fgEventPrintStats()", fgEventPrintStats, 
176                      FG_EVENT_READY, 60000 );
177
178     /* Initialize "time" */
179     fgTimeInit(t);
180     fgTimeUpdate(f, t);
181
182     /* Initialize shared sun position and sun_vec */
183     fgEventRegister( "fgUpdateSunPos()", fgUpdateSunPos, FG_EVENT_READY, 1000 );
184
185     /* Initialize view parameters */
186     fgViewInit(v);
187
188     /* Initialize the weather modeling subsystem */
189     fgWeatherInit();
190
191     /* Initialize the Cockpit subsystem */
192     if( fgCockpitInit( current_aircraft ) == NULL ) {
193         printf( "Error in Cockpit initialization!\n" );
194         exit( 1 );
195     }
196
197     /* Initialize the orbital elements of sun, moon and mayor planets */
198     fgSolarSystemInit(*t);
199
200     /* Initialize the Stars subsystem */
201     fgStarsInit();
202
203     /* Initialize the sun's position */
204     fgSunInit();
205
206     /* Intialize the moon's position */
207     fgMoonInit();
208
209     /* Initialize the "sky" */
210     fgSkyInit();
211
212     /* Initialize the Scenery Management subsystem */
213     fgSceneryInit();
214
215     /* Tell the Scenery Management system where we are so it can load
216      * the correct scenery data */
217     fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude);
218
219     /* I'm just sticking this here for now, it should probably move 
220      * eventually */
221     cur_elev = mesh_altitude(FG_Longitude * RAD_TO_DEG * 3600.0, 
222                              FG_Latitude  * RAD_TO_DEG * 3600.0);
223     printf("True ground elevation is %.2f meters here.\n", cur_elev);
224     if ( cur_elev > -9990.0 ) {
225         FG_Runway_altitude = cur_elev * METER_TO_FEET;
226     }
227
228     if ( FG_Altitude < FG_Runway_altitude ) {
229         FG_Altitude = FG_Runway_altitude + 3.758099;
230     }
231     printf("Updated position (after elevation adj): (%.4f, %.4f, %.2f)\n", 
232            FG_Latitude * RAD_TO_DEG, FG_Longitude * RAD_TO_DEG, 
233            FG_Altitude * FEET_TO_METER);
234     /* end of thing that I just stuck in that I should probably move */
235
236
237     /* Initialize the flight model subsystem data structures base on
238      * above values */
239     fgFlightModelInit( FG_LARCSIM, f, 1.0 / DEFAULT_MODEL_HZ );
240
241     /* To HUD or not to HUD */
242     show_hud = 0;
243
244     /* Let's show the instrument panel */
245     displayInstruments = 0;
246
247     /* Joystick support */
248     fgJoystickInit( 0 );
249
250     printf("\n");
251 }
252
253
254 /* $Log$
255 /* Revision 1.24  1997/12/30 20:47:44  curt
256 /* Integrated new event manager with subsystem initializations.
257 /*
258  * Revision 1.23  1997/12/30 16:36:50  curt
259  * Merged in Durk's changes ...
260  *
261  * Revision 1.22  1997/12/19 23:34:05  curt
262  * Lot's of tweaking with sky rendering and lighting.
263  *
264  * Revision 1.21  1997/12/19 16:45:00  curt
265  * Working on scene rendering order and options.
266  *
267  * Revision 1.20  1997/12/18 23:32:33  curt
268  * First stab at sky dome actually starting to look reasonable. :-)
269  *
270  * Revision 1.19  1997/12/17 23:13:36  curt
271  * Began working on rendering a sky.
272  *
273  * Revision 1.18  1997/12/15 23:54:49  curt
274  * Add xgl wrappers for debugging.
275  * Generate terrain normals on the fly.
276  *
277  * Revision 1.17  1997/12/15 20:59:09  curt
278  * Misc. tweaks.
279  *
280  * Revision 1.16  1997/12/12 19:52:48  curt
281  * Working on lightling and material properties.
282  *
283  * Revision 1.15  1997/12/11 04:43:55  curt
284  * Fixed sun vector and lighting problems.  I thing the moon is now lit
285  * correctly.
286  *
287  * Revision 1.14  1997/12/10 22:37:47  curt
288  * Prepended "fg" on the name of all global structures that didn't have it yet.
289  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
290  *
291  * Revision 1.13  1997/11/25 19:25:32  curt
292  * Changes to integrate Durk's moon/sun code updates + clean up.
293  *
294  * Revision 1.12  1997/11/15 18:16:35  curt
295  * minor tweaks.
296  *
297  * Revision 1.11  1997/10/30 12:38:42  curt
298  * Working on new scenery subsystem.
299  *
300  * Revision 1.10  1997/10/25 03:24:23  curt
301  * Incorporated sun, moon, and star positioning code contributed by Durk Talsma.
302  *
303  * Revision 1.9  1997/09/23 00:29:39  curt
304  * Tweaks to get things to compile with gcc-win32.
305  *
306  * Revision 1.8  1997/09/22 14:44:20  curt
307  * Continuing to try to align stars correctly.
308  *
309  * Revision 1.7  1997/09/16 15:50:30  curt
310  * Working on star alignment and time issues.
311  *
312  * Revision 1.6  1997/09/05 14:17:30  curt
313  * More tweaking with stars.
314  *
315  * Revision 1.5  1997/09/04 02:17:36  curt
316  * Shufflin' stuff.
317  *
318  * Revision 1.4  1997/08/27 21:32:26  curt
319  * Restructured view calculation code.  Added stars.
320  *
321  * Revision 1.3  1997/08/27 03:30:19  curt
322  * Changed naming scheme of basic shared structures.
323  *
324  * Revision 1.2  1997/08/25 20:27:23  curt
325  * Merged in initial HUD and Joystick code.
326  *
327  * Revision 1.1  1997/08/23 01:46:20  curt
328  * Initial revision.
329  *
330  */