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