00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028 #ifndef UTILITY_H
00029 #define UTILITY_H
00030
00031 #include "FlyLegacy.h"
00032
00033
00034
00035
00036
00037 #define MILES_PER_NM (1.151)
00038 #define KM_PER_NM (1.852)
00039 #define METRES_PER_FOOT (0.3048)
00040 #define FEET_PER_NM (6076.0)
00041 #define PI (3.1415926)
00042 #define DEG2RAD (PI / 180.0)
00043 #define RAD2DEG (180.0 / PI)
00044 #define FEET_PER_MILE (5280.0)
00045 #define FEET_PER_METRE (3.2808399)
00046
00047
00048 #define POLAR_CIRCUMFERENCE (double)(1.3104211E+08)
00049 #define FEET_PER_LAT_ARCSEC (double)(1.0111274E+02)
00050
00051
00052 #define EQUATORIAL_CIRCUMFERENCE (double)(1.3147339E+08)
00053
00054
00055 #define MEAN_CIRCUMFERENCE (FEET_PER_NM * 21600)
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 SPosition GeocToGeod (SPosition);
00067
00068
00069
00070
00071 SPosition GeodToGeoc (SPosition);
00072
00073
00074
00075
00076
00077 SVector GeocToCartesian (SPosition);
00078
00079
00080
00081
00082 SPosition CartesianToGeoc (SVector);
00083
00084
00085
00086
00087
00088 SVector GeodToCartesian (SPosition);
00089
00090
00091
00092
00093 SPosition CartesianToGeod (SVector);
00094
00095
00096
00097 void test_geodesy (void);
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 float GreatCircleDistance(SPosition *from, SPosition *to);
00111
00112
00113
00114
00115
00116
00117
00118
00119 SPosition GreatCirclePosition(SPosition *from, SVector *polar);
00120
00121
00122
00123
00124
00125 SVector GreatCirclePolar(SPosition *from, SPosition *to);
00126
00127
00128
00129
00130
00131 SVector VectorSum (SVector v1, SVector v2);
00132
00133
00134
00135
00136 SVector VectorDifference (SVector v1, SVector v2);
00137
00138
00139
00140
00141 double WrapTwoPi (double rad);
00142 double WrapPi (double rad);
00143 double Wrap360 (double deg);
00144 int Wrap360 (int deg);
00145 double Wrap180 (double deg);
00146 float Wrap24 (float hrs);
00147 float Wrap60 (float min);
00148 double FeetPerLonArcsec (double lat);
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 SPosition AddVector(SPosition &from, SVector &v);
00162
00163
00164
00165
00166
00167
00168
00169 SPosition SubtractVector(SPosition &from, SVector &v);
00170
00171
00172
00173
00174
00175 SVector SubtractPosition(SPosition &from, SPosition &to);
00176
00177
00178 float NmToMi (float nm);
00179 float MiToNm (float mi);
00180 float FeetToNm (float feet);
00181 float NmToFeet (float nm);
00182 float FpsToKt (float fps);
00183
00184 double FeetToMetres (double ft);
00185 double MetresToFeet (double m);
00186 float KmToNm (float km);
00187 float NmToKm (float nm);
00188
00189 float RadToDeg (float rad);
00190 double RadToDeg (double rad);
00191 float DegToRad (float deg);
00192 double DegToRad (double deg);
00193
00194 char *TagString (char* s, Tag tag);
00195 Tag StringToTag (const char* s);
00196 void TagToString (char* s, Tag tag);
00197
00198 void FormatPosition (SPosition pos, char* s);
00199 void FormatRADec (double ra, double dec, char* s);
00200 void FormatSiderealTime (double st, char *s);
00201
00202 void TrimTrailingWhitespace (char* s);
00203
00204
00205
00206
00207
00208 EMessageResult SendMessage (SMessage *msg);
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 typedef struct {
00220 union {
00221 struct {
00222 float Y;
00223 float x;
00224 float y;
00225 } Yxy;
00226 struct {
00227 float X;
00228 float Y;
00229 float Z;
00230 } XYZ;
00231 };
00232 } SCIE;
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 void CIE_Yxy_to_XYZ (SCIE in, SCIE &out);
00244
00245
00246
00247
00248 void CIE_XYZ_to_RGB_D65 (SCIE XYZ, sgdVec3 &RGB);
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 void init_globe_tile_table ();
00275 void lat_lon_to_qgt (double latArg, double lonArg, int &x, int &z);
00276 void lat_lon_to_globe_tile (double latArg, double lonArg, int &x, int &z);
00277
00278 void qgt_lon_bounds (int x, double &w, double &e);
00279 void qgt_lat_bounds (int z, double &s, double &n);
00280 void globe_tile_lon_bounds (int x, double &w, double &e);
00281 void globe_tile_lat_bounds (int z, double &s, double &n);
00282
00283 void qgt_position (SPosition pos, int &qx, int &qz, double &x, double &z);
00284 void delta_qgt (SPosition pos, int rx, int rz, double &x, double &z);
00285
00286 float TerrainScale (SPosition pos);
00287 float GlobeTileDistance (void);
00288 SVector PosToFlatCartesian (SPosition pos, int gx, int gz);
00289 SVector PosToFlatCartesian (SPosition pos);
00290 SVector PosToScaledFlatCartesian (SPosition pos);
00291 SVector PosToFlatCartesianQgt (SPosition pos, int x, int z);
00292 SVector PosToFlatCartesianQgt (SPosition pos);
00293 SVector PosToScaledFlatCartesianQgt (SPosition pos);
00294
00295
00296
00297
00298
00299
00300 class CImageTIFF {
00301 public:
00302
00303 CImageTIFF (const char* tifFilename);
00304 ~CImageTIFF (void);
00305
00306
00307 int GetWidth (void);
00308 int GetHeight (void);
00309 GLuint CreateTexture (bool mipmap);
00310
00311 protected:
00312 char name[64];
00313 int width, height, depth;
00314 GLubyte *image;
00315 GLuint texid;
00316 };
00317
00318
00319
00320
00321
00322
00323
00324 class CMaskImage {
00325 public:
00326
00327 CMaskImage (int width, int height);
00328 CMaskImage (int width, int height, const GLubyte *data);
00329 CMaskImage (int width, int height, const char* rawFilename);
00330 CMaskImage (const CMaskImage &src);
00331 ~CMaskImage (void);
00332
00333
00334 int GetWidth (void);
00335 int GetHeight (void);
00336
00337
00338
00339
00340
00341 public:
00342 char name[64];
00343 int width, height;
00344 GLubyte *rawdata;
00345 };
00346
00347
00348
00349
00350
00351
00352
00353 class CRawImage {
00354 public:
00355
00356 CRawImage (const char* rawFilename,
00357 const char* actFilename = NULL,
00358 const char* opaFilename = NULL);
00359 CRawImage (int width,
00360 int height,
00361 const char* rawFilename,
00362 const char* actFilename = NULL,
00363 const char* opaFilename = NULL);
00364 CRawImage (const CRawImage &src);
00365 ~CRawImage (void);
00366
00367
00368 void Init (void);
00369 void Load (const char* rawFilename,
00370 const char* actFilename,
00371 const char* opaFilename = NULL);
00372 int GetWidth (void);
00373 int GetHeight (void);
00374 void SetName (const char* name);
00375 void CreateTransferMaps (void);
00376 GLubyte* GetRGBImageData (void);
00377 GLubyte* GetRGBAImageData (void);
00378
00379 void Copy (const CRawImage &src);
00380 void CopyMasked (const CRawImage *src, const CMaskImage *mask);
00381 void Merge (const CRawImage *raw, const CMaskImage *mask, int actOffset);
00382 void MergeTransitions (const CRawImage *bRaw, const CMaskImage *bMask,
00383 const CRawImage *xRaw, const CMaskImage *xMask,
00384 const CRawImage *yRaw, const CMaskImage *yMask);
00385 GLuint GetTexture (bool mipmap);
00386 void FreeTexture (void);
00387
00388 protected:
00389 char name[64];
00390 int width, height;
00391 GLubyte *actdata;
00392 GLubyte *rawdata;
00393 GLubyte *opadata;
00394 GLuint texid;
00395
00396 GLfloat *xferRed;
00397 GLfloat *xferGreen;
00398 GLfloat *xferBlue;
00399 GLfloat *xferAlpha;
00400 };
00401
00402
00403 class CSunRawImage : public CRawImage {
00404 public:
00405 CSunRawImage (int width,
00406 int height,
00407 const char* rawFilename,
00408 const char* actFilename);
00409 };
00410
00411
00412
00413
00414
00415
00416
00417 class CModelBIN {
00418 public:
00419
00420 CModelBIN (const char* binFilename);
00421 ~CModelBIN ();
00422
00423
00424 ssgEntity *GetSSGEntity (void);
00425
00426 protected:
00427 ssgBranch *top;
00428 CRawImage *rawtexture;
00429 };
00430
00431
00432
00433
00434
00435
00436
00437 class CModelSMF {
00438 public:
00439
00440 CModelSMF (const char* smfFilename);
00441 ~CModelSMF ();
00442
00443
00444 ssgEntity *GetSSGEntity (void);
00445
00446 protected:
00447 ssgTransform *top;
00448 };
00449
00450
00451
00452
00453
00454
00455
00456 class CModelACM {
00457 public:
00458
00459 CModelACM (const char* acmFilename);
00460 ~CModelACM ();
00461
00462
00463 ssgEntity *GetSSGEntity (void);
00464
00465 protected:
00466 ssgTransform *top;
00467 CImageTIFF *tifftexture;
00468 };
00469
00470
00471
00472
00473
00474
00475
00476 SSurface* CreateSurface(int width, int height);
00477 void FreeSurface(SSurface *surface);
00478 void EraseSurface(SSurface *surface);
00479 void EraseSurfaceRGB(SSurface *surface, unsigned int rgb);
00480 void EraseSurfaceRGBA(SSurface *surface, unsigned int rgba);
00481 void DrawDot(SSurface *surface, int x, int y, unsigned int rgbColor);
00482 void DrawLine(SSurface *surface, int x1, int y1, int x2, int y2, unsigned int rgbColor);
00483 void DrawRect(SSurface *surface, int x1, int y1, int x2, int y2, unsigned int rgbColor);
00484 void FillRect(SSurface *surface, int x1, int y1, int x2, int y2, unsigned int rgbColor);
00485 void DrawCircle(SSurface *surface, int xCenter, int yCenter, int radius, unsigned int rgbColor);
00486 unsigned int MakeRGB(unsigned int r, unsigned int g, unsigned int b);
00487 unsigned int MakeRGBA(unsigned int r, unsigned int g, unsigned int b, unsigned int a);
00488 void UnmakeRGB (unsigned int rgb, unsigned int *r, unsigned int *g, unsigned int *b);
00489 void Blit (SSurface *surface);
00490 void BlitTransparent (SSurface *surface, unsigned int rgbTransparentColor);
00491 GLuint TextureFromSurface (SSurface *s, bool mipmap);
00492
00493 int LoadBitmap(SBitmap *bm);
00494 void DrawBitmap(SSurface *surface, SBitmap *bm, int x, int y, int frame);
00495 void DrawBitmapPartial (SSurface *surface, SBitmap *bm, int dx, int dy, int sx1, int sy1, int sx2, int sy2, int frame);
00496 void GetBitmapSize(SBitmap *bm, int *xSize, int *ySize);
00497 int NumBitmapFrames(SBitmap *bm);
00498 void FreeBitmap(SBitmap *bm);
00499
00500
00501
00502
00503
00504
00505
00506 int LoadFont (SFont *font);
00507 void FreeFont (SFont *font);
00508 void DrawChar (SSurface *surface, SFont *font,
00509 int x, int y, unsigned int rgbColour,
00510 char ascii);
00511 void DrawText (SSurface *surface, SFont *font,
00512 int x, int y, unsigned int rgbColour,
00513 const char* text);
00514 void DrawTextC (SSurface *surface, SFont *font,
00515 int x, int y, unsigned int rgbColour,
00516 const char* text);
00517 void DrawTextR (SSurface *surface, SFont *font,
00518 int x, int y, unsigned int rgbColour,
00519 const char* text);
00520 int TextHeight(SFont *font, const char *text);
00521 int TextWidth(SFont *font, const char *text);
00522 int CharHeight(SFont *font, char c);
00523 int CharWidth(SFont *font, char c);
00524 int MaxCharHeight(SFont *font);
00525 int MaxCharWidth(SFont *font);
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00537
00538 class CDataLookup {
00539 public:
00540 virtual float Lookup (float x) = 0;
00541 };
00542
00543 class CDataMap : public CDataLookup, public CStreamObject {
00544 public:
00545
00546 CDataMap (void);
00547
00548
00549 int Read (SStream *stream, Tag tag);
00550
00551
00552 float Lookup (float x);
00553
00554 protected:
00555 CDataLookup *dataSource;
00556 };
00557
00558
00559 #endif // UTILITY_H
00560
00561