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/mat3.h>
50 #include <simgear/math/fg_geodesy.hxx>
51 #include <simgear/math/fg_random.h>
52 #include <simgear/math/point3d.hxx>
53 #include <simgear/math/polar3d.hxx>
54 #include <simgear/misc/fgstream.hxx>
55 #include <simgear/misc/stopwatch.hxx>
56 #include <simgear/misc/texcoord.hxx>
58 #include <Main/options.hxx>
59 #include <Scenery/tileentry.hxx>
61 #include "materialmgr.hxx"
68 typedef vector < int > int_list;
69 typedef int_list::iterator int_list_iterator;
70 typedef int_list::const_iterator int_point_list_iterator;
73 static double normals[FG_MAX_NODES][3];
74 static double tex_coords[FG_MAX_NODES*3][3];
77 // given three points defining a triangle, calculate the normal
78 static void calc_normal(Point3D p1, Point3D p2,
79 Point3D p3, double normal[3])
84 v1[0] = p2[0] - p1[0]; v1[1] = p2[1] - p1[1]; v1[2] = p2[2] - p1[2];
85 v2[0] = p3[0] - p1[0]; v2[1] = p3[1] - p1[1]; v2[2] = p3[2] - p1[2];
87 MAT3cross_product(normal, v1, v2);
88 MAT3_NORMALIZE_VEC(normal,temp);
90 // fgPrintf( FG_TERRAIN, FG_DEBUG, " Normal = %.2f %.2f %.2f\n",
91 // normal[0], normal[1], normal[2]);
95 #define FG_TEX_CONSTANT 69.0
97 // Calculate texture coordinates for a given point.
98 static Point3D local_calc_tex_coords(const Point3D& node, const Point3D& ref) {
101 // double tmplon, tmplat;
103 // cout << "-> " << node[0] << " " << node[1] << " " << node[2] << endl;
104 // cout << "-> " << ref.x() << " " << ref.y() << " " << ref.z() << endl;
106 cp = Point3D( node[0] + ref.x(),
110 pp = fgCartToPolar3d(cp);
112 // tmplon = pp.lon() * RAD_TO_DEG;
113 // tmplat = pp.lat() * RAD_TO_DEG;
114 // cout << tmplon << " " << tmplat << endl;
116 pp.setx( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.x(), 11.0) );
117 pp.sety( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.y(), 11.0) );
119 if ( pp.x() < 0.0 ) {
120 pp.setx( pp.x() + 11.0 );
123 if ( pp.y() < 0.0 ) {
124 pp.sety( pp.y() + 11.0 );
127 // cout << pp << endl;
133 // Generate a generic ocean tile on the fly
134 ssgBranch *fgGenTile( const string& path, FGTileEntry *t) {
137 fragment.tile_ptr = t;
139 ssgSimpleState *state = NULL;
141 ssgBranch *tile = new ssgBranch () ;
142 tile -> setName ( (char *)path.c_str() ) ;
144 // find Ocean material in the properties list
145 if ( ! material_mgr.find( "Ocean", fragment.material_ptr )) {
146 FG_LOG( FG_TERRAIN, FG_ALERT,
147 "Ack! unknown usemtl name = " << "Ocean"
151 // set the texture width and height values for this
153 FGMaterial m = fragment.material_ptr->get_m();
154 double tex_width = m.get_xsize();
155 double tex_height = m.get_ysize();
158 state = fragment.material_ptr->get_state();
160 // Calculate center point
161 FGBucket b = t->tile_bucket;
162 double clon = b.get_center_lon();
163 double clat = b.get_center_lat();
164 double height = b.get_height();
165 double width = b.get_width();
167 Point3D center = fgGeodToCart(Point3D(clon*DEG_TO_RAD,clat*DEG_TO_RAD,0.0));
169 fragment.center = center;
170 // cout << "center = " << center << endl;;
172 // Caculate corner vertices
174 geod[0] = Point3D( clon - width/2.0, clat - height/2.0, 0.0 );
175 geod[1] = Point3D( clon + width/2.0, clat - height/2.0, 0.0 );
176 geod[2] = Point3D( clon + width/2.0, clat + height/2.0, 0.0 );
177 geod[3] = Point3D( clon - width/2.0, clat + height/2.0, 0.0 );
181 for ( i = 0; i < 4; ++i ) {
182 rad[i] = Point3D( geod[i].x() * DEG_TO_RAD, geod[i].y() * DEG_TO_RAD,
186 Point3D cart[4], rel[4];
188 for ( i = 0; i < 4; ++i ) {
189 cart[i] = fgGeodToCart(rad[i]);
190 rel[i] = cart[i] - center;
191 t->nodes.push_back( rel[i] );
192 // cout << "corner " << i << " = " << cart[i] << endl;
197 // Calculate bounding radius
198 t->bounding_radius = center.distance3D( cart[0] );
199 fragment.bounding_radius = t->bounding_radius;
200 // cout << "bounding radius = " << t->bounding_radius << endl;
204 for ( i = 0; i < 4; ++i ) {
205 normals[i] = cart[i];
206 double length = normals[i].distance3D( Point3D(0.0) );
207 normals[i] /= length;
208 // cout << "normal = " << normals[i] << endl;
211 // Calculate texture coordinates
212 point_list geod_nodes;
214 for ( i = 0; i < 4; ++i ) {
215 geod_nodes.push_back( geod[i] );
219 for ( i = 0; i < 4; ++i ) {
220 rectangle.push_back( i );
222 point_list texs = calc_tex_coords( b, geod_nodes, rectangle,
223 1000.0 / tex_width );
225 // Build flight gear structure
226 fragment.add_face(0, 1, 2);
227 fragment.add_face(0, 2, 3);
228 t->fragment_list.push_back(fragment);
230 // Allocate ssg structure
231 sgVec3 *vtlist = new sgVec3 [ 4 ];
232 t->vec3_ptrs.push_back( vtlist );
233 sgVec3 *vnlist = new sgVec3 [ 4 ];
234 t->vec3_ptrs.push_back( vnlist );
235 sgVec2 *tclist = new sgVec2 [ 4 ];
236 t->vec2_ptrs.push_back( tclist );
238 for ( i = 0; i < 4; ++i ) {
239 sgSetVec3( vtlist[i],
240 rel[i].x(), rel[i].y(), rel[i].z() );
241 sgSetVec3( vnlist[i],
242 normals[i].x(), normals[i].y(), normals[i].z() );
243 sgSetVec2( tclist[i], texs[i].x(), texs[i].y() );
246 unsigned short *vindex = new unsigned short [ 4 ];
247 t->index_ptrs.push_back( vindex );
248 unsigned short *tindex = new unsigned short [ 4 ];
249 t->index_ptrs.push_back( tindex );
250 for ( i = 0; i < 4; ++i ) {
256 new ssgVTable ( GL_TRIANGLE_FAN,
261 leaf->setState( state );
263 tile->addKid( leaf );
264 // if ( current_options.get_clouds() ) {
265 // fgGenCloudTile(path, t, tile);
272 // Load a .obj file and build the fragment list
273 ssgBranch *fgObjLoad( const string& path, FGTileEntry *t, const bool is_base) {
276 double approx_normal[3] /*, normal[3], scale = 0.0 */;
277 // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin;
278 // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 };
279 // GLint display_list = 0;
281 bool in_fragment = false, in_faces = false;
282 int vncount, vtcount;
283 int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
285 int last1 = 0, last2 = 0;
290 double scenery_version = 0.0;
291 double tex_width = 1000.0, tex_height = 1000.0;
292 bool shared_done = false;
293 int_list fan_vertices;
294 int_list fan_tex_coords;
296 ssgSimpleState *state = NULL;
297 sgVec3 *vtlist, *vnlist;
300 ssgBranch *tile = new ssgBranch () ;
302 tile -> setName ( (char *)path.c_str() ) ;
304 // Attempt to open "path.gz" or "path"
305 fg_gzifstream in( path );
306 if ( ! in.is_open() ) {
307 FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << path );
308 FG_LOG( FG_TERRAIN, FG_ALERT, "default to ocean tile: " << path );
310 return fgGenTile( path, t );
313 shading = current_options.get_shading();
322 t->bounding_radius = 0.0;
329 // ignore initial comments and blank lines. (priming the pump)
330 // in >> skipcomment;
337 while ( in.get(c) && c != '\0' ) {
340 while ( ! in.eof() ) {
349 if ( in.get( c ) && c == '#' ) {
350 // process a comment line
352 // getline( in, line );
353 // cout << "comment = " << line << endl;
357 if ( token == "Version" ) {
358 // read scenery versions number
359 in >> scenery_version;
360 // cout << "scenery_version = " << scenery_version << endl;
361 } else if ( token == "gbs" ) {
362 // reference point (center offset)
364 in >> t->center >> t->bounding_radius;
368 in >> junk1 >> junk2;
371 // cout << "center = " << center
372 // << " radius = " << t->bounding_radius << endl;
373 } else if ( token == "bs" ) {
374 // reference point (center offset)
375 in >> fragment.center;
376 in >> fragment.bounding_radius;
378 // cout << "center = " << fragment.center
379 // << " radius = " << fragment.bounding_radius << endl;
380 } else if ( token == "usemtl" ) {
381 // material property specification
383 // if first usemtl with shared_done = false, then set
384 // shared_done true and build the ssg shared lists
385 if ( ! shared_done ) {
387 if ( (int)nodes.size() != vncount ) {
388 FG_LOG( FG_TERRAIN, FG_ALERT,
389 "Tile has mismatched nodes and normals: "
395 vtlist = new sgVec3 [ nodes.size() ];
396 t->vec3_ptrs.push_back( vtlist );
397 vnlist = new sgVec3 [ vncount ];
398 t->vec3_ptrs.push_back( vnlist );
399 tclist = new sgVec2 [ vtcount ];
400 t->vec2_ptrs.push_back( tclist );
402 for ( i = 0; i < (int)nodes.size(); ++i ) {
403 sgSetVec3( vtlist[i],
404 nodes[i][0], nodes[i][1], nodes[i][2] );
406 for ( i = 0; i < vncount; ++i ) {
407 sgSetVec3( vnlist[i],
412 for ( i = 0; i < vtcount; ++i ) {
413 sgSetVec2( tclist[i],
419 // series of individual triangles
424 // this also signals the start of a new fragment
426 // close out the previous structure and start the next
428 // printf("xglEnd(); xglEndList();\n");
431 // fragment.display_list = display_list;
433 // push this fragment onto the tile's object list
434 t->fragment_list.push_back(fragment);
439 // printf("start of fragment (usemtl)\n");
441 // display_list = xglGenLists(1);
442 // xglNewList(display_list, GL_COMPILE);
443 // printf("xglGenLists(); xglNewList();\n");
446 // reset the existing face list
447 // printf("cleaning a fragment with %d faces\n",
448 // fragment.faces.size());
451 // scan the material line
454 fragment.tile_ptr = t;
456 // find this material in the properties list
457 if ( ! material_mgr.find( material, fragment.material_ptr )) {
458 FG_LOG( FG_TERRAIN, FG_ALERT,
459 "Ack! unknown usemtl name = " << material
463 // set the texture width and height values for this
465 FGMaterial m = fragment.material_ptr->get_m();
466 tex_width = m.get_xsize();
467 tex_height = m.get_ysize();
468 state = fragment.material_ptr->get_state();
469 // cout << "(w) = " << tex_width << " (h) = "
470 // << tex_width << endl;
472 // initialize the fragment transformation matrix
474 for ( i = 0; i < 16; i++ ) {
475 fragment.matrix[i] = 0.0;
477 fragment.matrix[0] = fragment.matrix[5] =
478 fragment.matrix[10] = fragment.matrix[15] = 1.0;
481 // unknown comment, just gobble the input untill the
491 // cout << "token = " << token << endl;
493 if ( token == "vn" ) {
495 if ( vncount < FG_MAX_NODES ) {
496 in >> normals[vncount][0]
497 >> normals[vncount][1]
498 >> normals[vncount][2];
501 FG_LOG( FG_TERRAIN, FG_ALERT,
502 "Read too many vertex normals in " << path
503 << " ... dying :-(" );
506 } else if ( token == "vt" ) {
507 // vertex texture coordinate
508 if ( vtcount < FG_MAX_NODES*3 ) {
509 in >> tex_coords[vtcount][0]
510 >> tex_coords[vtcount][1];
513 FG_LOG( FG_TERRAIN, FG_ALERT,
514 "Read too many vertex texture coords in " << path
519 } else if ( token == "v" ) {
521 if ( t->ncount < FG_MAX_NODES ) {
522 /* in >> nodes[t->ncount][0]
523 >> nodes[t->ncount][1]
524 >> nodes[t->ncount][2]; */
526 nodes.push_back(node);
531 FG_LOG( FG_TERRAIN, FG_ALERT,
532 "Read too many nodes in " << path
533 << " ... dying :-(");
536 } else if ( token == "t" ) {
537 // start a new triangle strip
539 n1 = n2 = n3 = n4 = 0;
541 // fgPrintf( FG_TERRAIN, FG_DEBUG,
542 // " new tri strip = %s", line);
543 in >> n1 >> n2 >> n3;
544 fragment.add_face(n1, n2, n3);
546 // fgPrintf( FG_TERRAIN, FG_DEBUG, "(t) = ");
548 // xglBegin(GL_TRIANGLE_STRIP);
549 // printf("xglBegin(tristrip) %d %d %d\n", n1, n2, n3);
555 // Shading model is "GL_SMOOTH" so use precalculated
556 // (averaged) normals
557 // MAT3_SCALE_VEC(normal, normals[n1], scale);
558 // xglNormal3dv(normal);
559 pp = local_calc_tex_coords(nodes[n1], center);
560 // xglTexCoord2f(pp.lon(), pp.lat());
561 // xglVertex3dv(nodes[n1].get_n());
563 // MAT3_SCALE_VEC(normal, normals[n2], scale);
564 // xglNormal3dv(normal);
565 pp = local_calc_tex_coords(nodes[n2], center);
566 // xglTexCoord2f(pp.lon(), pp.lat());
567 // xglVertex3dv(nodes[n2].get_n());
569 // MAT3_SCALE_VEC(normal, normals[n3], scale);
570 // xglNormal3dv(normal);
571 pp = local_calc_tex_coords(nodes[n3], center);
572 // xglTexCoord2f(pp.lon(), pp.lat());
573 // xglVertex3dv(nodes[n3].get_n());
575 // Shading model is "GL_FLAT" so calculate per face
576 // normals on the fly.
578 calc_normal(nodes[n1], nodes[n2],
579 nodes[n3], approx_normal);
581 calc_normal(nodes[n2], nodes[n1],
582 nodes[n3], approx_normal);
584 // MAT3_SCALE_VEC(normal, approx_normal, scale);
585 // xglNormal3dv(normal);
587 pp = local_calc_tex_coords(nodes[n1], center);
588 // xglTexCoord2f(pp.lon(), pp.lat());
589 // xglVertex3dv(nodes[n1].get_n());
591 pp = local_calc_tex_coords(nodes[n2], center);
592 // xglTexCoord2f(pp.lon(), pp.lat());
593 // xglVertex3dv(nodes[n2].get_n());
595 pp = local_calc_tex_coords(nodes[n3], center);
596 // xglTexCoord2f(pp.lon(), pp.lat());
597 // xglVertex3dv(nodes[n3].get_n());
599 // printf("some normals, texcoords, and vertices\n");
605 // There can be three or four values
607 while ( in.get(c) ) {
609 break; // only the one
619 fragment.add_face(n3, n2, n4);
622 // Shading model is "GL_SMOOTH"
623 // MAT3_SCALE_VEC(normal, normals[n4], scale);
625 // Shading model is "GL_FLAT"
626 calc_normal(nodes[n3], nodes[n2], nodes[n4],
628 // MAT3_SCALE_VEC(normal, approx_normal, scale);
630 // xglNormal3dv(normal);
631 pp = local_calc_tex_coords(nodes[n4], center);
632 // xglTexCoord2f(pp.lon(), pp.lat());
633 // xglVertex3dv(nodes[n4].get_n());
638 // printf("a normal, texcoord, and vertex (4th)\n");
640 } else if ( (token == "tf") || (token == "ts") ) {
642 // fgPrintf( FG_TERRAIN, FG_DEBUG, "new fan");
644 fan_vertices.clear();
645 fan_tex_coords.clear();
648 // xglBegin(GL_TRIANGLE_FAN);
651 fan_vertices.push_back( n1 );
652 // xglNormal3dv(normals[n1]);
653 if ( in.get( c ) && c == '/' ) {
655 fan_tex_coords.push_back( tex );
656 if ( scenery_version >= 0.4 ) {
657 if ( tex_width > 0 ) {
658 tclist[tex][0] *= (1000.0 / tex_width);
660 if ( tex_height > 0 ) {
661 tclist[tex][1] *= (1000.0 / tex_height);
664 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
665 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
668 pp = local_calc_tex_coords(nodes[n1], center);
670 // xglTexCoord2f(pp.x(), pp.y());
671 // xglVertex3dv(nodes[n1].get_n());
674 fan_vertices.push_back( n2 );
675 // xglNormal3dv(normals[n2]);
676 if ( in.get( c ) && c == '/' ) {
678 fan_tex_coords.push_back( tex );
679 if ( scenery_version >= 0.4 ) {
680 if ( tex_width > 0 ) {
681 tclist[tex][0] *= (1000.0 / tex_width);
683 if ( tex_height > 0 ) {
684 tclist[tex][1] *= (1000.0 / tex_height);
687 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
688 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
691 pp = local_calc_tex_coords(nodes[n2], center);
693 // xglTexCoord2f(pp.x(), pp.y());
694 // xglVertex3dv(nodes[n2].get_n());
696 // read all subsequent numbers until next thing isn't a number
707 if ( ! isdigit(c) || in.eof() ) {
712 fan_vertices.push_back( n3 );
713 // cout << " triangle = "
714 // << n1 << "," << n2 << "," << n3
716 // xglNormal3dv(normals[n3]);
717 if ( in.get( c ) && c == '/' ) {
719 fan_tex_coords.push_back( tex );
720 if ( scenery_version >= 0.4 ) {
721 if ( tex_width > 0 ) {
722 tclist[tex][0] *= (1000.0 / tex_width);
724 if ( tex_height > 0 ) {
725 tclist[tex][1] *= (1000.0 / tex_height);
728 pp.setx( tex_coords[tex][0] * (1000.0 / tex_width) );
729 pp.sety( tex_coords[tex][1] * (1000.0 / tex_height) );
732 pp = local_calc_tex_coords(nodes[n3], center);
734 // xglTexCoord2f(pp.x(), pp.y());
735 // xglVertex3dv(nodes[n3].get_n());
737 if ( token == "tf" ) {
739 fragment.add_face(n1, n2, n3);
744 fragment.add_face(n1, n2, n3);
746 fragment.add_face(n2, n1, n3);
756 // build the ssg entity
757 unsigned short *vindex =
758 new unsigned short [ fan_vertices.size() ];
759 t->index_ptrs.push_back( vindex );
761 unsigned short *tindex =
762 new unsigned short [ fan_tex_coords.size() ];
763 t->index_ptrs.push_back( tindex );
765 for ( i = 0; i < (int)fan_vertices.size(); ++i ) {
766 vindex[i] = fan_vertices[i];
768 for ( i = 0; i < (int)fan_tex_coords.size(); ++i ) {
769 tindex[i] = fan_tex_coords[i];
772 if ( token == "tf" ) {
775 new ssgVTable ( GL_TRIANGLE_FAN,
776 fan_vertices.size(), vindex, vtlist,
777 fan_vertices.size(), vindex, vnlist,
778 fan_tex_coords.size(), tindex, tclist,
783 new ssgVTable ( GL_TRIANGLE_STRIP,
784 fan_vertices.size(), vindex, vtlist,
785 fan_vertices.size(), vindex, vnlist,
786 fan_tex_coords.size(), tindex, tclist,
789 // leaf->makeDList();
790 leaf->setState( state );
792 tile->addKid( leaf );
794 } else if ( token == "f" ) {
798 // xglBegin(GL_TRIANGLES);
799 // printf("xglBegin(triangles)\n");
803 // fgPrintf( FG_TERRAIN, FG_DEBUG, "new triangle = %s", line);*/
804 in >> n1 >> n2 >> n3;
805 fragment.add_face(n1, n2, n3);
807 // xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]);
808 // xglNormal3dv(normals[n1]);
809 pp = local_calc_tex_coords(nodes[n1], center);
810 // xglTexCoord2f(pp.lon(), pp.lat());
811 // xglVertex3dv(nodes[n1].get_n());
813 // xglNormal3dv(normals[n2]);
814 pp = local_calc_tex_coords(nodes[n2], center);
815 // xglTexCoord2f(pp.lon(), pp.lat());
816 // xglVertex3dv(nodes[n2].get_n());
818 // xglNormal3dv(normals[n3]);
819 pp = local_calc_tex_coords(nodes[n3], center);
820 // xglTexCoord2f(pp.lon(), pp.lat());
821 // xglVertex3dv(nodes[n3].get_n());
822 // printf("some normals, texcoords, and vertices (tris)\n");
823 } else if ( token == "q" ) {
824 // continue a triangle strip
827 // fgPrintf( FG_TERRAIN, FG_DEBUG, "continued tri strip = %s ",
831 // There can be one or two values
833 while ( in.get(c) ) {
835 break; // only the one
844 // fgPrintf( FG_TERRAIN, FG_DEBUG, "read %d %d\n", n1, n2);
847 fragment.add_face(last1, last2, n1);
849 fragment.add_face(last2, last1, n1);
853 // Shading model is "GL_SMOOTH"
854 // MAT3_SCALE_VEC(normal, normals[n1], scale);
856 // Shading model is "GL_FLAT"
858 calc_normal(nodes[last1], nodes[last2],
859 nodes[n1], approx_normal);
861 calc_normal(nodes[last2], nodes[last1],
862 nodes[n1], approx_normal);
864 // MAT3_SCALE_VEC(normal, approx_normal, scale);
866 // xglNormal3dv(normal);
868 pp = local_calc_tex_coords(nodes[n1], center);
869 // xglTexCoord2f(pp.lon(), pp.lat());
870 // xglVertex3dv(nodes[n1].get_n());
871 // printf("a normal, texcoord, and vertex (4th)\n");
878 // fgPrintf( FG_TERRAIN, FG_DEBUG, " (cont)\n");
881 fragment.add_face(last1, last2, n2);
883 fragment.add_face(last2, last1, n2);
887 // Shading model is "GL_SMOOTH"
888 // MAT3_SCALE_VEC(normal, normals[n2], scale);
890 // Shading model is "GL_FLAT"
892 calc_normal(nodes[last1], nodes[last2],
893 nodes[n2], approx_normal);
895 calc_normal(nodes[last2], nodes[last1],
896 nodes[n2], approx_normal);
898 // MAT3_SCALE_VEC(normal, approx_normal, scale);
900 // xglNormal3dv(normal);
902 pp = local_calc_tex_coords(nodes[n2], center);
903 // xglTexCoord2f(pp.lon(), pp.lat());
904 // xglVertex3dv(nodes[n2].get_n());
905 // printf("a normal, texcoord, and vertex (4th)\n");
912 FG_LOG( FG_TERRAIN, FG_WARN, "Unknown token in "
913 << path << " = " << token );
916 // eat white space before start of while loop so if we are
917 // done with useful input it is noticed before hand.
927 // close out the previous structure and start the next
930 // printf("xglEnd(); xglEndList();\n");
933 // fragment.display_list = display_list;
935 // push this fragment onto the tile's object list
936 t->fragment_list.push_back(fragment);
940 // Draw normal vectors (for visually verifying normals)
942 xglColor3f(0.0, 0.0, 0.0);
943 for ( i = 0; i < t->ncount; i++ ) {
944 xglVertex3d(nodes[i][0],
947 xglVertex3d(nodes[i][0] + 500*normals[i][0],
948 nodes[i][1] + 500*normals[i][1],
949 nodes[i][2] + 500*normals[i][2]);
959 FG_LOG( FG_TERRAIN, FG_DEBUG,
960 "Loaded " << path << " in "
961 << stopwatch.elapsedSeconds() << " seconds" );
963 // Generate a cloud layer above the tiles
964 // if ( current_options.get_clouds() ) {
965 // fgGenCloudTile(path, t, tile);