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