1 // obj.cxx -- routines to handle "sorta" WaveFront .obj format files.
3 // Written by Curtis Olson, started October 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
28 #ifdef FG_MATH_EXCEPTION_CLASH
35 // #if defined ( __sun__ )
36 // extern "C" void *memmove(void *, const void *, size_t);
37 // extern "C" void *memset(void *, int, size_t);
40 #include <simgear/compiler.h>
44 #include <vector> // STL
45 #include <ctype.h> // isdigit()
47 #include <simgear/constants.h>
48 #include <simgear/debug/logstream.hxx>
49 #include <simgear/math/fg_geodesy.hxx>
50 #include <simgear/math/fg_random.h>
51 #include <simgear/math/point3d.hxx>
52 #include <simgear/math/polar3d.hxx>
53 #include <simgear/misc/fgstream.hxx>
54 #include <simgear/misc/stopwatch.hxx>
55 #include <simgear/misc/texcoord.hxx>
57 #include <Main/options.hxx>
58 #include <Scenery/tileentry.hxx>
60 #include "materialmgr.hxx"
67 typedef vector < int > int_list;
68 typedef int_list::iterator int_list_iterator;
69 typedef int_list::const_iterator int_point_list_iterator;
72 static double normals[FG_MAX_NODES][3];
73 static double tex_coords[FG_MAX_NODES*3][3];
76 // given three points defining a triangle, calculate the normal
77 static void calc_normal(Point3D p1, Point3D p2,
78 Point3D p3, sgVec3 normal)
82 v1[0] = p2[0] - p1[0]; v1[1] = p2[1] - p1[1]; v1[2] = p2[2] - p1[2];
83 v2[0] = p3[0] - p1[0]; v2[1] = p3[1] - p1[1]; v2[2] = p3[2] - p1[2];
85 sgVectorProductVec3( normal, v1, v2 );
86 sgNormalizeVec3( normal );
88 // fgPrintf( FG_TERRAIN, FG_DEBUG, " Normal = %.2f %.2f %.2f\n",
89 // normal[0], normal[1], normal[2]);
93 #define FG_TEX_CONSTANT 69.0
95 // Calculate texture coordinates for a given point.
96 static Point3D local_calc_tex_coords(const Point3D& node, const Point3D& ref) {
99 // double tmplon, tmplat;
101 // cout << "-> " << node[0] << " " << node[1] << " " << node[2] << endl;
102 // cout << "-> " << ref.x() << " " << ref.y() << " " << ref.z() << endl;
104 cp = Point3D( node[0] + ref.x(),
108 pp = fgCartToPolar3d(cp);
110 // tmplon = pp.lon() * RAD_TO_DEG;
111 // tmplat = pp.lat() * RAD_TO_DEG;
112 // cout << tmplon << " " << tmplat << endl;
114 pp.setx( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.x(), 11.0) );
115 pp.sety( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.y(), 11.0) );
117 if ( pp.x() < 0.0 ) {
118 pp.setx( pp.x() + 11.0 );
121 if ( pp.y() < 0.0 ) {
122 pp.sety( pp.y() + 11.0 );
125 // cout << pp << endl;
131 // Generate a generic ocean tile on the fly
132 ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
135 fragment.tile_ptr = t;
137 ssgSimpleState *state = NULL;
139 ssgBranch *tile = new ssgBranch () ;
140 tile -> setName ( (char *)path.c_str() ) ;
142 // find Ocean material in the properties list
143 if ( ! material_mgr.find( "Ocean", fragment.material_ptr )) {
144 FG_LOG( FG_TERRAIN, FG_ALERT,
145 "Ack! unknown usemtl name = " << "Ocean"
149 // set the texture width and height values for this
151 FGMaterial m = fragment.material_ptr->get_m();
152 double tex_width = m.get_xsize();
153 // double tex_height = m.get_ysize();
156 state = fragment.material_ptr->get_state();
158 // Calculate center point
159 FGBucket b = t->tile_bucket;
160 double clon = b.get_center_lon();
161 double clat = b.get_center_lat();
162 double height = b.get_height();
163 double width = b.get_width();
165 Point3D center = fgGeodToCart(Point3D(clon*DEG_TO_RAD,clat*DEG_TO_RAD,0.0));
167 fragment.center = center;
168 // cout << "center = " << center << endl;;
170 // Caculate corner vertices
172 geod[0] = Point3D( clon - width/2.0, clat - height/2.0, 0.0 );
173 geod[1] = Point3D( clon + width/2.0, clat - height/2.0, 0.0 );
174 geod[2] = Point3D( clon + width/2.0, clat + height/2.0, 0.0 );
175 geod[3] = Point3D( clon - width/2.0, clat + height/2.0, 0.0 );
179 for ( i = 0; i < 4; ++i ) {
180 rad[i] = Point3D( geod[i].x() * DEG_TO_RAD, geod[i].y() * DEG_TO_RAD,
184 Point3D cart[4], rel[4];
186 for ( i = 0; i < 4; ++i ) {
187 cart[i] = fgGeodToCart(rad[i]);
188 rel[i] = cart[i] - center;
189 t->nodes.push_back( rel[i] );
190 // cout << "corner " << i << " = " << cart[i] << endl;
195 // Calculate bounding radius
196 t->bounding_radius = center.distance3D( cart[0] );
197 fragment.bounding_radius = t->bounding_radius;
198 // cout << "bounding radius = " << t->bounding_radius << endl;
202 for ( i = 0; i < 4; ++i ) {
203 normals[i] = cart[i];
204 double length = normals[i].distance3D( Point3D(0.0) );
205 normals[i] /= length;
206 // cout << "normal = " << normals[i] << endl;
209 // Calculate texture coordinates
210 point_list geod_nodes;
212 for ( i = 0; i < 4; ++i ) {
213 geod_nodes.push_back( geod[i] );
217 for ( i = 0; i < 4; ++i ) {
218 rectangle.push_back( i );
220 point_list texs = calc_tex_coords( b, geod_nodes, rectangle,
221 1000.0 / tex_width );
223 // Build flight gear structure
224 fragment.add_face(0, 1, 2);
225 fragment.add_face(0, 2, 3);
226 t->fragment_list.push_back(fragment);
228 // Allocate ssg structure
229 ssgVertexArray *vl = new ssgVertexArray( 4 );
230 ssgNormalArray *nl = new ssgNormalArray( 4 );
231 ssgTexCoordArray *tl = new ssgTexCoordArray( 4 );
232 ssgColourArray *cl = new ssgColourArray( 1 );
235 sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
238 // sgVec3 *vtlist = new sgVec3 [ 4 ];
239 // t->vec3_ptrs.push_back( vtlist );
240 // sgVec3 *vnlist = new sgVec3 [ 4 ];
241 // t->vec3_ptrs.push_back( vnlist );
242 // sgVec2 *tclist = new sgVec2 [ 4 ];
243 // t->vec2_ptrs.push_back( tclist );
247 for ( i = 0; i < 4; ++i ) {
249 rel[i].x(), rel[i].y(), rel[i].z() );
253 normals[i].x(), normals[i].y(), normals[i].z() );
256 sgSetVec2( tmp2, texs[i].x(), texs[i].y());
261 new ssgVtxTable ( GL_TRIANGLE_FAN, vl, nl, tl, cl );
263 leaf->setState( state );
265 tile->addKid( leaf );
266 // if ( current_options.get_clouds() ) {
267 // fgGenCloudTile(path, t, tile);
274 // Load a .obj file and build the fragment list
275 ssgBranch *fgObjLoad( const string& path, FGTileEntry *t, const bool is_base) {
278 sgVec3 approx_normal;
279 // double normal[3], scale = 0.0;
280 // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
281 // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
282 // GLint display_list = 0;
284 bool in_fragment = false, in_faces = false;
285 int vncount, vtcount;
286 int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
288 int last1 = 0, last2 = 0;
293 double scenery_version = 0.0;
294 double tex_width = 1000.0, tex_height = 1000.0;
295 bool shared_done = false;
296 int_list fan_vertices;
297 int_list fan_tex_coords;
299 ssgSimpleState *state = NULL;
300 sgVec3 *vtlist, *vnlist;
303 ssgBranch *tile = new ssgBranch () ;
305 tile -> setName ( (char *)path.c_str() ) ;
307 // Attempt to open "path.gz" or "path"
308 fg_gzifstream in( path );
309 if ( ! in.is_open() ) {
310 FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << path );
311 FG_LOG( FG_TERRAIN, FG_ALERT, "default to ocean tile: " << path );
313 return fgGenTile( path, t );
316 shading = current_options.get_shading();
325 t->bounding_radius = 0.0;
332 // ignore initial comments and blank lines. (priming the pump)
333 // in >> skipcomment;
340 while ( in.get(c) && c != '\0' ) {
343 while ( ! in.eof() ) {
352 if ( in.get( c ) && c == '#' ) {
353 // process a comment line
355 // getline( in, line );
356 // cout << "comment = " << line << endl;
360 if ( token == "Version" ) {
361 // read scenery versions number
362 in >> scenery_version;
363 // cout << "scenery_version = " << scenery_version << endl;
364 } else if ( token == "gbs" ) {
365 // reference point (center offset)
367 in >> t->center >> t->bounding_radius;
371 in >> junk1 >> junk2;
374 // cout << "center = " << center
375 // << " radius = " << t->bounding_radius << endl;
376 } else if ( token == "bs" ) {
377 // reference point (center offset)
378 in >> fragment.center;
379 in >> fragment.bounding_radius;
381 // cout << "center = " << fragment.center
382 // << " radius = " << fragment.bounding_radius << endl;
383 } else if ( token == "usemtl" ) {
384 // material property specification
386 // if first usemtl with shared_done = false, then set
387 // shared_done true and build the ssg shared lists
388 if ( ! shared_done ) {
390 if ( (int)nodes.size() != vncount ) {
391 FG_LOG( FG_TERRAIN, FG_ALERT,
392 "Tile has mismatched nodes and normals: "
398 vtlist = new sgVec3 [ nodes.size() ];
399 t->vec3_ptrs.push_back( vtlist );
400 vnlist = new sgVec3 [ vncount ];
401 t->vec3_ptrs.push_back( vnlist );
402 tclist = new sgVec2 [ vtcount ];
403 t->vec2_ptrs.push_back( tclist );
405 for ( i = 0; i < (int)nodes.size(); ++i ) {
406 sgSetVec3( vtlist[i],
407 nodes[i][0], nodes[i][1], nodes[i][2] );
409 for ( i = 0; i < vncount; ++i ) {
410 sgSetVec3( vnlist[i],
415 for ( i = 0; i < vtcount; ++i ) {
416 sgSetVec2( tclist[i],
422 // series of individual triangles
427 // this also signals the start of a new fragment
429 // close out the previous structure and start the next
431 // printf("xglEnd(); xglEndList();\n");
434 // fragment.display_list = display_list;
436 // push this fragment onto the tile's object list
437 t->fragment_list.push_back(fragment);
442 // printf("start of fragment (usemtl)\n");
444 // display_list = xglGenLists(1);
445 // xglNewList(display_list, GL_COMPILE);
446 // printf("xglGenLists(); xglNewList();\n");
449 // reset the existing face list
450 // printf("cleaning a fragment with %d faces\n",
451 // fragment.faces.size());
454 // scan the material line
457 fragment.tile_ptr = t;
459 // find this material in the properties list
460 if ( ! material_mgr.find( material, fragment.material_ptr )) {
461 // see if this is an on the fly texture
463 int pos = file.rfind( "/" );
464 file = file.substr( 0, pos );
465 cout << "current file = " << file << endl;
468 cout << "current file = " << file << endl;
469 if ( ! material_mgr.add_item( file ) ) {
470 FG_LOG( FG_TERRAIN, FG_ALERT,
471 "Ack! unknown usemtl name = " << material
474 // locate our newly created material
475 if ( !material_mgr.find( material, fragment.material_ptr ) ) {
476 FG_LOG( FG_TERRAIN, FG_ALERT,
477 "Ack! bad on the fly materia create = "
478 << material << " in " << path );
484 // set the texture width and height values for this
486 FGMaterial m = fragment.material_ptr->get_m();
487 tex_width = m.get_xsize();
488 tex_height = m.get_ysize();
489 state = fragment.material_ptr->get_state();
490 // cout << "(w) = " << tex_width << " (h) = "
491 // << tex_width << endl;
493 // initialize the fragment transformation matrix
495 for ( i = 0; i < 16; i++ ) {
496 fragment.matrix[i] = 0.0;
498 fragment.matrix[0] = fragment.matrix[5] =
499 fragment.matrix[10] = fragment.matrix[15] = 1.0;
502 // unknown comment, just gobble the input untill the
512 // cout << "token = " << token << endl;
514 if ( token == "vn" ) {
516 if ( vncount < FG_MAX_NODES ) {
517 in >> normals[vncount][0]
518 >> normals[vncount][1]
519 >> normals[vncount][2];
522 FG_LOG( FG_TERRAIN, FG_ALERT,
523 "Read too many vertex normals in " << path
524 << " ... dying :-(" );
527 } else if ( token == "vt" ) {
528 // vertex texture coordinate
529 if ( vtcount < FG_MAX_NODES*3 ) {
530 in >> tex_coords[vtcount][0]
531 >> tex_coords[vtcount][1];
534 FG_LOG( FG_TERRAIN, FG_ALERT,
535 "Read too many vertex texture coords in " << path
540 } else if ( token == "v" ) {
542 if ( t->ncount < FG_MAX_NODES ) {
543 /* in >> nodes[t->ncount][0]
544 >> nodes[t->ncount][1]
545 >> nodes[t->ncount][2]; */
547 nodes.push_back(node);
552 FG_LOG( FG_TERRAIN, FG_ALERT,
553 "Read too many nodes in " << path
554 << " ... dying :-(");
557 } else if ( token == "t" ) {
558 // start a new triangle strip
560 n1 = n2 = n3 = n4 = 0;
562 // fgPrintf( FG_TERRAIN, FG_DEBUG,
563 // " new tri strip = %s", line);
564 in >> n1 >> n2 >> n3;
565 fragment.add_face(n1, n2, n3);
567 // fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = ");
569 // xglBegin(GL_TRIANGLE_STRIP);
570 // printf("xglBegin(tristrip) %d %d %d\n", n1, n2, n3);
576 // Shading model is "GL_SMOOTH" so use precalculated
577 // (averaged) normals
578 // MAT3_SCALE_VEC(normal, normals[n1], scale);
579 // xglNormal3dv(normal);
580 pp = local_calc_tex_coords(nodes[n1], center);
581 // xglTexCoord2f(pp.lon(), pp.lat());
582 // xglVertex3dv(nodes[n1].get_n());
584 // MAT3_SCALE_VEC(normal, normals[n2], scale);
585 // xglNormal3dv(normal);
586 pp = local_calc_tex_coords(nodes[n2], center);
587 // xglTexCoord2f(pp.lon(), pp.lat());
588 // xglVertex3dv(nodes[n2].get_n());
590 // MAT3_SCALE_VEC(normal, normals[n3], scale);
591 // xglNormal3dv(normal);
592 pp = local_calc_tex_coords(nodes[n3], center);
593 // xglTexCoord2f(pp.lon(), pp.lat());
594 // xglVertex3dv(nodes[n3].get_n());
596 // Shading model is "GL_FLAT" so calculate per face
597 // normals on the fly.
599 calc_normal(nodes[n1], nodes[n2],
600 nodes[n3], approx_normal);
602 calc_normal(nodes[n2], nodes[n1],
603 nodes[n3], approx_normal);
605 // MAT3_SCALE_VEC(normal, approx_normal, scale);
606 // xglNormal3dv(normal);
608 pp = local_calc_tex_coords(nodes[n1], center);
609 // xglTexCoord2f(pp.lon(), pp.lat());
610 // xglVertex3dv(nodes[n1].get_n());
612 pp = local_calc_tex_coords(nodes[n2], center);
613 // xglTexCoord2f(pp.lon(), pp.lat());
614 // xglVertex3dv(nodes[n2].get_n());
616 pp = local_calc_tex_coords(nodes[n3], center);
617 // xglTexCoord2f(pp.lon(), pp.lat());
618 // xglVertex3dv(nodes[n3].get_n());
620 // printf("some normals, texcoords, and vertices\n");
626 // There can be three or four values
628 while ( in.get(c) ) {
630 break; // only the one
640 fragment.add_face(n3, n2, n4);
643 // Shading model is "GL_SMOOTH"
644 // MAT3_SCALE_VEC(normal, normals[n4], scale);
646 // Shading model is "GL_FLAT"
647 calc_normal(nodes[n3], nodes[n2], nodes[n4],
649 // MAT3_SCALE_VEC(normal, approx_normal, scale);
651 // xglNormal3dv(normal);
652 pp = local_calc_tex_coords(nodes[n4], center);
653 // xglTexCoord2f(pp.lon(), pp.lat());
654 // xglVertex3dv(nodes[n4].get_n());
659 // printf("a normal, texcoord, and vertex (4th)\n");
661 } else if ( (token == "tf") || (token == "ts") ) {
663 // fgPrintf( FG_TERRAIN, FG_DEBUG, "new fan");
665 fan_vertices.clear();
666 fan_tex_coords.clear();
669 // xglBegin(GL_TRIANGLE_FAN);
672 fan_vertices.push_back( n1 );
673 // xglNormal3dv(normals[n1]);
674 if ( in.get( c ) && c == '/' ) {
676 fan_tex_coords.push_back( tex );
677 if ( scenery_version >= 0.4 ) {
678 if ( tex_width > 0 ) {
679 tclist[tex][0] *= (1000.0 / tex_width);
681 if ( tex_height > 0 ) {
682 tclist[tex][1] *= (1000.0 / tex_height);
685 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
686 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
689 pp = local_calc_tex_coords(nodes[n1], center);
691 // xglTexCoord2f(pp.x(), pp.y());
692 // xglVertex3dv(nodes[n1].get_n());
695 fan_vertices.push_back( n2 );
696 // xglNormal3dv(normals[n2]);
697 if ( in.get( c ) && c == '/' ) {
699 fan_tex_coords.push_back( tex );
700 if ( scenery_version >= 0.4 ) {
701 if ( tex_width > 0 ) {
702 tclist[tex][0] *= (1000.0 / tex_width);
704 if ( tex_height > 0 ) {
705 tclist[tex][1] *= (1000.0 / tex_height);
708 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
709 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
712 pp = local_calc_tex_coords(nodes[n2], center);
714 // xglTexCoord2f(pp.x(), pp.y());
715 // xglVertex3dv(nodes[n2].get_n());
717 // read all subsequent numbers until next thing isn't a number
728 if ( ! isdigit(c) || in.eof() ) {
733 fan_vertices.push_back( n3 );
734 // cout << " triangle = "
735 // << n1 << "," << n2 << "," << n3
737 // xglNormal3dv(normals[n3]);
738 if ( in.get( c ) && c == '/' ) {
740 fan_tex_coords.push_back( tex );
741 if ( scenery_version >= 0.4 ) {
742 if ( tex_width > 0 ) {
743 tclist[tex][0] *= (1000.0 / tex_width);
745 if ( tex_height > 0 ) {
746 tclist[tex][1] *= (1000.0 / tex_height);
749 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
750 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
753 pp = local_calc_tex_coords(nodes[n3], center);
755 // xglTexCoord2f(pp.x(), pp.y());
756 // xglVertex3dv(nodes[n3].get_n());
758 if ( token == "tf" ) {
760 fragment.add_face(n1, n2, n3);
765 fragment.add_face(n1, n2, n3);
767 fragment.add_face(n2, n1, n3);
777 // build the ssg entity
778 int size = (int)fan_vertices.size();
779 ssgVertexArray *vl = new ssgVertexArray( size );
780 ssgNormalArray *nl = new ssgNormalArray( size );
781 ssgTexCoordArray *tl = new ssgTexCoordArray( size );
782 ssgColourArray *cl = new ssgColourArray( 1 );
785 sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
790 for ( i = 0; i < size; ++i ) {
791 sgCopyVec3( tmp3, vtlist[ fan_vertices[i] ] );
794 sgCopyVec3( tmp3, vnlist[ fan_vertices[i] ] );
797 sgCopyVec2( tmp2, tclist[ fan_tex_coords[i] ] );
802 if ( token == "tf" ) {
805 new ssgVtxTable ( GL_TRIANGLE_FAN, vl, nl, tl, cl );
809 new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, nl, tl, cl );
811 // leaf->makeDList();
812 leaf->setState( state );
814 tile->addKid( leaf );
816 } else if ( token == "f" ) {
820 // xglBegin(GL_TRIANGLES);
821 // printf("xglBegin(triangles)\n");
825 // fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
826 in >> n1 >> n2 >> n3;
827 fragment.add_face(n1, n2, n3);
829 // xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
830 // xglNormal3dv(normals[n1]);
831 pp = local_calc_tex_coords(nodes[n1], center);
832 // xglTexCoord2f(pp.lon(), pp.lat());
833 // xglVertex3dv(nodes[n1].get_n());
835 // xglNormal3dv(normals[n2]);
836 pp = local_calc_tex_coords(nodes[n2], center);
837 // xglTexCoord2f(pp.lon(), pp.lat());
838 // xglVertex3dv(nodes[n2].get_n());
840 // xglNormal3dv(normals[n3]);
841 pp = local_calc_tex_coords(nodes[n3], center);
842 // xglTexCoord2f(pp.lon(), pp.lat());
843 // xglVertex3dv(nodes[n3].get_n());
844 // printf("some normals, texcoords, and vertices (tris)\n");
845 } else if ( token == "q" ) {
846 // continue a triangle strip
849 // fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ",
853 // There can be one or two values
855 while ( in.get(c) ) {
857 break; // only the one
866 // fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2);
869 fragment.add_face(last1, last2, n1);
871 fragment.add_face(last2, last1, n1);
875 // Shading model is "GL_SMOOTH"
876 // MAT3_SCALE_VEC(normal, normals[n1], scale);
878 // Shading model is "GL_FLAT"
880 calc_normal(nodes[last1], nodes[last2],
881 nodes[n1], approx_normal);
883 calc_normal(nodes[last2], nodes[last1],
884 nodes[n1], approx_normal);
886 // MAT3_SCALE_VEC(normal, approx_normal, scale);
888 // xglNormal3dv(normal);
890 pp = local_calc_tex_coords(nodes[n1], center);
891 // xglTexCoord2f(pp.lon(), pp.lat());
892 // xglVertex3dv(nodes[n1].get_n());
893 // printf("a normal, texcoord, and vertex (4th)\n");
900 // fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n");
903 fragment.add_face(last1, last2, n2);
905 fragment.add_face(last2, last1, n2);
909 // Shading model is "GL_SMOOTH"
910 // MAT3_SCALE_VEC(normal, normals[n2], scale);
912 // Shading model is "GL_FLAT"
914 calc_normal(nodes[last1], nodes[last2],
915 nodes[n2], approx_normal);
917 calc_normal(nodes[last2], nodes[last1],
918 nodes[n2], approx_normal);
920 // MAT3_SCALE_VEC(normal, approx_normal, scale);
922 // xglNormal3dv(normal);
924 pp = local_calc_tex_coords(nodes[n2], center);
925 // xglTexCoord2f(pp.lon(), pp.lat());
926 // xglVertex3dv(nodes[n2].get_n());
927 // printf("a normal, texcoord, and vertex (4th)\n");
934 FG_LOG( FG_TERRAIN, FG_WARN, "Unknown token in "
935 << path << " = " << token );
938 // eat white space before start of while loop so if we are
939 // done with useful input it is noticed before hand.
949 // close out the previous structure and start the next
952 // printf("xglEnd(); xglEndList();\n");
955 // fragment.display_list = display_list;
957 // push this fragment onto the tile's object list
958 t->fragment_list.push_back(fragment);
962 // Draw normal vectors (for visually verifying normals)
964 xglColor3f(0.0, 0.0, 0.0);
965 for ( i = 0; i < t->ncount; i++ ) {
966 xglVertex3d(nodes[i][0],
969 xglVertex3d(nodes[i][0] + 500*normals[i][0],
970 nodes[i][1] + 500*normals[i][1],
971 nodes[i][2] + 500*normals[i][2]);
981 FG_LOG( FG_TERRAIN, FG_DEBUG,
982 "Loaded " << path << " in "
983 << stopwatch.elapsedSeconds() << " seconds" );
985 // Generate a cloud layer above the tiles
986 // if ( current_options.get_clouds() ) {
987 // fgGenCloudTile(path, t, tile);