00001 #ifndef _AIRPORT_H
00002 #define _AIRPORT_H
00003
00004 #ifdef __GNUG__
00005 #include <vector>
00006 #include <vector.h>
00007 #include <map.h>
00008 using namespace std;
00009 #else
00010 #include <vector>
00011 #include <map>
00012 #endif
00013
00014 #include <ctype.h>
00015 #include <string>
00016 #include <list>
00017 #include <algorithm>
00018 #include <fstream.h>
00019 #include <stdlib.h>
00020 #include <math.h>
00021
00022 #ifdef HPUX
00023 #define atan2 atan2f
00024 #endif
00025
00026 #include "OBJlib.h"
00027 #include "waterGL.h"
00028
00029
00030
00031
00032
00033
00034 #define PI 3.1415926535897932
00035
00036 #define YES 0
00037 #define NO 1
00038 #define QUEUED 2
00039
00040 #define ONE_WAY 0
00041 #define TWO_WAY 1
00042
00043 #define LIGHT_INTERVAL 15
00044
00045
00046
00047
00048
00050
00051 {
00052 vector<float> coords;
00053 };
00054
00056
00057 struct RunwayPiece
00058 {
00059 string handle;
00060 unsigned long thresholdWeight;
00061 float startX, endX, startY, endY, anchorX, anchorY, radius;
00062 int direction;
00063 int maxPlanesQueued;
00064 list<string> planesQueued;
00065 };
00066
00067
00068 struct TerminalPiece
00069 {
00070 int x;
00071 int y;
00072 int xRadius;
00073 int yRadius;
00074 int height;
00075 int theta;
00076 };
00077
00078
00079 struct TowerPiece
00080 {
00081 int x;
00082 int y;
00083 int xRadius;
00084 int yRadius;
00085 int height;
00086 };
00087
00091
00092 struct RunwayResponse
00093 {
00094 int response;
00095 int queuePosition;
00096 int delayTimeGuess;
00097 };
00098
00103
00104 class Airport
00105 {
00106 public:
00109 Airport();
00110
00112 ~Airport();
00113
00115 void Animate();
00116
00119 void Center( double & x, double & y, double & z );
00120
00123 void GetNearestPoint( float planeX, float planeY, float & coordX, float & coordY, float & runwayDirX, float & runwayDirY, string runwayHandle );
00124 void GetNearestPoint( float planeX, float planeY, float & coordX, float & coordY, float & runwayDirX, float & runwayDirY );
00125
00128 string GetNearestRunway( float xPos, float yPos );
00129
00131 const int GetNumRunways();
00132
00134 const int GetNumPlanesQueued( string runwayHandle );
00135
00137 bool IsPlaneQueued( string planeHandle, string runwayHandle );
00138
00141 bool LoadAirport( char * name );
00142
00144 bool Render();
00145
00147 RunwayResponse ReserveRunway( string planeHandle, string runwayHandle );
00148 RunwayResponse ReserveRunway( string planeHandle, float xPos, float yPos );
00149
00151 void SetScale( double newScale );
00152
00156 void SetWaterSpeed( float xSpeed, float ySpeed );
00157
00159 void UnreserveRunway( string planeHandle, string runwayHandle );
00160 void UnreserveRunway( string planeHandle );
00161 private:
00162
00163 void FindLine( float startX, float startY, float endX, float endY, float & m, float & B );
00164
00165
00166 bool InsideRunway( float x, float y, int & numInside );
00167
00168
00169 bool Intersection( float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float & x, float & y);
00170
00171
00172 bool LoadCoast( ifstream & airportInfo, char * buffer );
00173
00174
00175 bool LoadDisplayLists();
00176
00177
00178 bool LoadExtents( ifstream & airportInfo, char * buffer );
00179
00180
00181 bool LoadTowers( ifstream & airportInfo, char * buffer );
00182 bool LoadTerminals( ifstream & airportInfo, char * buffer );
00183 bool LoadRunways( ifstream & airportInfo, char * buffer );
00184
00185
00186 bool LoadModels();
00187
00188
00189 bool LoadTextures();
00190
00191
00192 void RenderLights();
00193
00194
00195 void RenderRunways();
00196 void RenderTerminal( int centerX, int centerY, int radiusX, int radiusY, int height, int theta );
00197 void RenderTower( int centerX, int centerY, int radiusX, int radiusY, int height );
00198 void RenderWater();
00199
00200
00201
00202 void SetupRunwayEdges();
00203
00204
00205
00206 void SetupWater();
00207
00208
00209
00210 bool SkipComments( ifstream & file, char * buffer );
00211
00212
00213
00214 bool SkipSpaces( ifstream & file, char * buffer );
00215
00216
00217
00218
00219
00220 TowerPiece tower;
00221 vector<RunwayPiece> runways;
00222 vector<TerminalPiece> terminals;
00223
00224
00225
00226 vector<Coastline> coast;
00227
00228
00229
00230 vector<WaterGL> water;
00231
00232
00233 map<string, int> runwayHandleMap;
00234
00235
00236
00237 vector<float> runwayEdges;
00238
00239
00240
00241
00242 GLMmodel * towerModel;
00243 GLMmodel * terminalModel;
00244
00245
00246 GLuint airportDisplayList;
00247
00248 int extentX1, extentY1, extentX2, extentY2;
00249
00250 int centerX, centerY;
00251
00252 double scale;
00253
00254
00255
00256
00257
00258 };
00259
00260 #endif