]> git.mxchange.org Git - flightgear.git/blob - Simulator/Objects/obj.cxx
Merge FG_Tools as subdirectory
[flightgear.git] / Simulator / Objects / obj.cxx
1 // obj.cxx -- routines to handle "sorta" WaveFront .obj format files.
2 //
3 // Written by Curtis Olson, started October 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #ifdef HAVE_WINDOWS_H
30 #  include <windows.h>
31 #endif
32
33 #include <stdio.h>
34 #include <string.h>
35 #include <GL/glut.h>
36 #include <XGL/xgl.h>
37
38 // #if defined ( __sun__ )
39 // extern "C" void *memmove(void *, const void *, size_t);
40 // extern "C" void *memset(void *, int, size_t);
41 // #endif
42
43 #include <Include/compiler.h>
44
45 #include STL_STRING
46 #include <map>          // STL
47 #include <ctype.h>      // isdigit()
48
49 #include <Debug/logstream.hxx>
50 #include <Misc/fgstream.hxx>
51 #include <Include/fg_constants.h>
52 #include <Main/options.hxx>
53 #include <Math/mat3.h>
54 #include <Math/fg_random.h>
55 #include <Math/point3d.hxx>
56 #include <Math/polar3d.hxx>
57 #include <Misc/stopwatch.hxx>
58 #include <Scenery/tile.hxx>
59
60 #include "material.hxx"
61 #include "obj.hxx"
62
63 FG_USING_STD(string);
64
65
66 static double normals[MAX_NODES][3];
67
68
69 // given three points defining a triangle, calculate the normal
70 static void calc_normal(double p1[3], double p2[3], 
71                         double p3[3], double normal[3])
72 {
73     double v1[3], v2[3];
74     double temp;
75
76     v1[0] = p2[0] - p1[0]; v1[1] = p2[1] - p1[1]; v1[2] = p2[2] - p1[2];
77     v2[0] = p3[0] - p1[0]; v2[1] = p3[1] - p1[1]; v2[2] = p3[2] - p1[2];
78
79     MAT3cross_product(normal, v1, v2);
80     MAT3_NORMALIZE_VEC(normal,temp);
81
82     // fgPrintf( FG_TERRAIN, FG_DEBUG, "  Normal = %.2f %.2f %.2f\n", 
83     //           normal[0], normal[1], normal[2]);
84 }
85
86
87 #define FG_TEX_CONSTANT 69.0
88
89
90 // Calculate texture coordinates for a given point.
91 static Point3D calc_tex_coords(double *node, const Point3D& ref) {
92     Point3D cp;
93     Point3D pp;
94     // double tmplon, tmplat;
95
96     // cout << "-> " << node[0] << " " << node[1] << " " << node[2] << endl;
97     // cout << "-> " << ref.x() << " " << ref.y() << " " << ref.z() << endl;
98
99     cp = Point3D( node[0] + ref.x(),
100                   node[1] + ref.y(),
101                   node[2] + ref.z() );
102
103     pp = fgCartToPolar3d(cp);
104
105     // tmplon = pp.lon() * RAD_TO_DEG;
106     // tmplat = pp.lat() * RAD_TO_DEG;
107     // cout << tmplon << " " << tmplat << endl;
108
109     pp.setx( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.x(), 11.0) );
110     pp.sety( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.y(), 11.0) );
111
112     if ( pp.x() < 0.0 ) {
113         pp.setx( pp.x() + 11.0 );
114     }
115
116     if ( pp.y() < 0.0 ) {
117         pp.sety( pp.y() + 11.0 );
118     }
119
120     // cout << pp << endl;
121
122     return(pp);
123 }
124
125
126 // Load a .obj file and build the GL fragment list
127 int fgObjLoad( const string& path, fgTILE *t) {
128     fgFRAGMENT fragment;
129     Point3D pp;
130     double approx_normal[3], normal[3] /*, scale = 0.0 */;
131     // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
132     // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
133     GLint display_list = 0;
134     int shading;
135     int in_fragment = 0, in_faces = 0, vncount;
136     int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
137     int last1 = 0, last2 = 0, odd = 0;
138     double (*nodes)[3];
139     Point3D center;
140
141     // printf("loading %s\n", path.c_str() );
142
143     // Attempt to open "path.gz" or "path"
144     fg_gzifstream in( path );
145     if ( ! in ) {
146         FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << path );
147         return 0;
148     }
149
150     shading = current_options.get_shading();
151
152     in_fragment = 0;
153     t->ncount = 0;
154     vncount = 0;
155     t->bounding_radius = 0.0;
156     nodes = t->nodes;
157     center = t->center;
158
159     StopWatch stopwatch;
160     stopwatch.start();
161
162     // ignore initial comments and blank lines. (priming the pump)
163     // in >> skipcomment;
164     string line;
165
166     while ( ! in.eof() ) {
167         string token;
168         char c;
169
170         in >> skipws;
171
172         if ( in.get( c ) && c == '#' ) {
173             // process a comment line
174
175             // getline( in, line );
176             // cout << "comment = " << line << endl;
177
178             in >> token;
179
180             if ( token == "gbs" ) {
181                 // reference point (center offset)
182                 in >> t->center >> t->bounding_radius;
183                 center = t->center;
184                 // cout << "center = " << center 
185                 //      << " radius = " << t->bounding_radius << endl;
186             } else if ( token == "bs" ) {
187                 // reference point (center offset)
188                 in >> fragment.center;
189                 in >> fragment.bounding_radius;
190
191                 // cout << "center = " << fragment.center 
192                 //      << " radius = " << fragment.bounding_radius << endl;
193             } else if ( token == "usemtl" ) {
194                 // material property specification
195
196                 // series of individual triangles
197                 if ( in_faces ) {
198                     xglEnd();
199                 }
200
201                 // this also signals the start of a new fragment
202                 if ( in_fragment ) {
203                     // close out the previous structure and start the next
204                     xglEndList();
205                     // printf("xglEnd(); xglEndList();\n");
206
207                     // update fragment
208                     fragment.display_list = display_list;
209
210                     // push this fragment onto the tile's object list
211                     t->fragment_list.push_back(fragment);
212                 } else {
213                     in_fragment = 1;
214                 }
215
216                 // printf("start of fragment (usemtl)\n");
217
218                 display_list = xglGenLists(1);
219                 xglNewList(display_list, GL_COMPILE);
220                 // printf("xglGenLists(); xglNewList();\n");
221                 in_faces = 0;
222
223                 // reset the existing face list
224                 // printf("cleaning a fragment with %d faces\n", 
225                 //        fragment.faces.size());
226                 fragment.init();
227                 
228                 // scan the material line
229                 string material;
230                 in >> material;
231                 fragment.tile_ptr = t;
232                 
233                 // find this material in the properties list
234                 if ( ! material_mgr.find( material, fragment.material_ptr )) {
235                     FG_LOG( FG_TERRAIN, FG_ALERT, 
236                             "Ack! unknown usemtl name = " << material 
237                             << " in " << path );
238                 }
239                 
240                 // initialize the fragment transformation matrix
241                 /*
242                  for ( i = 0; i < 16; i++ ) {
243                    fragment.matrix[i] = 0.0;
244                  }
245                  fragment.matrix[0] = fragment.matrix[5] =
246                  fragment.matrix[10] = fragment.matrix[15] = 1.0;
247                 */
248             } else {
249                 // unknown comment, just gobble the input untill the
250                 // end of line
251
252                 in >> skipeol;
253             }
254         } else {
255             in.putback( c );
256         
257             in >> token;
258
259             // cout << "token = " << token << endl;
260
261             if ( token == "vn" ) {
262                 // vertex normal
263                 if ( vncount < MAX_NODES ) {
264                     in >> normals[vncount][0]
265                        >> normals[vncount][1]
266                        >> normals[vncount][2];
267                     vncount++;
268                 } else {
269                     FG_LOG( FG_TERRAIN, FG_ALERT, 
270                             "Read too many vertex normals ... dying :-(" );
271                     exit(-1);
272                 }
273             } else if ( token == "v" ) {
274                 // node (vertex)
275                 if ( t->ncount < MAX_NODES ) {
276                     in >> t->nodes[t->ncount][0]
277                        >> t->nodes[t->ncount][1]
278                        >> t->nodes[t->ncount][2];
279                     t->ncount++;
280                 } else {
281                     FG_LOG( FG_TERRAIN, FG_ALERT, 
282                             "Read too many nodes ... dying :-(");
283                     exit(-1);
284                 }
285             } else if ( token == "t" ) {
286                 // start a new triangle strip
287
288                 n1 = n2 = n3 = n4 = 0;
289
290                 // fgPrintf( FG_TERRAIN, FG_DEBUG, 
291                 //           "    new tri strip = %s", line);
292                 in >> n1 >> n2 >> n3;
293                 fragment.add_face(n1, n2, n3);
294
295                 // fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = ");
296
297                 xglBegin(GL_TRIANGLE_STRIP);
298                 // printf("xglBegin(tristrip) %d %d %d\n", n1, n2, n3);
299
300                 odd = 1; 
301                 // scale = 1.0;
302
303                 if ( shading ) {
304                     // Shading model is "GL_SMOOTH" so use precalculated
305                     // (averaged) normals
306                     // MAT3_SCALE_VEC(normal, normals[n1], scale);
307                     xglNormal3dv(normal);
308                     pp = calc_tex_coords(nodes[n1], center);
309                     xglTexCoord2f(pp.lon(), pp.lat());
310                     xglVertex3dv(nodes[n1]);            
311
312                     // MAT3_SCALE_VEC(normal, normals[n2], scale);
313                     xglNormal3dv(normal);
314                     pp = calc_tex_coords(nodes[n2], center);
315                     xglTexCoord2f(pp.lon(), pp.lat());
316                     xglVertex3dv(nodes[n2]);                            
317
318                     // MAT3_SCALE_VEC(normal, normals[n3], scale);
319                     xglNormal3dv(normal);
320                     pp = calc_tex_coords(nodes[n3], center);
321                     xglTexCoord2f(pp.lon(), pp.lat());
322                     xglVertex3dv(nodes[n3]);
323                 } else {
324                     // Shading model is "GL_FLAT" so calculate per face
325                     // normals on the fly.
326                     if ( odd ) {
327                         calc_normal(nodes[n1], nodes[n2], 
328                                     nodes[n3], approx_normal);
329                     } else {
330                         calc_normal(nodes[n2], nodes[n1], 
331                                     nodes[n3], approx_normal);
332                     }
333                     // MAT3_SCALE_VEC(normal, approx_normal, scale);
334                     xglNormal3dv(normal);
335
336                     pp = calc_tex_coords(nodes[n1], center);
337                     xglTexCoord2f(pp.lon(), pp.lat());
338                     xglVertex3dv(nodes[n1]);            
339
340                     pp = calc_tex_coords(nodes[n2], center);
341                     xglTexCoord2f(pp.lon(), pp.lat());
342                     xglVertex3dv(nodes[n2]);            
343                     
344                     pp = calc_tex_coords(nodes[n3], center);
345                     xglTexCoord2f(pp.lon(), pp.lat());
346                     xglVertex3dv(nodes[n3]);            
347                 }
348                 // printf("some normals, texcoords, and vertices\n");
349
350                 odd = 1 - odd;
351                 last1 = n2;
352                 last2 = n3;
353
354                 // There can be three or four values 
355                 char c;
356                 while ( in.get(c) ) {
357                     if ( c == '\n' ) {
358                         break; // only the one
359                     }
360                     if ( isdigit(c) ){
361                         in.putback(c);
362                         in >> n4;
363                         break;
364                     }
365                 }
366
367                 if ( n4 > 0 ) {
368                     fragment.add_face(n3, n2, n4);
369
370                     if ( shading ) {
371                         // Shading model is "GL_SMOOTH"
372                         // MAT3_SCALE_VEC(normal, normals[n4], scale);
373                     } else {
374                         // Shading model is "GL_FLAT"
375                         calc_normal(nodes[n3], nodes[n2], nodes[n4], 
376                                     approx_normal);
377                         // MAT3_SCALE_VEC(normal, approx_normal, scale);
378                     }
379                     xglNormal3dv(normal);
380                     pp = calc_tex_coords(nodes[n4], center);
381                     xglTexCoord2f(pp.lon(), pp.lat());
382                     xglVertex3dv(nodes[n4]);            
383                     
384                     odd = 1 - odd;
385                     last1 = n3;
386                     last2 = n4;
387                     // printf("a normal, texcoord, and vertex (4th)\n");
388                 }
389             } else if ( token == "tf" ) {
390                 // triangle fan
391                 // fgPrintf( FG_TERRAIN, FG_DEBUG, "new fan");
392
393                 xglBegin(GL_TRIANGLE_FAN);
394
395                 in >> n1;
396                 xglNormal3dv(normals[n1]);
397                 pp = calc_tex_coords(nodes[n1], center);
398                 xglTexCoord2f(pp.lon(), pp.lat());
399                 xglVertex3dv(nodes[n1]);
400
401                 in >> n2;
402                 xglNormal3dv(normals[n2]);
403                 pp = calc_tex_coords(nodes[n2], center);
404                 xglTexCoord2f(pp.lon(), pp.lat());
405                 xglVertex3dv(nodes[n2]);
406                 
407                 // read all subsequent numbers until next thing isn't a number
408                 while ( true ) {
409                     in >> skipws;
410
411                     char c;
412                     in.get(c);
413                     in.putback(c);
414                     if ( ! isdigit(c) || in.eof() ) {
415                         break;
416                     }
417
418                     in >> n3;
419                     // cout << "  triangle = " 
420                     //      << n1 << "," << n2 << "," << n3 
421                     //      << endl;
422                     xglNormal3dv(normals[n3]);
423                     pp = calc_tex_coords(nodes[n3], center);
424                     xglTexCoord2f(pp.lon(), pp.lat());
425                     xglVertex3dv(nodes[n3]);
426
427                     fragment.add_face(n1, n2, n3);
428                     n2 = n3;
429                 }
430
431                 xglEnd();
432             } else if ( token == "f" ) {
433                 // unoptimized face
434
435                 if ( !in_faces ) {
436                     xglBegin(GL_TRIANGLES);
437                     // printf("xglBegin(triangles)\n");
438                     in_faces = 1;
439                 }
440
441                 // fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
442                 in >> n1 >> n2 >> n3;
443                 fragment.add_face(n1, n2, n3);
444
445                 // xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
446                 xglNormal3dv(normals[n1]);
447                 pp = calc_tex_coords(nodes[n1], center);
448                 xglTexCoord2f(pp.lon(), pp.lat());
449                 xglVertex3dv(nodes[n1]);
450
451                 xglNormal3dv(normals[n2]);
452                 pp = calc_tex_coords(nodes[n2], center);
453                 xglTexCoord2f(pp.lon(), pp.lat());
454                 xglVertex3dv(nodes[n2]);
455                 
456                 xglNormal3dv(normals[n3]);
457                 pp = calc_tex_coords(nodes[n3], center);
458                 xglTexCoord2f(pp.lon(), pp.lat());
459                 xglVertex3dv(nodes[n3]);
460                 // printf("some normals, texcoords, and vertices (tris)\n");
461             } else if ( token == "q" ) {
462                 // continue a triangle strip
463                 n1 = n2 = 0;
464
465                 // fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ", 
466                 //           line);
467                 in >> n1;
468
469                 // There can be one or two values 
470                 char c;
471                 while ( in.get(c) ) {
472                     if ( c == '\n' ) {
473                         break; // only the one
474                     }
475
476                     if ( isdigit(c) ) {
477                         in.putback(c);
478                         in >> n2;
479                         break;
480                     }
481                 }
482                 // fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2);
483
484                 if ( odd ) {
485                     fragment.add_face(last1, last2, n1);
486                 } else {
487                     fragment.add_face(last2, last1, n1);
488                 }
489
490                 if ( shading ) {
491                     // Shading model is "GL_SMOOTH"
492                     // MAT3_SCALE_VEC(normal, normals[n1], scale);
493                 } else {
494                     // Shading model is "GL_FLAT"
495                     if ( odd ) {
496                         calc_normal(nodes[last1], nodes[last2], nodes[n1], 
497                                     approx_normal);
498                     } else {
499                         calc_normal(nodes[last2], nodes[last1], nodes[n1], 
500                                     approx_normal);
501                     }
502                     // MAT3_SCALE_VEC(normal, approx_normal, scale);
503                 }
504                 xglNormal3dv(normal);
505
506                 pp = calc_tex_coords(nodes[n1], center);
507                 xglTexCoord2f(pp.lon(), pp.lat());
508                 xglVertex3dv(nodes[n1]);
509                 // printf("a normal, texcoord, and vertex (4th)\n");
510    
511                 odd = 1 - odd;
512                 last1 = last2;
513                 last2 = n1;
514
515                 if ( n2 > 0 ) {
516                     // fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n");
517
518                     if ( odd ) {
519                         fragment.add_face(last1, last2, n2);
520                     } else {
521                         fragment.add_face(last2, last1, n2);
522                     }
523
524                     if ( shading ) {
525                         // Shading model is "GL_SMOOTH"
526                         // MAT3_SCALE_VEC(normal, normals[n2], scale);
527                     } else {
528                         // Shading model is "GL_FLAT"
529                         if ( odd ) {
530                             calc_normal(nodes[last1], nodes[last2], 
531                                         nodes[n2], approx_normal);
532                         } else {
533                             calc_normal(nodes[last2], nodes[last1], 
534                                         nodes[n2], approx_normal);
535                         }
536                         // MAT3_SCALE_VEC(normal, approx_normal, scale);
537                     }
538                     xglNormal3dv(normal);
539                 
540                     pp = calc_tex_coords(nodes[n2], center);
541                     xglTexCoord2f(pp.lon(), pp.lat());
542                     xglVertex3dv(nodes[n2]);            
543                     // printf("a normal, texcoord, and vertex (4th)\n");
544
545                     odd = 1 -odd;
546                     last1 = last2;
547                     last2 = n2;
548                 }
549             } else {
550                 FG_LOG( FG_TERRAIN, FG_WARN, "Unknown token in " 
551                         << path << " = " << token );
552             }
553
554             // eat white space before start of while loop so if we are
555             // done with useful input it is noticed before hand.
556             in >> skipws;
557         }
558     }
559
560     if ( in_fragment ) {
561         // close out the previous structure and start the next
562         xglEnd();
563         xglEndList();
564         // printf("xglEnd(); xglEndList();\n");
565         
566         // update fragment
567         fragment.display_list = display_list;
568         
569         // push this fragment onto the tile's object list
570         t->fragment_list.push_back(fragment);
571     }
572
573 #if 0
574     // Draw normal vectors (for visually verifying normals)
575     xglBegin(GL_LINES);
576     xglColor3f(0.0, 0.0, 0.0);
577     for ( i = 0; i < t->ncount; i++ ) {
578         xglVertex3d(t->nodes[i][0],
579                     t->nodes[i][1] ,
580                     t->nodes[i][2]);
581         xglVertex3d(t->nodes[i][0] + 500*normals[i][0],
582                     t->nodes[i][1] + 500*normals[i][1],
583                     t->nodes[i][2] + 500*normals[i][2]);
584     } 
585     xglEnd();
586 #endif
587
588     stopwatch.stop();
589     FG_LOG( FG_TERRAIN, FG_INFO, 
590             "Loaded " << path << " in " 
591             << stopwatch.elapsedSeconds() << " seconds" );
592     
593     return 1;
594 }
595
596
597 // $Log$
598 // Revision 1.15  1999/03/31 13:25:58  curt
599 // Removed some debugging output.
600 //
601 // Revision 1.14  1999/03/30 23:48:24  curt
602 // modifications to obj loader to handle tri fans.
603 //
604 // Revision 1.13  1999/03/27 05:36:03  curt
605 // Alas, I have made non-backwardsly compatible changes to the scenery file
606 //   format.  Thus I have had to make the corresponding changes here in the
607 //   file loader.
608 // Things that do not correspond the the .obj format are placed in comments.
609 //
610 // Revision 1.12  1999/03/02 01:03:25  curt
611 // Tweaks for building with native SGI compilers.
612 //
613 // Revision 1.11  1999/02/26 22:09:59  curt
614 // Added initial support for native SGI compilers.
615 //
616 // Revision 1.10  1998/11/06 21:18:18  curt
617 // Converted to new logstream debugging facility.  This allows release
618 // builds with no messages at all (and no performance impact) by using
619 // the -DFG_NDEBUG flag.
620 //
621 // Revision 1.9  1998/11/06 14:47:06  curt
622 // Changes to track Bernie's updates to fgstream.
623 //
624 // Revision 1.8  1998/10/20 18:33:55  curt
625 // Tweaked texture coordinates, but we still have some problems. :-(
626 //
627 // Revision 1.7  1998/10/20 15:48:44  curt
628 // Removed an extraneous output message.
629 //
630 // Revision 1.6  1998/10/18 01:17:21  curt
631 // Point3D tweaks.
632 //
633 // Revision 1.5  1998/10/16 00:54:39  curt
634 // Converted to Point3D class.
635 //
636 // Revision 1.4  1998/09/15 01:35:07  curt
637 // cleaned up my fragment.num_faces hack :-) to use the STL (no need in
638 // duplicating work.)
639 // Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
640 // removed some unneeded stuff from fgTileMgrCurElev()
641 //
642 // Revision 1.3  1998/09/03 21:27:03  curt
643 // Fixed a serious bug caused by not-quite-correct comment/white space eating
644 // which resulted in mismatched glBegin() glEnd() pairs, incorrect display lists,
645 // and ugly display artifacts.
646 //
647 // Revision 1.2  1998/09/01 19:03:09  curt
648 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
649 //  - The new classes in libmisc.tgz define a stream interface into zlib.
650 //    I've put these in a new directory, Lib/Misc.  Feel free to rename it
651 //    to something more appropriate.  However you'll have to change the
652 //    include directives in all the other files.  Additionally you'll have
653 //    add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
654 //
655 //    The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
656 //    test so I've included the required changes in config.tgz.
657 //
658 //    There are a fair few changes to Simulator/Objects as I've moved
659 //    things around.  Loading tiles is quicker but thats not where the delay
660 //    is.  Tile loading takes a few tenths of a second per file on a P200
661 //    but it seems to be the post-processing that leads to a noticeable
662 //    blip in framerate.  I suppose its time to start profiling to see where
663 //    the delays are.
664 //
665 //    I've included a brief description of each archives contents.
666 //
667 // Lib/Misc/
668 //   zfstream.cxx
669 //   zfstream.hxx
670 //     C++ stream interface into zlib.
671 //     Taken from zlib-1.1.3/contrib/iostream/.
672 //     Minor mods for STL compatibility.
673 //     There's no copyright associated with these so I assume they're
674 //     covered by zlib's.
675 //
676 //   fgstream.cxx
677 //   fgstream.hxx
678 //     FlightGear input stream using gz_ifstream.  Tries to open the
679 //     given filename.  If that fails then filename is examined and a
680 //     ".gz" suffix is removed or appended and that file is opened.
681 //
682 //   stopwatch.hxx
683 //     A simple timer for benchmarking.  Not used in production code.
684 //     Taken from the Blitz++ project.  Covered by GPL.
685 //
686 //   strutils.cxx
687 //   strutils.hxx
688 //     Some simple string manipulation routines.
689 //
690 // Simulator/Airports/
691 //   Load airports database using fgstream.
692 //   Changed fgAIRPORTS to use set<> instead of map<>.
693 //   Added bool fgAIRPORTS::search() as a neater way doing the lookup.
694 //   Returns true if found.
695 //
696 // Simulator/Astro/
697 //   Modified fgStarsInit() to load stars database using fgstream.
698 //
699 // Simulator/Objects/
700 //   Modified fgObjLoad() to use fgstream.
701 //   Modified fgMATERIAL_MGR::load_lib() to use fgstream.
702 //   Many changes to fgMATERIAL.
703 //   Some changes to fgFRAGMENT but I forget what!
704 //
705 // Revision 1.1  1998/08/25 16:51:25  curt
706 // Moved from ../Scenery
707 //
708 // Revision 1.23  1998/08/20 15:16:43  curt
709 // obj.cxx: use more explicit parenthases.
710 // texload.[ch]: use const in function definitions where appropriate.
711 //
712 // Revision 1.22  1998/08/20 15:12:03  curt
713 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
714 // the need for "void" pointers and casts.
715 // Quick hack to count the number of scenery polygons that are being drawn.
716 //
717 // Revision 1.21  1998/08/12 21:13:04  curt
718 // material.cxx: don't load textures if they are disabled
719 // obj.cxx: optimizations from Norman Vine
720 // tile.cxx: minor tweaks
721 // tile.hxx: addition of num_faces
722 // tilemgr.cxx: minor tweaks
723 //
724 // Revision 1.20  1998/07/24 21:42:07  curt
725 // material.cxx: whups, double method declaration with no definition.
726 // obj.cxx: tweaks to avoid errors in SGI's CC.
727 // tile.cxx: optimizations by Norman Vine.
728 // tilemgr.cxx: optimizations by Norman Vine.
729 //
730 // Revision 1.19  1998/07/13 21:01:58  curt
731 // Wrote access functions for current fgOPTIONS.
732 //
733 // Revision 1.18  1998/07/12 03:18:27  curt
734 // Added ground collision detection.  This involved:
735 // - saving the entire vertex list for each tile with the tile records.
736 // - saving the face list for each fragment with the fragment records.
737 // - code to intersect the current vertical line with the proper face in
738 //   an efficient manner as possible.
739 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
740 //
741 // Revision 1.17  1998/07/08 14:47:21  curt
742 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
743 // polare3d.h renamed to polar3d.hxx
744 // fg{Cartesian,Polar}Point3d consolodated.
745 // Added some initial support for calculating local current ground elevation.
746 //
747 // Revision 1.16  1998/07/06 21:34:33  curt
748 // Added using namespace std for compilers that support this.
749 //
750 // Revision 1.15  1998/07/04 00:54:28  curt
751 // Added automatic mipmap generation.
752 //
753 // When rendering fragments, use saved model view matrix from associated tile
754 // rather than recalculating it with push() translate() pop().
755 //
756 // Revision 1.14  1998/06/17 21:36:40  curt
757 // Load and manage multiple textures defined in the Materials library.
758 // Boost max material fagments for each material property to 800.
759 // Multiple texture support when rendering.
760 //
761 // Revision 1.13  1998/06/12 00:58:05  curt
762 // Build only static libraries.
763 // Declare memmove/memset for Sloaris.
764 //
765 // Revision 1.12  1998/06/08 17:57:54  curt
766 // Working first pass at material proporty sorting.
767 //
768 // Revision 1.11  1998/06/06 01:09:31  curt
769 // I goofed on the log message in the last commit ... now fixed.
770 //
771 // Revision 1.10  1998/06/06 01:07:17  curt
772 // Increased per material fragment list size from 100 to 400.
773 // Now correctly draw viewable fragments in per material order.
774 //
775 // Revision 1.9  1998/06/05 22:39:54  curt
776 // Working on sorting by, and rendering by material properties.
777 //
778 // Revision 1.8  1998/06/05 18:19:18  curt
779 // Recognize file, file.gz, and file.obj as scenery object files.
780 //
781 // Revision 1.7  1998/05/24 02:49:09  curt
782 // Implimented fragment level view frustum culling.
783 //
784 // Revision 1.6  1998/05/23 14:09:20  curt
785 // Added tile.cxx and tile.hxx.
786 // Working on rewriting the tile management system so a tile is just a list
787 // fragments, and the fragment record contains the display list for that 
788 // fragment.
789 //
790 // Revision 1.5  1998/05/20 20:53:53  curt
791 // Moved global ref point and radius (bounding sphere info, and offset) to
792 // data file rather than calculating it on the fly.
793 // Fixed polygon winding problem in scenery generation stage rather than
794 // compensating for it on the fly.
795 // Made a fgTILECACHE class.
796 //
797 // Revision 1.4  1998/05/16 13:09:57  curt
798 // Beginning to add support for view frustum culling.
799 // Added some temporary code to calculate bouding radius, until the
800 //   scenery generation tools and scenery can be updated.
801 //
802 // Revision 1.3  1998/05/03 00:48:01  curt
803 // Updated texture coordinate fmod() parameter.
804 //
805 // Revision 1.2  1998/05/02 01:52:14  curt
806 // Playing around with texture coordinates.
807 //
808 // Revision 1.1  1998/04/30 12:35:28  curt
809 // Added a command line rendering option specify smooth/flat shading.
810 //
811 // Revision 1.35  1998/04/28 21:43:26  curt
812 // Wrapped zlib calls up so we can conditionally comment out zlib support.
813 //
814 // Revision 1.34  1998/04/28 01:21:42  curt
815 // Tweaked texture parameter calculations to keep the number smaller.  This
816 // avoids the "swimming" problem.
817 // Type-ified fgTIME and fgVIEW.
818 //
819 // Revision 1.33  1998/04/27 15:58:15  curt
820 // Screwing around with texture coordinate generation ... still needs work.
821 //
822 // Revision 1.32  1998/04/27 03:30:13  curt
823 // Minor transformation adjustments to try to keep scenery tiles closer to
824 // (0, 0, 0)  GLfloats run out of precision at the distances we need to model
825 // the earth, but we can do a bunch of pre-transformations using double math
826 // and then cast to GLfloat once everything is close in where we have less
827 // precision problems.
828 //
829 // Revision 1.31  1998/04/25 15:09:57  curt
830 // Changed "r" to "rb" in gzopen() options.  This fixes bad behavior in win32.
831 //
832 // Revision 1.30  1998/04/24 14:21:08  curt
833 // Added "file.obj.gz" support.
834 //
835 // Revision 1.29  1998/04/24 00:51:07  curt
836 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
837 // Tweaked the scenery file extentions to be "file.obj" (uncompressed)
838 // or "file.obz" (compressed.)
839 //
840 // Revision 1.28  1998/04/22 13:22:44  curt
841 // C++ - ifing the code a bit.
842 //
843 // Revision 1.27  1998/04/18 04:13:17  curt
844 // Added zlib on the fly decompression support for loading scenery objects.
845 //
846 // Revision 1.26  1998/04/03 22:11:36  curt
847 // Converting to Gnu autoconf system.
848 //
849 // Revision 1.25  1998/03/14 00:30:50  curt
850 // Beginning initial terrain texturing experiments.
851 //
852 // Revision 1.24  1998/02/09 21:30:18  curt
853 // Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
854 //
855 // Revision 1.23  1998/02/09 15:07:52  curt
856 // Minor tweaks.
857 //
858 // Revision 1.22  1998/02/01 03:39:54  curt
859 // Minor tweaks.
860 //
861 // Revision 1.21  1998/01/31 00:43:25  curt
862 // Added MetroWorks patches from Carmen Volpe.
863 //
864 // Revision 1.20  1998/01/29 00:51:39  curt
865 // First pass at tile cache, dynamic tile loading and tile unloading now works.
866 //
867 // Revision 1.19  1998/01/27 03:26:42  curt
868 // Playing with new fgPrintf command.
869 //
870 // Revision 1.18  1998/01/19 19:27:16  curt
871 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
872 // This should simplify things tremendously.
873 //
874 // Revision 1.17  1998/01/13 00:23:10  curt
875 // Initial changes to support loading and management of scenery tiles.  Note,
876 // there's still a fair amount of work left to be done.
877 //
878 // Revision 1.16  1997/12/30 23:09:40  curt
879 // Worked on winding problem without luck, so back to calling glFrontFace()
880 // 3 times for each scenery area.
881 //
882 // Revision 1.15  1997/12/30 20:47:51  curt
883 // Integrated new event manager with subsystem initializations.
884 //
885 // Revision 1.14  1997/12/30 01:38:46  curt
886 // Switched back to per vertex normals and smooth shading for terrain.
887 //
888 // Revision 1.13  1997/12/18 23:32:36  curt
889 // First stab at sky dome actually starting to look reasonable. :-)
890 //
891 // Revision 1.12  1997/12/17 23:13:47  curt
892 // Began working on rendering the sky.
893 //
894 // Revision 1.11  1997/12/15 23:55:01  curt
895 // Add xgl wrappers for debugging.
896 // Generate terrain normals on the fly.
897 //
898 // Revision 1.10  1997/12/12 21:41:28  curt
899 // More light/material property tweaking ... still a ways off.
900 //
901 // Revision 1.9  1997/12/12 19:52:57  curt
902 // Working on lightling and material properties.
903 //
904 // Revision 1.8  1997/12/10 01:19:51  curt
905 // Tweaks for verion 0.15 release.
906 //
907 // Revision 1.7  1997/12/08 22:51:17  curt
908 // Enhanced to handle ccw and cw tri-stripe winding.  This is a temporary
909 // admission of defeat.  I will eventually go back and get all the stripes
910 // wound the same way (ccw).
911 //
912 // Revision 1.6  1997/11/25 19:25:35  curt
913 // Changes to integrate Durk's moon/sun code updates + clean up.
914 //
915 // Revision 1.5  1997/11/15 18:16:39  curt
916 // minor tweaks.
917 //
918 // Revision 1.4  1997/11/14 00:26:49  curt
919 // Transform scenery coordinates earlier in pipeline when scenery is being
920 // created, not when it is being loaded.  Precalculate normals for each node
921 // as average of the normals of each containing polygon so Garoude shading is
922 // now supportable.
923 //
924 // Revision 1.3  1997/10/31 04:49:12  curt
925 // Tweaking vertex orders.
926 //
927 // Revision 1.2  1997/10/30 12:38:45  curt
928 // Working on new scenery subsystem.
929 //
930 // Revision 1.1  1997/10/28 21:14:54  curt
931 // Initial revision.
932
933