1 /**************************************************************************
2 * fg_init.c -- Flight Gear top level initialization routines
4 * Written by Curtis Olson, started August 1997.
6 * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
23 * (Log is kept at end of this file)
24 **************************************************************************/
32 #include "../constants.h"
33 #include "../general.h"
35 #include "../Aircraft/aircraft.h"
36 #include "../Cockpit/cockpit.h"
37 #include "../Joystick/joystick.h"
38 #include "../Math/fg_random.h"
39 #include "../Scenery/mesh.h"
40 #include "../Scenery/scenery.h"
41 #include "../Scenery/stars.h"
42 #include "../Time/sunpos.h"
43 #include "../Weather/weather.h"
46 extern int show_hud; /* HUD state */
49 /* General house keeping initializations */
51 void fgInitGeneral( void ) {
56 /* seed the random number generater */
59 /* determine the fg root path */
60 if ( (g->root_dir = getenv("FG_ROOT")) == NULL ) {
61 /* environment variable not defined */
62 printf("FG_ROOT needs to be defined! See the documentation.\n");
65 printf("FG_ROOT = %s\n", g->root_dir);
69 /* This is the top level init routine which calls all the other
70 * initialization routines. If you are adding a subsystem to flight
71 * gear, its initialization call should located in this routine.*/
73 void fgInitSubsystems( void ) {
78 f = ¤t_aircraft.flight;
80 /****************************************************************
81 * The following section sets up the flight model EOM parameters and
82 * should really be read in from one or more files.
83 ****************************************************************/
85 /* Globe Aiport, AZ */
86 FG_Runway_altitude = 3234.5;
87 FG_Runway_latitude = 120070.41;
88 FG_Runway_longitude = -398391.28;
89 FG_Runway_heading = 102.0 * DEG_TO_RAD;
91 /* Initial Position at GLOBE airport */
92 FG_Latitude = ( 120070.41 / 3600.0 ) * DEG_TO_RAD;
93 FG_Longitude = ( -398391.28 / 3600.0 ) * DEG_TO_RAD;
94 FG_Altitude = FG_Runway_altitude + 3.758099;
96 /* Initial Position north of the city of Globe */
97 /* FG_Latitude = ( 120625.64 / 3600.0 ) * DEG_TO_RAD; */
98 /* FG_Longitude = ( -398673.28 / 3600.0 ) * DEG_TO_RAD; */
99 /* FG_Altitude = 0.0 + 3.758099; */
101 printf("Initial position is: (%.4f, %.4f, %.2f)\n",
102 FG_Latitude * RAD_TO_DEG, FG_Longitude * RAD_TO_DEG,
103 FG_Altitude * FEET_TO_METER);
105 /* Initial Velocity */
106 FG_V_north = 0.0 /* 7.287719E+00 */;
107 FG_V_east = 0.0 /* 1.521770E+03 */;
108 FG_V_down = 0.0 /* -1.265722E-05 */;
110 /* Initial Orientation */
111 FG_Phi = -2.658474E-06;
112 FG_Theta = 7.401790E-03;
113 FG_Psi = 270.0 * DEG_TO_RAD;
114 /* FG_Psi = 0.0 * DEG_TO_RAD; */
116 /* Initial Angular B rates */
117 FG_P_body = 7.206685E-05;
118 FG_Q_body = 0.000000E+00;
119 FG_R_body = 9.492658E-05;
121 FG_Earth_position_angle = 0.000000E+00;
123 /* Mass properties and geometry values */
124 FG_Mass = 8.547270E+01;
125 FG_I_xx = 1.048000E+03;
126 FG_I_yy = 3.000000E+03;
127 FG_I_zz = 3.530000E+03;
128 FG_I_xz = 0.000000E+00;
130 /* CG position w.r.t. ref. point */
131 FG_Dx_cg = 0.000000E+00;
132 FG_Dy_cg = 0.000000E+00;
133 FG_Dz_cg = 0.000000E+00;
135 /* Set initial position and slew parameters */
136 /* fgSlewInit(-398391.3, 120070.41, 244, 3.1415); */ /* GLOBE Airport */
137 /* fgSlewInit(-335340,162540, 15, 4.38); */
138 /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */
140 /* Initialize shared sun position and sun_vec */
143 /* Initialize the weather modeling subsystem */
146 /* Initialize the Cockpit subsystem */
147 fgCockpitInit( current_aircraft );
149 /* Initialize the Stars subsystem */
152 /* Initialize the Scenery Management subsystem */
155 /* Tell the Scenery Management system where we are so it can load
156 * the correct scenery data */
157 fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude);
160 /* I'm just sticking this here for now, it should probably move
162 cur_elev = mesh_altitude(FG_Longitude * RAD_TO_DEG * 3600.0,
163 FG_Latitude * RAD_TO_DEG * 3600.0);
164 printf("Ground elevation is %.2f meters here.\n", cur_elev);
165 if ( cur_elev > -9990.0 ) {
166 FG_Runway_altitude = cur_elev * METER_TO_FEET;
169 if ( FG_Altitude < FG_Runway_altitude ) {
170 FG_Altitude = FG_Runway_altitude + 3.758099;
172 printf("Updated position is: (%.4f, %.4f, %.2f)\n",
173 FG_Latitude * RAD_TO_DEG, FG_Longitude * RAD_TO_DEG,
174 FG_Altitude * FEET_TO_METER);
175 /* end of thing that I just stuck in that I should probably move */
178 /* Initialize the flight model subsystem data structures base on
180 fgFlightModelInit( FG_LARCSIM, f, 1.0 / DEFAULT_MODEL_HZ );
182 /* To HUD or not to HUD */
185 /* Joystick support */
191 /* Revision 1.3 1997/08/27 03:30:19 curt
192 /* Changed naming scheme of basic shared structures.
194 * Revision 1.2 1997/08/25 20:27:23 curt
195 * Merged in initial HUD and Joystick code.
197 * Revision 1.1 1997/08/23 01:46:20 curt