]> git.mxchange.org Git - flightgear.git/blob - Main/fg_init.c
1f223ecc7898160047d93874e4fec82ac5b238e5
[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/astro.h"
42 #include "../Scenery/scenery.h"
43 #include "../Time/fg_time.h"
44 #include "../Time/sunpos.h"
45 #include "../Weather/weather.h"
46
47
48 extern int show_hud;             /* HUD state */
49
50
51 /* General house keeping initializations */
52
53 void fgInitGeneral( void ) {
54     struct GENERAL *g;
55
56     g = &general;
57
58     /* seed the random number generater */
59     fg_srandom();
60
61     /* determine the fg root path */
62     if ( (g->root_dir = getenv("FG_ROOT")) == NULL ) {
63         /* environment variable not defined */
64         printf("FG_ROOT needs to be defined!  See the documentation.\n");
65         exit(0);
66     } 
67     printf("FG_ROOT = %s\n", g->root_dir);
68 }
69
70
71 /* This is the top level init routine which calls all the other
72  * initialization routines.  If you are adding a subsystem to flight
73  * gear, its initialization call should located in this routine.*/
74
75 void fgInitSubsystems( void ) {
76     double cur_elev;
77
78     struct FLIGHT *f;
79     struct fgTIME *t;
80     struct VIEW *v;
81
82     f = &current_aircraft.flight;
83     t = &cur_time_params;
84     v = &current_view;
85
86
87     /****************************************************************
88      * The following section sets up the flight model EOM parameters and 
89      * should really be read in from one or more files.
90      ****************************************************************/
91
92     /* Globe Aiport, AZ */
93     FG_Runway_longitude = -398391.28;
94     FG_Runway_latitude = 120070.41;
95     FG_Runway_altitude = 3234.5;
96     FG_Runway_heading = 102.0 * DEG_TO_RAD;
97
98     /* Initial Position at GLOBE airport */
99     FG_Longitude = ( -398391.28 / 3600.0 ) * DEG_TO_RAD;
100     FG_Latitude  = (  120070.41 / 3600.0 ) * DEG_TO_RAD;
101     FG_Altitude = FG_Runway_altitude + 3.758099;
102     FG_Altitude = 10000;
103     
104     /* Initial Position north of the city of Globe */
105     /* FG_Longitude = ( -398673.28 / 3600.0 ) * DEG_TO_RAD; */
106     /* FG_Latitude  = (  120625.64 / 3600.0 ) * DEG_TO_RAD; */
107     /* FG_Altitude = 0.0 + 3.758099; */
108
109     /* Initial Position: 10125 Jewell St. NE */
110     /* FG_Longitude = ( -93.15 ) * DEG_TO_RAD; */
111     /* FG_Latitude  = (  45.15 ) * DEG_TO_RAD; */
112     /* FG_Altitude = FG_Runway_altitude + 3.758099; */
113
114     /* A random test position */
115     /* FG_Longitude = ( 88128.00 / 3600.0 ) * DEG_TO_RAD; */
116     /* FG_Latitude  = ( 93312.00 / 3600.0 ) * DEG_TO_RAD; */
117
118     printf("Initial position is: (%.4f, %.4f, %.2f)\n", 
119            FG_Longitude * RAD_TO_DEG, FG_Latitude * RAD_TO_DEG, 
120            FG_Altitude * FEET_TO_METER);
121
122       /* Initial Velocity */
123     FG_V_north = 0.0 /*  7.287719E+00 */;
124     FG_V_east  = 0.0 /*  1.521770E+03 */;
125     FG_V_down  = 0.0 /* -1.265722E-05 */;
126
127     /* Initial Orientation */
128     FG_Phi   = -2.658474E-06;
129     FG_Theta =  7.401790E-03;
130     FG_Psi   =  270.0 * DEG_TO_RAD;
131     /* FG_Psi   =  0.0 * DEG_TO_RAD; */
132
133     /* Initial Angular B rates */
134     FG_P_body = 7.206685E-05;
135     FG_Q_body = 0.000000E+00;
136     FG_R_body = 9.492658E-05;
137
138     FG_Earth_position_angle = 0.000000E+00;
139
140     /* Mass properties and geometry values */
141     FG_Mass = 8.547270E+01;
142     FG_I_xx = 1.048000E+03;
143     FG_I_yy = 3.000000E+03;
144     FG_I_zz = 3.530000E+03;
145     FG_I_xz = 0.000000E+00;
146
147     /* CG position w.r.t. ref. point */
148     FG_Dx_cg = 0.000000E+00;
149     FG_Dy_cg = 0.000000E+00;
150     FG_Dz_cg = 0.000000E+00;
151
152     /* Set initial position and slew parameters */
153     /* fgSlewInit(-398391.3, 120070.41, 244, 3.1415); */ /* GLOBE Airport */
154     /* fgSlewInit(-335340,162540, 15, 4.38); */
155     /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */
156
157     /* Initialize "time" */
158     fgTimeInit(t);
159     fgTimeUpdate(f, t);
160
161     /* Initialize shared sun position and sun_vec */
162     fgUpdateSunPos(scenery.center);
163
164     /* Initialize view parameters */
165     fgViewInit(v);
166
167     /* Initialize the weather modeling subsystem */
168     fgWeatherInit();
169
170     /* Initialize the Cockpit subsystem */
171     if( fgCockpitInit( current_aircraft ) == NULL )
172     {
173         printf( "Error in Cockpit initialization!\n" );
174         exit( 1 );
175     }
176
177     /* Initialize Astronomical Objects */
178     fgAstroInit();
179
180     /* Initialize the Scenery Management subsystem */
181     fgSceneryInit();
182
183     /* Tell the Scenery Management system where we are so it can load
184      * the correct scenery data */
185     fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude);
186
187
188     /* I'm just sticking this here for now, it should probably move 
189      * eventually */
190     cur_elev = mesh_altitude(FG_Longitude * RAD_TO_DEG * 3600.0, 
191                              FG_Latitude  * RAD_TO_DEG * 3600.0);
192     printf("Ground elevation is %.2f meters here.\n", cur_elev);
193     if ( cur_elev > -9990.0 ) {
194         FG_Runway_altitude = cur_elev * METER_TO_FEET;
195     }
196
197     if ( FG_Altitude < FG_Runway_altitude ) {
198         FG_Altitude = FG_Runway_altitude + 3.758099;
199     }
200     printf("Updated position is: (%.4f, %.4f, %.2f)\n", 
201            FG_Latitude * RAD_TO_DEG, FG_Longitude * RAD_TO_DEG, 
202            FG_Altitude * FEET_TO_METER);
203     /* end of thing that I just stuck in that I should probably move */
204
205
206     /* Initialize the flight model subsystem data structures base on
207      * above values */
208     fgFlightModelInit( FG_LARCSIM, f, 1.0 / DEFAULT_MODEL_HZ );
209
210     /* To HUD or not to HUD */
211     show_hud = 1;
212
213     /* Joystick support */
214     fgJoystickInit( 0 );
215 }
216
217
218 /* $Log$
219 /* Revision 1.13  1997/11/25 19:25:32  curt
220 /* Changes to integrate Durk's moon/sun code updates + clean up.
221 /*
222  * Revision 1.12  1997/11/15 18:16:35  curt
223  * minor tweaks.
224  *
225  * Revision 1.11  1997/10/30 12:38:42  curt
226  * Working on new scenery subsystem.
227  *
228  * Revision 1.10  1997/10/25 03:24:23  curt
229  * Incorporated sun, moon, and star positioning code contributed by Durk Talsma.
230  *
231  * Revision 1.9  1997/09/23 00:29:39  curt
232  * Tweaks to get things to compile with gcc-win32.
233  *
234  * Revision 1.8  1997/09/22 14:44:20  curt
235  * Continuing to try to align stars correctly.
236  *
237  * Revision 1.7  1997/09/16 15:50:30  curt
238  * Working on star alignment and time issues.
239  *
240  * Revision 1.6  1997/09/05 14:17:30  curt
241  * More tweaking with stars.
242  *
243  * Revision 1.5  1997/09/04 02:17:36  curt
244  * Shufflin' stuff.
245  *
246  * Revision 1.4  1997/08/27 21:32:26  curt
247  * Restructured view calculation code.  Added stars.
248  *
249  * Revision 1.3  1997/08/27 03:30:19  curt
250  * Changed naming scheme of basic shared structures.
251  *
252  * Revision 1.2  1997/08/25 20:27:23  curt
253  * Merged in initial HUD and Joystick code.
254  *
255  * Revision 1.1  1997/08/23 01:46:20  curt
256  * Initial revision.
257  *
258  */