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