]> git.mxchange.org Git - flightgear.git/blob - Main/fg_init.c
Initial revision.
[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
32 #include "../constants.h"
33 #include "../general.h"
34
35 #include "../Aircraft/aircraft.h"
36 #include "../Math/fg_random.h"
37 #include "../Scenery/mesh.h"
38 #include "../Scenery/scenery.h"
39 #include "../Time/sunpos.h"
40 #include "../Weather/weather.h"
41
42
43 /* General house keeping initializations */
44
45 void fgInitGeneral( void ) {
46     struct general_params *g;
47
48     g = &general;
49
50     /* seed the random number generater */
51     fg_srandom();
52
53     /* determine the fg root path */
54     if ( (g->root_dir = getenv("FG_ROOT")) == NULL ) {
55         /* environment variable not defined */
56         printf("FG_ROOT needs to be defined!  See the documentation.\n");
57         exit(0);
58     } 
59     printf("FG_ROOT = %s\n", g->root_dir);
60 }
61
62
63 /* This is the top level init routine which calls all the other
64  * initialization routines.  If you are adding a subsystem to flight
65  * gear, its initialization call should located in this routine.*/
66
67 void fgInitSubsystems( void ) {
68     double cur_elev;
69
70     struct flight_params *f;
71
72     f = &current_aircraft.flight;
73
74     /****************************************************************
75      * The following section sets up the flight model EOM parameters and 
76      * should really be read in from one or more files.
77      ****************************************************************/
78
79     /* Globe Aiport, AZ */
80     FG_Runway_altitude = 3234.5;
81     FG_Runway_latitude = 120070.41;
82     FG_Runway_longitude = -398391.28;
83     FG_Runway_heading = 102.0 * DEG_TO_RAD;
84
85     /* Initial Position at GLOBE airport */
86     FG_Latitude  = (  120070.41 / 3600.0 ) * DEG_TO_RAD;
87     FG_Longitude = ( -398391.28 / 3600.0 ) * DEG_TO_RAD;
88     FG_Altitude = FG_Runway_altitude + 3.758099;
89
90     /* Initial Position north of the city of Globe */
91     /* FG_Latitude  = (  120625.64 / 3600.0 ) * DEG_TO_RAD; */
92     /* FG_Longitude = ( -398673.28 / 3600.0 ) * DEG_TO_RAD; */
93     /* FG_Altitude = 0.0 + 3.758099; */
94
95     printf("Initial position is: (%.4f, %.4f, %.2f)\n", 
96            FG_Latitude * RAD_TO_DEG, FG_Longitude * RAD_TO_DEG, 
97            FG_Altitude * FEET_TO_METER);
98
99       /* Initial Velocity */
100     FG_V_north = 0.0 /*  7.287719E+00 */;
101     FG_V_east  = 0.0 /*  1.521770E+03 */;
102     FG_V_down  = 0.0 /* -1.265722E-05 */;
103
104     /* Initial Orientation */
105     FG_Phi   = -2.658474E-06;
106     FG_Theta =  7.401790E-03;
107     FG_Psi   =  270.0 * DEG_TO_RAD;
108     /* FG_Psi   =  0.0 * DEG_TO_RAD; */
109
110     /* Initial Angular B rates */
111     FG_P_body = 7.206685E-05;
112     FG_Q_body = 0.000000E+00;
113     FG_R_body = 9.492658E-05;
114
115     FG_Earth_position_angle = 0.000000E+00;
116
117     /* Mass properties and geometry values */
118     FG_Mass = 8.547270E+01;
119     FG_I_xx = 1.048000E+03;
120     FG_I_yy = 3.000000E+03;
121     FG_I_zz = 3.530000E+03;
122     FG_I_xz = 0.000000E+00;
123
124     /* CG position w.r.t. ref. point */
125     FG_Dx_cg = 0.000000E+00;
126     FG_Dy_cg = 0.000000E+00;
127     FG_Dz_cg = 0.000000E+00;
128
129     /* Set initial position and slew parameters */
130     /* fgSlewInit(-398391.3, 120070.41, 244, 3.1415); */ /* GLOBE Airport */
131     /* fgSlewInit(-335340,162540, 15, 4.38); */
132     /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */
133
134     /* Initialize shared sun position and sun_vec */
135     fgUpdateSunPos();
136
137     /* Initialize the weather modeling subsystem */
138     fgWeatherInit();
139
140     /* Initialize the Scenery Management subsystem */
141     fgSceneryInit();
142
143     /* Tell the Scenery Management system where we are so it can load
144      * the correct scenery data */
145     fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude);
146
147
148     /* I'm just sticking this here for now, it should probably move 
149      * eventually */
150     cur_elev = mesh_altitude(FG_Longitude * RAD_TO_DEG * 3600.0, 
151                              FG_Latitude  * RAD_TO_DEG * 3600.0);
152     printf("Ground elevation is %.2f meters here.\n", cur_elev);
153     if ( cur_elev > -9990.0 ) {
154         FG_Runway_altitude = cur_elev * METER_TO_FEET;
155     }
156
157     if ( FG_Altitude < FG_Runway_altitude ) {
158         FG_Altitude = FG_Runway_altitude + 3.758099;
159     }
160     printf("Updated position is: (%.4f, %.4f, %.2f)\n", 
161            FG_Latitude * RAD_TO_DEG, FG_Longitude * RAD_TO_DEG, 
162            FG_Altitude * FEET_TO_METER);
163     /* end of thing that I just stuck in that I should probably move */
164
165
166     /* Initialize the flight model subsystem data structures base on
167      * above values */
168     fgFlightModelInit( FG_LARCSIM, f, 1.0 / DEFAULT_MODEL_HZ );
169 }
170
171
172 /* $Log$
173 /* Revision 1.1  1997/08/23 01:46:20  curt
174 /* Initial revision.
175 /*
176  */