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