]> git.mxchange.org Git - flightgear.git/blob - Objects/obj.cxx
Moved from ../Scenery
[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
46 #ifdef NEEDNAMESPACESTD
47 using namespace std;
48 #endif
49
50 #include <Debug/fg_debug.h>
51 #include <Include/fg_constants.h>
52 #include <Include/fg_zlib.h>
53 #include <Main/options.hxx>
54 #include <Math/mat3.h>
55 #include <Math/fg_random.h>
56 #include <Math/polar3d.hxx>
57 #include <Scenery/tile.hxx>
58
59 #include "material.hxx"
60 #include "obj.hxx"
61
62
63 static double normals[MAX_NODES][3];
64
65
66 // given three points defining a triangle, calculate the normal
67 static void calc_normal(double p1[3], double p2[3], 
68                         double p3[3], double normal[3])
69 {
70     double v1[3], v2[3];
71     double temp;
72
73     v1[0] = p2[0] - p1[0]; v1[1] = p2[1] - p1[1]; v1[2] = p2[2] - p1[2];
74     v2[0] = p3[0] - p1[0]; v2[1] = p3[1] - p1[1]; v2[2] = p3[2] - p1[2];
75
76     MAT3cross_product(normal, v1, v2);
77     MAT3_NORMALIZE_VEC(normal,temp);
78
79     // fgPrintf( FG_TERRAIN, FG_DEBUG, "  Normal = %.2f %.2f %.2f\n", 
80     //           normal[0], normal[1], normal[2]);
81 }
82
83
84 #define FG_TEX_CONSTANT 128.0
85
86
87 // Calculate texture coordinates for a given point.
88 fgPoint3d calc_tex_coords(double *node, fgPoint3d *ref) {
89     fgPoint3d cp;
90     fgPoint3d pp;
91
92     cp.x = node[0] + ref->x; 
93     cp.y = node[1] + ref->y;
94     cp.z = node[2] + ref->z;
95
96     pp = fgCartToPolar3d(cp);
97
98     pp.lon = fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.lon, 25.0);
99     pp.lat = fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.lat, 25.0);
100
101     return(pp);
102 }
103
104
105 // Load a .obj file and build the GL fragment list
106 int fgObjLoad(char *path, fgTILE *t) {
107     fgFRAGMENT fragment;
108     fgPoint3d pp;
109     char fgpath[256], line[256], material[256];
110     double approx_normal[3], normal[3], scale;
111     // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
112     // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
113     GLint display_list;
114     fgFile f;
115     int shading;
116     int in_fragment, in_faces, vncount, n1, n2, n3, n4;
117     int last1, last2, odd;
118     double (*nodes)[3];
119     fgPoint3d *center;
120
121     // First try "path.gz" (compressed format)
122     strcpy(fgpath, path);
123     strcat(fgpath, ".gz");
124     if ( (f = fgopen(fgpath, "rb")) == NULL ) {
125         // Next try "path" (uncompressed format)
126         strcpy(fgpath, path);
127         if ( (f = fgopen(fgpath, "rb")) == NULL ) {
128             // Next try "path.obj" (uncompressed format)
129             strcat(fgpath, ".gz");
130             if ( (f = fgopen(fgpath, "rb")) == NULL ) {
131                 strcpy(fgpath, path);
132                 fgPrintf( FG_TERRAIN, FG_ALERT, 
133                           "Cannot open file: %s\n", fgpath );
134                 return(0);
135             }
136         }
137     }
138
139     shading = current_options.get_shading();
140
141     in_fragment = 0;
142     t->ncount = 1;
143     vncount = 1;
144     t->bounding_radius = 0.0;
145     nodes = t->nodes;
146     center = &t->center;
147
148     while ( fggets(f, line, 250) != NULL ) {
149         if ( line[0] == '#' ) {
150             // comment -- ignore
151         } else if ( line[0] == '\n' ) {
152             // empty line -- ignore
153         } else if ( strncmp(line, "gbs ", 4) == 0 ) {
154             // reference point (center offset)
155             sscanf(line, "gbs %lf %lf %lf %lf\n", 
156                    &t->center.x, &t->center.y, &t->center.z, 
157                    &t->bounding_radius);
158         } else if ( strncmp(line, "bs ", 3) == 0 ) {
159             // reference point (center offset)
160             sscanf(line, "bs %lf %lf %lf %lf\n", 
161                    &fragment.center.x, &fragment.center.y, &fragment.center.z, 
162                    &fragment.bounding_radius);
163         } else if ( strncmp(line, "v ", 2) == 0 ) {
164             // node (vertex)
165             if ( t->ncount < MAX_NODES ) {
166                 // fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex = %s", line);
167                 sscanf(line, "v %lf %lf %lf\n", 
168                        &(t->nodes[t->ncount][0]), &(t->nodes[t->ncount][1]), 
169                        &(t->nodes[t->ncount][2]));
170
171                 t->ncount++;
172
173             } else {
174                 fgPrintf( FG_TERRAIN, FG_EXIT, 
175                           "Read too many nodes ... dying :-(\n");
176             }
177         } else if ( strncmp(line, "vn ", 3) == 0 ) {
178             // vertex normal
179             if ( vncount < MAX_NODES ) {
180                 // fgPrintf( FG_TERRAIN, FG_DEBUG, "vertex normal = %s", line);
181                 sscanf(line, "vn %lf %lf %lf\n", 
182                        &normals[vncount][0], &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         } else if ( strncmp(line, "usemtl ", 7) == 0 ) {
190             // material property specification
191
192             // this also signals the start of a new fragment
193             if ( in_fragment ) {
194                 // close out the previous structure and start the next
195                 xglEnd();
196                 xglEndList();
197
198                 // update fragment
199                 fragment.display_list = display_list;
200
201                 // push this fragment onto the tile's object list
202                 t->fragment_list.push_back(fragment);
203             } else {
204                 in_fragment = 1;
205             }
206
207             display_list = xglGenLists(1);
208             xglNewList(display_list, GL_COMPILE);
209             in_faces = 0;
210
211             // reset the existing face list
212             // printf("cleaning a fragment with %d faces\n", 
213             //        fragment.faces.size());
214             while ( fragment.faces.size() ) {
215                 //  printf("emptying face list\n");
216                 fragment.faces.pop_front();
217             }
218
219             // scan the material line
220             sscanf(line, "usemtl %s\n", material);
221
222             // give the fragment a pointer back to the tile
223             fragment.tile_ptr = t;
224
225             // find this material in the properties list
226             map < string, fgMATERIAL, less<string> > :: iterator myfind = 
227                 material_mgr.material_map.find(material);
228             if ( myfind == material_mgr.material_map.end() ) {
229                 fgPrintf( FG_TERRAIN, FG_ALERT, 
230                           "Ack! unknown usemtl name = %s in %s\n",
231                           material, path);
232             } else {
233                 fragment.material_ptr = &((*myfind).second);
234             }
235
236             // initialize the fragment transformation matrix
237             /*
238             for ( i = 0; i < 16; i++ ) {
239                 fragment.matrix[i] = 0.0;
240             }
241             fragment.matrix[0] = fragment.matrix[5] =
242                 fragment.matrix[10] = fragment.matrix[15] = 1.0;
243             */
244         
245             // initialize fragment face counter
246             fragment.num_faces = 0;
247                 
248         } else if ( line[0] == 't' ) {
249             // start a new triangle strip
250
251             n1 = n2 = n3 = n4 = 0;
252
253             // fgPrintf( FG_TERRAIN, FG_DEBUG, "    new tri strip = %s", line);
254             sscanf(line, "t %d %d %d %d\n", &n1, &n2, &n3, &n4);
255
256             fragment.add_face(n1, n2, n3);
257
258             // fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = ");
259
260             xglBegin(GL_TRIANGLE_STRIP);
261
262             odd = 1; 
263             scale = 1.0;
264
265             if ( shading ) {
266                 // Shading model is "GL_SMOOTH" so use precalculated
267                 // (averaged) normals
268                 MAT3_SCALE_VEC(normal, normals[n1], scale);
269                 xglNormal3dv(normal);
270                 pp = calc_tex_coords(nodes[n1], center);
271                 xglTexCoord2f(pp.lon, pp.lat);
272                 // xglVertex3d(t->nodes[n1][0],t->nodes[n1][1],t->nodes[n1][2]);
273                 xglVertex3dv(nodes[n1]);                
274
275                 MAT3_SCALE_VEC(normal, normals[n2], scale);
276                 xglNormal3dv(normal);
277                 pp = calc_tex_coords(nodes[n2], center);
278                 xglTexCoord2f(pp.lon, pp.lat);
279                 //xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
280                 xglVertex3dv(nodes[n2]);                                
281
282                 MAT3_SCALE_VEC(normal, normals[n3], scale);
283                 xglNormal3dv(normal);
284                 pp = calc_tex_coords(nodes[n3], center);
285                 xglTexCoord2f(pp.lon, pp.lat);
286                 // xglVertex3d(t->nodes[n3][0],t->nodes[n3][1],t->nodes[n3][2]);
287                 xglVertex3dv(nodes[n3]);                
288             } else {
289                 // Shading model is "GL_FLAT" so calculate per face
290                 // normals on the fly.
291                 if ( odd ) {
292                     calc_normal(nodes[n1], nodes[n2], 
293                                 nodes[n3], approx_normal);
294                 } else {
295                     calc_normal(nodes[n2], nodes[n1], 
296                                 nodes[n3], approx_normal);
297                 }
298                 MAT3_SCALE_VEC(normal, approx_normal, scale);
299                 xglNormal3dv(normal);
300
301                 pp = calc_tex_coords(nodes[n1], center);
302                 xglTexCoord2f(pp.lon, pp.lat);
303                 // xglVertex3d(t->nodes[n1][0],t->nodes[n1][1],t->nodes[n1][2]);
304                 xglVertex3dv(nodes[n1]);                
305
306                 pp = calc_tex_coords(nodes[n2], center);
307                 xglTexCoord2f(pp.lon, pp.lat);
308                 // xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
309                 xglVertex3dv(nodes[n2]);                
310
311                 pp = calc_tex_coords(nodes[n3], center);
312                 xglTexCoord2f(pp.lon, pp.lat);
313                 // xglVertex3d(t->nodes[n3][0],t->nodes[n3][1],t->nodes[n3][2]);
314                 xglVertex3dv(nodes[n3]);                
315             }
316
317             odd = 1 - odd;
318             last1 = n2;
319             last2 = n3;
320
321             if ( n4 > 0 ) {
322                 fragment.add_face(n3, n2, n4);
323
324                 if ( shading ) {
325                     // Shading model is "GL_SMOOTH"
326                     MAT3_SCALE_VEC(normal, normals[n4], scale);
327                 } else {
328                     // Shading model is "GL_FLAT"
329                     calc_normal(nodes[n3], nodes[n2], nodes[n4], 
330                                 approx_normal);
331                     MAT3_SCALE_VEC(normal, approx_normal, scale);
332                 }
333                 xglNormal3dv(normal);
334                 pp = calc_tex_coords(nodes[n4], center);
335                 xglTexCoord2f(pp.lon, pp.lat);
336                 // xglVertex3d(t->nodes[n4][0],t->nodes[n4][1],t->nodes[n4][2]);
337                 xglVertex3dv(nodes[n4]);                
338
339                 odd = 1 - odd;
340                 last1 = n3;
341                 last2 = n4;
342             }
343         } else if ( line[0] == 'f' ) {
344             // unoptimized face
345
346             if ( !in_faces ) {
347                 xglBegin(GL_TRIANGLES);
348                 in_faces = 1;
349             }
350
351             // fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
352             sscanf(line, "f %d %d %d\n", &n1, &n2, &n3);
353
354             fragment.add_face(n1, n2, n3);
355
356             // xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
357             xglNormal3dv(normals[n1]);
358             pp = calc_tex_coords(nodes[n1], center);
359             xglTexCoord2f(pp.lon, pp.lat);
360             // xglVertex3d(t->nodes[n1][0], t->nodes[n1][1], t->nodes[n1][2]);
361             xglVertex3dv(nodes[n1]);
362
363             // xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]);
364             xglNormal3dv(normals[n2]);
365             pp = calc_tex_coords(nodes[n2], center);
366             xglTexCoord2f(pp.lon, pp.lat);
367             // xglVertex3d(t->nodes[n2][0], t->nodes[n2][1], t->nodes[n2][2]);
368             xglVertex3dv(nodes[n2]);
369                 
370             // xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]);
371             xglNormal3dv(normals[n3]);
372             pp = calc_tex_coords(nodes[n3], center);
373             xglTexCoord2f(pp.lon, pp.lat);
374             // xglVertex3d(t->nodes[n3][0], t->nodes[n3][1], t->nodes[n3][2]);
375             xglVertex3dv(nodes[n3]);
376         } else if ( line[0] == 'q' ) {
377             // continue a triangle strip
378             n1 = n2 = 0;
379
380             // fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ", 
381             //           line);
382             sscanf(line, "q %d %d\n", &n1, &n2);
383             // fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2);
384
385             if ( odd ) {
386                 fragment.add_face(last1, last2, n1);
387             } else {
388                 fragment.add_face(last2, last1, n1);
389             }
390
391             if ( shading ) {
392                 // Shading model is "GL_SMOOTH"
393                 MAT3_SCALE_VEC(normal, normals[n1], scale);
394                 xglNormal3dv(normal);
395             } else {
396                 // Shading model is "GL_FLAT"
397                 if ( odd ) {
398                     calc_normal(nodes[last1], nodes[last2], nodes[n1], 
399                                 approx_normal);
400                 } else {
401                     calc_normal(nodes[last2], nodes[last1], nodes[n1], 
402                                 approx_normal);
403                 }
404                 MAT3_SCALE_VEC(normal, approx_normal, scale);
405                 xglNormal3dv(normal);
406             }
407
408             pp = calc_tex_coords(nodes[n1], center);
409             xglTexCoord2f(pp.lon, pp.lat);
410             // xglVertex3d(t->nodes[n1][0], t->nodes[n1][1], t->nodes[n1][2]);
411             xglVertex3dv(nodes[n1]);
412     
413             odd = 1 - odd;
414             last1 = last2;
415             last2 = n1;
416
417             if ( n2 > 0 ) {
418                 // fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n");
419
420                 if ( odd ) {
421                     fragment.add_face(last1, last2, n2);
422                 } else {
423                     fragment.add_face(last2, last1, n2);
424                 }
425
426                 if ( shading ) {
427                     // Shading model is "GL_SMOOTH"
428                     MAT3_SCALE_VEC(normal, normals[n2], scale);
429                     xglNormal3dv(normal);
430                 } else {
431                     // Shading model is "GL_FLAT"
432                     if ( odd ) {
433                         calc_normal(nodes[last1], nodes[last2], 
434                                     nodes[n2], approx_normal);
435                     } else {
436                         calc_normal(nodes[last2], nodes[last1], 
437                                     nodes[n2], approx_normal);
438                     }
439                     MAT3_SCALE_VEC(normal, approx_normal, scale);
440                     xglNormal3dv(normal);
441                 }
442
443                 pp = calc_tex_coords(nodes[n2], center);
444                 xglTexCoord2f(pp.lon, pp.lat);
445                 // xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]);
446                 xglVertex3dv(nodes[n2]);                
447
448                 odd = 1 -odd;
449                 last1 = last2;
450                 last2 = n2;
451             }
452         } else {
453             fgPrintf( FG_TERRAIN, FG_WARN, "Unknown line in %s = %s\n", 
454                       path, line);
455         }
456     }
457
458     if ( in_fragment ) {
459         // close out the previous structure and start the next
460         xglEnd();
461         xglEndList();
462
463         // update fragment
464         fragment.display_list = display_list;
465         
466         // push this fragment onto the tile's object list
467         t->fragment_list.push_back(fragment);
468     }
469
470     // Draw normal vectors (for visually verifying normals)
471     /*
472     xglBegin(GL_LINES);
473     xglColor3f(0.0, 0.0, 0.0);
474     for ( i = 0; i < t->ncount; i++ ) {
475         xglVertex3d(t->nodes[i][0],
476                     t->nodes[i][1] ,
477                     t->nodes[i][2]);
478         xglVertex3d(t->nodes[i][0] + 500*normals[i][0],
479                     t->nodes[i][1] + 500*normals[i][1],
480                     t->nodes[i][2] + 500*normals[i][2]);
481     } 
482     xglEnd();
483     */   
484
485     fgclose(f);
486
487     return(1);
488 }
489
490
491 // $Log$
492 // Revision 1.1  1998/08/25 16:51:25  curt
493 // Moved from ../Scenery
494 //
495 // Revision 1.23  1998/08/20 15:16:43  curt
496 // obj.cxx: use more explicit parenthases.
497 // texload.[ch]: use const in function definitions where appropriate.
498 //
499 // Revision 1.22  1998/08/20 15:12:03  curt
500 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
501 // the need for "void" pointers and casts.
502 // Quick hack to count the number of scenery polygons that are being drawn.
503 //
504 // Revision 1.21  1998/08/12 21:13:04  curt
505 // material.cxx: don't load textures if they are disabled
506 // obj.cxx: optimizations from Norman Vine
507 // tile.cxx: minor tweaks
508 // tile.hxx: addition of num_faces
509 // tilemgr.cxx: minor tweaks
510 //
511 // Revision 1.20  1998/07/24 21:42:07  curt
512 // material.cxx: whups, double method declaration with no definition.
513 // obj.cxx: tweaks to avoid errors in SGI's CC.
514 // tile.cxx: optimizations by Norman Vine.
515 // tilemgr.cxx: optimizations by Norman Vine.
516 //
517 // Revision 1.19  1998/07/13 21:01:58  curt
518 // Wrote access functions for current fgOPTIONS.
519 //
520 // Revision 1.18  1998/07/12 03:18:27  curt
521 // Added ground collision detection.  This involved:
522 // - saving the entire vertex list for each tile with the tile records.
523 // - saving the face list for each fragment with the fragment records.
524 // - code to intersect the current vertical line with the proper face in
525 //   an efficient manner as possible.
526 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
527 //
528 // Revision 1.17  1998/07/08 14:47:21  curt
529 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
530 // polare3d.h renamed to polar3d.hxx
531 // fg{Cartesian,Polar}Point3d consolodated.
532 // Added some initial support for calculating local current ground elevation.
533 //
534 // Revision 1.16  1998/07/06 21:34:33  curt
535 // Added using namespace std for compilers that support this.
536 //
537 // Revision 1.15  1998/07/04 00:54:28  curt
538 // Added automatic mipmap generation.
539 //
540 // When rendering fragments, use saved model view matrix from associated tile
541 // rather than recalculating it with push() translate() pop().
542 //
543 // Revision 1.14  1998/06/17 21:36:40  curt
544 // Load and manage multiple textures defined in the Materials library.
545 // Boost max material fagments for each material property to 800.
546 // Multiple texture support when rendering.
547 //
548 // Revision 1.13  1998/06/12 00:58:05  curt
549 // Build only static libraries.
550 // Declare memmove/memset for Sloaris.
551 //
552 // Revision 1.12  1998/06/08 17:57:54  curt
553 // Working first pass at material proporty sorting.
554 //
555 // Revision 1.11  1998/06/06 01:09:31  curt
556 // I goofed on the log message in the last commit ... now fixed.
557 //
558 // Revision 1.10  1998/06/06 01:07:17  curt
559 // Increased per material fragment list size from 100 to 400.
560 // Now correctly draw viewable fragments in per material order.
561 //
562 // Revision 1.9  1998/06/05 22:39:54  curt
563 // Working on sorting by, and rendering by material properties.
564 //
565 // Revision 1.8  1998/06/05 18:19:18  curt
566 // Recognize file, file.gz, and file.obj as scenery object files.
567 //
568 // Revision 1.7  1998/05/24 02:49:09  curt
569 // Implimented fragment level view frustum culling.
570 //
571 // Revision 1.6  1998/05/23 14:09:20  curt
572 // Added tile.cxx and tile.hxx.
573 // Working on rewriting the tile management system so a tile is just a list
574 // fragments, and the fragment record contains the display list for that 
575 // fragment.
576 //
577 // Revision 1.5  1998/05/20 20:53:53  curt
578 // Moved global ref point and radius (bounding sphere info, and offset) to
579 // data file rather than calculating it on the fly.
580 // Fixed polygon winding problem in scenery generation stage rather than
581 // compensating for it on the fly.
582 // Made a fgTILECACHE class.
583 //
584 // Revision 1.4  1998/05/16 13:09:57  curt
585 // Beginning to add support for view frustum culling.
586 // Added some temporary code to calculate bouding radius, until the
587 //   scenery generation tools and scenery can be updated.
588 //
589 // Revision 1.3  1998/05/03 00:48:01  curt
590 // Updated texture coordinate fmod() parameter.
591 //
592 // Revision 1.2  1998/05/02 01:52:14  curt
593 // Playing around with texture coordinates.
594 //
595 // Revision 1.1  1998/04/30 12:35:28  curt
596 // Added a command line rendering option specify smooth/flat shading.
597 //
598 // Revision 1.35  1998/04/28 21:43:26  curt
599 // Wrapped zlib calls up so we can conditionally comment out zlib support.
600 //
601 // Revision 1.34  1998/04/28 01:21:42  curt
602 // Tweaked texture parameter calculations to keep the number smaller.  This
603 // avoids the "swimming" problem.
604 // Type-ified fgTIME and fgVIEW.
605 //
606 // Revision 1.33  1998/04/27 15:58:15  curt
607 // Screwing around with texture coordinate generation ... still needs work.
608 //
609 // Revision 1.32  1998/04/27 03:30:13  curt
610 // Minor transformation adjustments to try to keep scenery tiles closer to
611 // (0, 0, 0)  GLfloats run out of precision at the distances we need to model
612 // the earth, but we can do a bunch of pre-transformations using double math
613 // and then cast to GLfloat once everything is close in where we have less
614 // precision problems.
615 //
616 // Revision 1.31  1998/04/25 15:09:57  curt
617 // Changed "r" to "rb" in gzopen() options.  This fixes bad behavior in win32.
618 //
619 // Revision 1.30  1998/04/24 14:21:08  curt
620 // Added "file.obj.gz" support.
621 //
622 // Revision 1.29  1998/04/24 00:51:07  curt
623 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
624 // Tweaked the scenery file extentions to be "file.obj" (uncompressed)
625 // or "file.obz" (compressed.)
626 //
627 // Revision 1.28  1998/04/22 13:22:44  curt
628 // C++ - ifing the code a bit.
629 //
630 // Revision 1.27  1998/04/18 04:13:17  curt
631 // Added zlib on the fly decompression support for loading scenery objects.
632 //
633 // Revision 1.26  1998/04/03 22:11:36  curt
634 // Converting to Gnu autoconf system.
635 //
636 // Revision 1.25  1998/03/14 00:30:50  curt
637 // Beginning initial terrain texturing experiments.
638 //
639 // Revision 1.24  1998/02/09 21:30:18  curt
640 // Fixed a nagging problem with terrain tiles not "quite" matching up perfectly.
641 //
642 // Revision 1.23  1998/02/09 15:07:52  curt
643 // Minor tweaks.
644 //
645 // Revision 1.22  1998/02/01 03:39:54  curt
646 // Minor tweaks.
647 //
648 // Revision 1.21  1998/01/31 00:43:25  curt
649 // Added MetroWorks patches from Carmen Volpe.
650 //
651 // Revision 1.20  1998/01/29 00:51:39  curt
652 // First pass at tile cache, dynamic tile loading and tile unloading now works.
653 //
654 // Revision 1.19  1998/01/27 03:26:42  curt
655 // Playing with new fgPrintf command.
656 //
657 // Revision 1.18  1998/01/19 19:27:16  curt
658 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
659 // This should simplify things tremendously.
660 //
661 // Revision 1.17  1998/01/13 00:23:10  curt
662 // Initial changes to support loading and management of scenery tiles.  Note,
663 // there's still a fair amount of work left to be done.
664 //
665 // Revision 1.16  1997/12/30 23:09:40  curt
666 // Worked on winding problem without luck, so back to calling glFrontFace()
667 // 3 times for each scenery area.
668 //
669 // Revision 1.15  1997/12/30 20:47:51  curt
670 // Integrated new event manager with subsystem initializations.
671 //
672 // Revision 1.14  1997/12/30 01:38:46  curt
673 // Switched back to per vertex normals and smooth shading for terrain.
674 //
675 // Revision 1.13  1997/12/18 23:32:36  curt
676 // First stab at sky dome actually starting to look reasonable. :-)
677 //
678 // Revision 1.12  1997/12/17 23:13:47  curt
679 // Began working on rendering the sky.
680 //
681 // Revision 1.11  1997/12/15 23:55:01  curt
682 // Add xgl wrappers for debugging.
683 // Generate terrain normals on the fly.
684 //
685 // Revision 1.10  1997/12/12 21:41:28  curt
686 // More light/material property tweaking ... still a ways off.
687 //
688 // Revision 1.9  1997/12/12 19:52:57  curt
689 // Working on lightling and material properties.
690 //
691 // Revision 1.8  1997/12/10 01:19:51  curt
692 // Tweaks for verion 0.15 release.
693 //
694 // Revision 1.7  1997/12/08 22:51:17  curt
695 // Enhanced to handle ccw and cw tri-stripe winding.  This is a temporary
696 // admission of defeat.  I will eventually go back and get all the stripes
697 // wound the same way (ccw).
698 //
699 // Revision 1.6  1997/11/25 19:25:35  curt
700 // Changes to integrate Durk's moon/sun code updates + clean up.
701 //
702 // Revision 1.5  1997/11/15 18:16:39  curt
703 // minor tweaks.
704 //
705 // Revision 1.4  1997/11/14 00:26:49  curt
706 // Transform scenery coordinates earlier in pipeline when scenery is being
707 // created, not when it is being loaded.  Precalculate normals for each node
708 // as average of the normals of each containing polygon so Garoude shading is
709 // now supportable.
710 //
711 // Revision 1.3  1997/10/31 04:49:12  curt
712 // Tweaking vertex orders.
713 //
714 // Revision 1.2  1997/10/30 12:38:45  curt
715 // Working on new scenery subsystem.
716 //
717 // Revision 1.1  1997/10/28 21:14:54  curt
718 // Initial revision.
719
720