1 // tileentry.cxx -- routines to handle a scenery tile
3 // Written by Curtis Olson, started May 1998.
5 // Copyright (C) 1998 - 2001 Curtis L. Olson - curt@flightgear.org
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 #include <simgear/compiler.h>
30 #include <simgear/bucket/newbucket.hxx>
31 #include <simgear/debug/logstream.hxx>
32 #include <simgear/math/sg_geodesy.hxx>
33 #include <simgear/math/sg_random.h>
34 #include <simgear/misc/sgstream.hxx>
36 #include <Aircraft/aircraft.hxx>
37 #include <Include/general.hxx>
38 #include <Main/globals.hxx>
39 #include <Main/viewer.hxx>
40 #include <Scenery/scenery.hxx>
41 #include <Time/light.hxx>
42 #include <Objects/apt_signs.hxx>
43 #include <Objects/matlib.hxx>
44 #include <Objects/newmat.hxx>
45 #include <Objects/obj.hxx>
47 #include "tileentry.hxx"
48 #include "tilemgr.hxx"
52 FGTileEntry::FGTileEntry ( const SGBucket& b )
54 center( Point3D( 0.0 ) ),
56 terra_transform( new ssgTransform ),
57 terra_range( new ssgRangeSelector ),
63 // update the contents
64 // if ( vec3_ptrs.size() || vec2_ptrs.size() || index_ptrs.size() ) {
65 // SG_LOG( SG_TERRAIN, SG_ALERT,
66 // "Attempting to overwrite existing or"
67 // << " not properly freed leaf data." );
74 FGTileEntry::~FGTileEntry () {
75 // cout << "nodes = " << nodes.size() << endl;;
81 // Please keep this for reference. We use Norman's optimized routine,
82 // but here is what the routine really is doing.
84 FGTileEntry::WorldCoordinate( sgCoord *obj_pos, Point3D center,
85 double lat, double lon, double elev, double hdg)
88 Point3D geod( lon * SGD_DEGREES_TO_RADIANS,
89 lat * SGD_DEGREES_TO_RADIANS,
92 Point3D world_pos = sgGeodToCart( geod );
93 Point3D offset = world_pos - center;
96 sgMakeTransMat4( POS, offset.x(), offset.y(), offset.z() );
98 sgVec3 obj_rt, obj_up;
99 sgSetVec3( obj_rt, 0.0, 1.0, 0.0); // Y axis
100 sgSetVec3( obj_up, 0.0, 0.0, 1.0); // Z axis
102 sgMat4 ROT_lon, ROT_lat, ROT_hdg;
103 sgMakeRotMat4( ROT_lon, lon, obj_up );
104 sgMakeRotMat4( ROT_lat, 90 - lat, obj_rt );
105 sgMakeRotMat4( ROT_hdg, hdg, obj_up );
108 sgCopyMat4( TUX, ROT_hdg );
109 sgPostMultMat4( TUX, ROT_lat );
110 sgPostMultMat4( TUX, ROT_lon );
111 sgPostMultMat4( TUX, POS );
113 sgSetCoord( obj_pos, TUX );
118 // Norman's 'fast hack' for above
119 static void WorldCoordinate( sgCoord *obj_pos, Point3D center, double lat,
120 double lon, double elev, double hdg )
122 double lon_rad = lon * SGD_DEGREES_TO_RADIANS;
123 double lat_rad = lat * SGD_DEGREES_TO_RADIANS;
124 double hdg_rad = hdg * SGD_DEGREES_TO_RADIANS;
127 Point3D geod( lon_rad, lat_rad, elev );
129 Point3D world_pos = sgGeodToCart( geod );
130 Point3D offset = world_pos - center;
134 SGfloat sin_lat = (SGfloat)sin( lat_rad );
135 SGfloat cos_lat = (SGfloat)cos( lat_rad );
136 SGfloat cos_lon = (SGfloat)cos( lon_rad );
137 SGfloat sin_lon = (SGfloat)sin( lon_rad );
138 SGfloat sin_hdg = (SGfloat)sin( hdg_rad ) ;
139 SGfloat cos_hdg = (SGfloat)cos( hdg_rad ) ;
141 mat[0][0] = cos_hdg * (SGfloat)sin_lat * (SGfloat)cos_lon - sin_hdg * (SGfloat)sin_lon;
142 mat[0][1] = cos_hdg * (SGfloat)sin_lat * (SGfloat)sin_lon + sin_hdg * (SGfloat)cos_lon;
143 mat[0][2] = -cos_hdg * (SGfloat)cos_lat;
146 mat[1][0] = -sin_hdg * (SGfloat)sin_lat * (SGfloat)cos_lon - cos_hdg * (SGfloat)sin_lon;
147 mat[1][1] = -sin_hdg * (SGfloat)sin_lat * (SGfloat)sin_lon + cos_hdg * (SGfloat)cos_lon;
148 mat[1][2] = sin_hdg * (SGfloat)cos_lat;
151 mat[2][0] = (SGfloat)cos_lat * (SGfloat)cos_lon;
152 mat[2][1] = (SGfloat)cos_lat * (SGfloat)sin_lon;
153 mat[2][2] = (SGfloat)sin_lat;
156 mat[3][0] = offset.x();
157 mat[3][1] = offset.y();
158 mat[3][2] = offset.z();
161 sgSetCoord( obj_pos, mat );
165 // recurse an ssg tree and call removeKid() on every node from the
166 // bottom up. Leaves the original branch in existance, but empty so
167 // it can be removed by the calling routine.
168 static void my_remove_branch( ssgBranch * branch ) {
169 for ( ssgEntity *k = branch->getKid( 0 );
171 k = branch->getNextKid() )
173 if ( k -> isAKindOf ( ssgTypeBranch() ) ) {
174 my_remove_branch( (ssgBranch *)k );
175 branch -> removeKid ( k );
176 } else if ( k -> isAKindOf ( ssgTypeLeaf() ) ) {
177 branch -> removeKid ( k ) ;
185 unsigned char env_map[TEXRES_X][TEXRES_Y][4];
186 // SetColor & SetColor2 functions were provided by Christian Mayer (26 April 2001) - used without change
187 void setColor(float x, float y, float z, float angular_size, float r,
188 float g, float b, float a)
191 float inv_length = 1.0 / sqrt(x*x + y*y + z*z);
192 x *= inv_length; y *= inv_length; z *= inv_length;
194 float cos_angular_size = cos(angular_size*(22.0/7.0)/180.0);
196 for( int s = 0; s < TEXRES_X; s++) {
197 for( int t = 0; t < TEXRES_Y; t++) {
199 float s_2 = (float)s/TEXRES_X - 0.5; // centre of texture 0,0
200 float t_2 = (float)t/TEXRES_Y - 0.5; // elev
204 if ((1.0 - 4.0*s_2*s_2 - 4.0*t_2*t_2) >= 0.0) {
206 float m = 4.0 * sqrt(1.0 - 4.0*s_2*s_2 - 4.0*t_2*t_2);
209 rz = m*m / 8.0 - 1.0;
217 float tx = rx; //mirroring on the z=0 plane
218 float ty = ry; //assumes that the normal is allways
219 float tz = -rz; //n(0.0, 0.0, 1.0)
221 if ( cos_angular_size < (x*tx + y*ty + z*tz) ) {
222 env_map[s][t][0] = (unsigned char) r * 255;
223 env_map[s][t][1] = (unsigned char) g * 255;
224 env_map[s][t][2] = (unsigned char) b * 255;
225 env_map[s][t][3] = (unsigned char) a * 255;
231 // elevation_size, float azimuth_size are the *total* angular size of the light
232 void setColor2(float elevation_size,float azimuth_size, float r, float g, float b, float a)
234 for( int s = 0; s < TEXRES_X; s++) {
235 for( int t = 0; t < TEXRES_Y; t++) {
236 float s_2 = (float)s/TEXRES_X - 0.5;
237 float t_2 = (float)t/TEXRES_Y - 0.5;
241 if ((1.0 - 4.0*s_2*s_2 - 4.0*t_2*t_2) >= 0.0) {
243 float m = 4.0 * sqrt(1.0 - 4.0*s_2*s_2 - 4.0*t_2*t_2);
246 rz = m*m / 8.0 - 1.0;
253 float tx = rx; //mirroring on the z=0 plane to reverse
254 float ty = ry; //OpenGLs automatic mirroring
257 //get elevation => project t onto the x-z-plane
258 float tz_proj1 = tz / sqrt(tx*tx + tz*tz);
259 float televation = acos( -tz_proj1 ) * 180.0 / 3.1415;
261 //get azi => project t onto the y-z-plane
262 float tz_proj2 = tz / sqrt(ty*ty + tz*tz);
263 float tazimuth = acos( -tz_proj2 ) * 180.0 / 3.1415;
265 //note televation and tazimuth are the angles *between* the
266 //temporary vector and the normal (0,0,-1). They are *NOT*
267 //the elevation and azimuth angles
270 //if (((elevation_size > televation) || (elevation_size < -televation)) &&
271 // ((azimuth_size > tazimuth ) || (azimuth_size < -tazimuth )))
273 if (((televation*televation) / (elevation_size*elevation_size / 4.0) +
274 (tazimuth *tazimuth ) / (azimuth_size *azimuth_size / 4.0)) <= 1.0)
276 env_map[s][t][0] = (unsigned char) r * 255;
277 env_map[s][t][1] = (unsigned char) g * 255;
278 env_map[s][t][2] = (unsigned char) b * 255;
279 env_map[s][t][3] = (unsigned char) a * 255;
286 // This function performs billboarding of polygons drawn using the UP and RIGHT vectors obtained
287 // from the transpose of the MODEL_VIEW_MATRIX of the ssg_current_context. Each polygon is drawn
288 // at the coordinate array and material state as passed thro arguments.
289 void *fgBillboard( ssgBranch *lightmaps, ssgVertexArray *light_maps, ssgSimpleState *lightmap_state, float size) {
291 sgVec3 rt, up, nrt, nup, pt, quads[4], lmaps[4];
293 ssgGetModelviewMatrix ( tmat );
294 sgSetVec3 (rt, tmat[0][0], tmat[1][0], tmat[2][0]);
295 sgSetVec3 (up, tmat[0][1], tmat[1][1], tmat[2][1]);
296 sgSetVec3 (nrt, tmat[0][0], tmat[1][0], tmat[2][0]);
297 sgSetVec3 (nup, tmat[0][1], tmat[1][1], tmat[2][1]);
301 sgAddVec3 (quads[0], nrt, nup);
302 sgAddVec3 (quads[1], rt, nup);
303 sgAddVec3 (quads[2], rt, up);
304 sgAddVec3 (quads[3], nrt, up);
306 sgScaleVec3 (quads[0], size);
307 sgScaleVec3 (quads[1], size);
308 sgScaleVec3 (quads[2], size);
309 sgScaleVec3 (quads[3], size);
312 sgSetVec4( color, 1.0, 1.0, 0.0, 1.0 );
315 sgSetVec2( texcoords[0], 1.0, 1.0 );
316 sgSetVec2( texcoords[1], 0.0, 1.0 );
317 sgSetVec2( texcoords[2], 0.0, 0.0 );
318 sgSetVec2( texcoords[3], 1.0, 0.0 );
320 for (int j = 0; j < 4; j++ ) {
321 sgCopyVec3(lmaps[j] ,quads[j]);
324 for ( int i = 0; i < light_maps->getNum(); ++i ) {
325 // Allocate ssg structure
326 ssgVertexArray *vl = new ssgVertexArray( 1 );
327 ssgTexCoordArray *tl = new ssgTexCoordArray( 1 );
328 ssgColourArray *cl = new ssgColourArray( 1 );
330 float *temp = light_maps->get(i);
331 sgSetVec3(pt,temp[0],temp[1],temp[2]);
333 for (int k=0; k<4; k++) {
334 sgAddVec3( quads[k],lmaps[k], pt );
336 tl->add(texcoords[k]);
340 ssgLeaf *leaf = NULL;
341 leaf = new ssgVtxTable ( GL_TRIANGLE_FAN, vl, NULL, tl, cl );
342 leaf->setState( lightmap_state );
343 lightmaps->addKid( leaf );
349 ssgBranch* FGTileEntry::gen_runway_lights( ssgVertexArray *points,ssgVertexArray *normal,
350 ssgVertexArray *dir, int type[])
353 //************** HARD CODED RUNWAY LIGHT TEXTURES BEGIN ************************
354 GLuint texEdge, texTaxi, texCenter, texTouchdown;
355 GLuint texThreshold, texCrossbar, texUndershoot, texApproach;
356 GLuint texRabbit, texVasi, texWhite, texRed, texGreen, texYellow;
359 setColor(0.0,0.0,1.0,360.0, 0, 0, 0, 0);
360 setColor2(10.0, 40.0, 1, 1, 1, 1);
361 setColor2(6.0, 40.0, 1, 0.5, 0.5, 1);
362 setColor2(5.0, 40.0, 1, 0, 0, 1);
363 glGenTextures(1, &texVasi);
364 glBindTexture(GL_TEXTURE_2D, texVasi);
365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
367 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
368 ssgSimpleState *vasi_state;
369 vasi_state = new ssgSimpleState();
371 vasi_state->setTexture( texVasi );
372 vasi_state->disable( GL_LIGHTING );
373 vasi_state->enable( GL_TEXTURE_2D );
374 vasi_state->setShadeModel( GL_SMOOTH );
377 setColor(0.0,0.0,-1.0,180.0, 1, 1, 0.5, 1);
378 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
379 glGenTextures(1, &texEdge);
380 glBindTexture(GL_TEXTURE_2D, texEdge);
381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
383 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
384 ssgSimpleState *edge_state;
385 edge_state = new ssgSimpleState();
387 edge_state->setTexture( texEdge );
388 edge_state->disable( GL_LIGHTING );
389 edge_state->enable( GL_TEXTURE_2D );
390 edge_state->setShadeModel( GL_SMOOTH );
393 setColor(0.0,0.0,-1.0,180.0, 0, 1, 0, 1);
394 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
395 glGenTextures(1, &texTouchdown);
396 glBindTexture(GL_TEXTURE_2D, texTouchdown);
397 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
398 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
399 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
400 ssgSimpleState *touchdown_state;
401 touchdown_state = new ssgSimpleState();
402 touchdown_state->ref();
403 touchdown_state->setTexture( texTouchdown );
404 touchdown_state->disable( GL_LIGHTING );
405 touchdown_state->enable( GL_TEXTURE_2D );
406 touchdown_state->setShadeModel( GL_SMOOTH );
409 setColor(0.0,0.0,-1.0,180.0, 1, 0, 0, 1);
410 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
411 glGenTextures(1, &texThreshold);
412 glBindTexture(GL_TEXTURE_2D, texThreshold);
413 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
415 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
416 ssgSimpleState *threshold_state;
417 threshold_state = new ssgSimpleState();
418 threshold_state->ref();
419 threshold_state->setTexture( texThreshold );
420 threshold_state->disable( GL_LIGHTING );
421 threshold_state->enable( GL_TEXTURE_2D );
422 threshold_state->setShadeModel( GL_SMOOTH );
425 setColor(0.0,0.0,-1.0,180.0, 0, 0, 1, 1);
426 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
427 glGenTextures(1, &texTaxi);
428 glBindTexture(GL_TEXTURE_2D, texTaxi);
429 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
430 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
431 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
432 ssgSimpleState *taxi_state;
433 taxi_state = new ssgSimpleState();
435 taxi_state->setTexture( texTaxi );
436 taxi_state->disable( GL_LIGHTING );
437 taxi_state->enable( GL_TEXTURE_2D );
438 taxi_state->setShadeModel( GL_SMOOTH );
441 setColor(0.0,0.0,-1.0,180.0, 1, 1, 1, 1);
442 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
443 glGenTextures(1, &texWhite);
444 glBindTexture(GL_TEXTURE_2D, texWhite);
445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
446 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
447 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
448 ssgSimpleState *white_state;
449 white_state = new ssgSimpleState();
451 white_state->setTexture( texWhite );
452 white_state->disable( GL_LIGHTING );
453 white_state->enable( GL_TEXTURE_2D );
454 white_state->setShadeModel( GL_SMOOTH );
457 setColor(0.0,0.0,-1.0,180.0, 1, 0, 0, 1);
458 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
459 glGenTextures(1, &texRed);
460 glBindTexture(GL_TEXTURE_2D, texRed);
461 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
462 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
463 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
464 ssgSimpleState *red_state;
465 red_state = new ssgSimpleState();
467 red_state->setTexture( texRed );
468 red_state->disable( GL_LIGHTING );
469 red_state->enable( GL_TEXTURE_2D );
470 red_state->setShadeModel( GL_SMOOTH );
473 setColor(0.0,0.0,-1.0,180.0, 0, 1, 0, 1);
474 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
475 glGenTextures(1, &texGreen);
476 glBindTexture(GL_TEXTURE_2D, texGreen);
477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
478 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
479 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
480 ssgSimpleState *green_state;
481 green_state = new ssgSimpleState();
483 green_state->setTexture( texGreen );
484 green_state->disable( GL_LIGHTING );
485 green_state->enable( GL_TEXTURE_2D );
486 green_state->setShadeModel( GL_SMOOTH );
489 setColor(0.0,0.0,-1.0,180.0, 1, 1, 0, 1);
490 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
491 glGenTextures(1, &texYellow);
492 glBindTexture(GL_TEXTURE_2D, texYellow);
493 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
494 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
495 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXRES_X, TEXRES_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, env_map);
496 ssgSimpleState *yellow_state;
497 yellow_state = new ssgSimpleState();
499 yellow_state->setTexture( texYellow );
500 yellow_state->disable( GL_LIGHTING );
501 yellow_state->enable( GL_TEXTURE_2D );
502 yellow_state->setShadeModel( GL_SMOOTH );
503 //************** HARD CODED RUNWAY LIGHT TEXTURES END ************************
505 ssgBranch *runway_lights = new ssgBranch;
506 sgVec3 v2,v3,inf,side;
508 ssgLeaf *leaf1 = NULL;
509 ssgLeaf *leaf2 = NULL;
510 ssgLeaf *leaf7 = NULL;
511 ssgLeaf *leaf8 = NULL;
512 ssgLeaf *leaf9 = NULL;
514 ssgVertexArray *vlw = new ssgVertexArray( 1 );
515 ssgNormalArray *nlw = new ssgNormalArray( 1 );
516 ssgVertexArray *vlt = new ssgVertexArray( 1 );
517 ssgNormalArray *nlt = new ssgNormalArray( 1 );
518 ssgVertexArray *vlr = new ssgVertexArray( 1 );
519 ssgNormalArray *nlr = new ssgNormalArray( 1 );
520 ssgVertexArray *vlg = new ssgVertexArray( 1 );
521 ssgNormalArray *nlg = new ssgNormalArray( 1 );
522 ssgVertexArray *vly = new ssgVertexArray( 1 );
523 ssgNormalArray *nly = new ssgNormalArray( 1 );
525 for ( int i = 0; i < points->getNum()-1; i=i++ ) {
527 // Allocate ssg structure
528 ssgVertexArray *vl = new ssgVertexArray( 1 );
529 ssgNormalArray *nl = new ssgNormalArray( 1 );
530 ssgVertexArray *vl1 = new ssgVertexArray( 1 );
531 ssgNormalArray *nl1 = new ssgNormalArray( 1 );
533 float *n1 = normal->get(i);
534 float *d1 = dir->get(i);
536 /* TEMPORARY CODE BEGIN
537 // calculate normal using 1st, 2nd & last vertices of the group
539 sgMakeNormal (n1, points->get(0), points->get(1), points->get(points->getNum()-1) );
541 sgSubVec3(d1,points->get(1),points->get(0));
542 printf("%f %f %f\n",n1[0],n1[1],n1[2]);
543 printf("%f %f %f\n",d1[0],d1[1],d1[2]);
545 ----TEMPORARY CODE END */
548 sgNormaliseVec3 ( n1 );
549 sgNormaliseVec3 ( d1 );
555 sgVectorProductVec3(side,n1,d1);
556 sgScaleVec3 (inf,n1,-50);
557 sgScaleVec3 (side,5);
559 float *v1 = points->get(i);
560 sgAddVec3(v2,v1,inf);
561 sgAddVec3(v3,v2,side);
563 if ( type[i] == 1) { //POINT,WHITE
568 } else if (type[i] == 2) { //POINT,TAXI
573 } else if (type[i] == 3) { //SINGLE POLYGON,VASI
582 ssgLeaf *leaf3 = NULL;
583 leaf3 = new ssgVtxTable ( GL_POLYGON, vl, nl, NULL, NULL );
584 leaf3->setState( vasi_state );
585 runway_lights->addKid( leaf3 );
587 } else if (type[i] == 4) { //BACK-TO-BACK POLYGONS,TOUCHDOWN/THRESHOLD
603 ssgLeaf *leaf41 = NULL;
604 leaf41 = new ssgVtxTable ( GL_POLYGON, vl, nl, NULL, NULL );
605 leaf41->setState( touchdown_state );
606 runway_lights->addKid( leaf41 );
608 ssgLeaf *leaf42 = NULL;
609 leaf42 = new ssgVtxTable ( GL_POLYGON, vl1, nl1, NULL, NULL );
610 leaf42->setState( threshold_state );
611 runway_lights->addKid( leaf42 );
613 } else if ( type[i] == 5) { //POINT,WHITE, SEQUENCE LIGHTS (RABBIT)
617 ssgLeaf *leaf5 = NULL;
618 leaf5 = new ssgVtxTable ( GL_POINTS, vl, nl, NULL, NULL );
619 leaf5->setState( white_state );
620 lightmaps_sequence->addKid (leaf5);
622 } else if ( type[i] == 6) { //POINT,WHITE, SEQUENCE LIGHTS (RABBIT)
626 ssgLeaf *leaf6 = NULL;
627 leaf6 = new ssgVtxTable ( GL_POINTS, vl, nl, NULL, NULL );
628 leaf6->setState( yellow_state );
629 ols_transform->addKid (leaf6);
630 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
631 // lightmaps_sequence->addKid (leaf6);
632 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
634 } else if (type[i] == 7) { //POINT,RED
639 } else if (type[i] == 8) { //POINT,GREEN
644 } else if (type[i] == 9) { //POINT,YELLOW
653 leaf1 = new ssgVtxTable ( GL_POINTS, vlw, nlw, NULL, NULL );
654 leaf1->setState( white_state );
655 runway_lights->addKid( leaf1 );
657 leaf2 = new ssgVtxTable ( GL_POINTS, vlt, nlt, NULL, NULL );
658 leaf2->setState( taxi_state );
659 runway_lights->addKid( leaf2 );
661 leaf7 = new ssgVtxTable ( GL_POINTS, vlr, nlr, NULL, NULL );
662 leaf7->setState( red_state );
663 runway_lights->addKid( leaf7 );
665 leaf8 = new ssgVtxTable ( GL_POINTS, vlg, nlg, NULL, NULL );
666 leaf8->setState( green_state );
667 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
668 ols_transform->ref();
669 lightmaps_sequence->addKid (ols_transform);
670 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
671 lightmaps_sequence->addKid (leaf8);
673 leaf9 = new ssgVtxTable ( GL_POINTS, vly, nly, NULL, NULL );
674 leaf9->setState( yellow_state );
675 runway_lights->addKid( leaf9 );
677 lightmaps_sequence->select(0xFFFFFF);
678 return runway_lights;
682 #ifdef WISH_PLIB_WAS_THREADED // but it isn't
684 // Schedule tile to be freed/removed
685 void FGTileEntry::sched_removal() {
686 global_tile_mgr.ready_to_delete( this );
692 // Clean up the memory used by this tile and delete the arrays used by
693 // ssg as well as the whole ssg branch
694 void FGTileEntry::free_tile() {
696 SG_LOG( SG_TERRAIN, SG_INFO,
697 "FREEING TILE = (" << tile_bucket << ")" );
699 SG_LOG( SG_TERRAIN, SG_DEBUG,
700 " deleting " << nodes.size() << " nodes" );
703 // delete the ssg structures
704 SG_LOG( SG_TERRAIN, SG_DEBUG,
705 " deleting (leaf data) vertex, normal, and "
706 << " texture coordinate arrays" );
708 for ( i = 0; i < (int)vec3_ptrs.size(); ++i ) {
709 delete [] vec3_ptrs[i];
713 for ( i = 0; i < (int)vec2_ptrs.size(); ++i ) {
714 delete [] vec2_ptrs[i];
718 for ( i = 0; i < (int)index_ptrs.size(); ++i ) {
719 delete index_ptrs[i];
723 // delete the terrain branch (this should already have been
724 // disconnected from the scene graph)
725 ssgDeRefDelete( terra_transform );
727 if ( gnd_lights_transform ) {
728 // delete the terrain lighting branch (this should already have been
729 // disconnected from the scene graph)
730 ssgDeRefDelete( gnd_lights_transform );
734 if ( lightmaps_transform ) {
735 // delete the terrain lighting branch (this should already have been
736 // disconnected from the scene graph)
737 ssgDeRefDelete( lightmaps_transform );
743 // Update the ssg transform node for this tile so it can be
744 // properly drawn relative to our (0,0,0) point
745 void FGTileEntry::prep_ssg_node( const Point3D& p, float vis) {
746 if ( !loaded ) return;
750 // #define USE_UP_AND_COMING_PLIB_FEATURE
751 #ifdef USE_UP_AND_COMING_PLIB_FEATURE
752 terra_range->setRange( 0, SG_ZERO );
753 terra_range->setRange( 1, vis + bounding_radius );
754 gnd_lights_range->setRange( 0, SG_ZERO );
755 gnd_lights_range->setRange( 1, vis * 1.5 + bounding_radius );
759 ranges[1] = vis + bounding_radius;
760 terra_range->setRanges( ranges, 2 );
761 if ( gnd_lights_range ) {
762 ranges[1] = vis * 1.5 + bounding_radius;
763 gnd_lights_range->setRanges( ranges, 2 );
767 sgSetVec3( sgTrans, offset.x(), offset.y(), offset.z() );
768 terra_transform->setTransform( sgTrans );
770 if ( gnd_lights_transform ) {
771 // we need to lift the lights above the terrain to avoid
772 // z-buffer fighting. We do this based on our altitude and
773 // the distance this tile is away from scenery center.
776 sgCopyVec3( up, globals->get_current_view()->get_world_up() );
779 if ( current_aircraft.fdm_state ) {
780 agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
781 - scenery.get_cur_elev();
786 // sgTrans just happens to be the
787 // vector from scenery center to the center of this tile which
788 // is what we want to calculate the distance of
790 sgCopyVec3( to, sgTrans );
791 double dist = sgLengthVec3( to );
793 if ( general.get_glDepthBits() > 16 ) {
794 sgScaleVec3( up, 10.0 + agl / 100.0 + dist / 10000 );
796 sgScaleVec3( up, 10.0 + agl / 20.0 + dist / 5000 );
798 sgAddVec3( sgTrans, up );
799 gnd_lights_transform->setTransform( sgTrans );
801 // select which set of lights based on sun angle
802 float sun_angle = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
803 if ( sun_angle > 95 ) {
804 gnd_lights_brightness->select(0x04);
805 } else if ( sun_angle > 92 ) {
806 gnd_lights_brightness->select(0x02);
807 } else if ( sun_angle > 89 ) {
808 gnd_lights_brightness->select(0x01);
810 gnd_lights_brightness->select(0x00);
815 // Transform & Render runway lights - 23 Mar 2001
816 sgSetVec3( sgTrans, offset.x(), offset.y(), offset.z() );
817 if ( lightmaps_transform ) {
818 static unsigned int selectnode = 0;
819 // Run-time extension check.
820 if (!glutExtensionSupported("GL_EXT_point_parameters")) {
821 //use lightmaps on billboarded polygons
823 // using GL_EXT_point_parameters
825 // This part is same as ground-lights code above by Curt
827 sgCopyVec3( up1, globals->get_current_view()->get_world_up() );
830 if ( current_aircraft.fdm_state ) {
831 agl1 = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
832 - scenery.get_cur_elev();
837 // sgTrans just happens to be the
838 // vector from scenery center to the center of this tile which
839 // is what we want to calculate the distance of
841 sgCopyVec3( to1, sgTrans );
842 double dist1 = sgLengthVec3( to1 );
844 if ( general.get_glDepthBits() > 16 ) {
845 sgScaleVec3( up1, 0.0 + agl1 / 2000.0 + dist1 / 10000 );
847 sgScaleVec3( up1, 0.0 + agl1 / 20.0 + dist1 / 5000 );
849 sgAddVec3( sgTrans, up1 );
850 lightmaps_transform->setTransform( sgTrans );
852 float sun_angle1 = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
853 if ( (sun_angle1 > 89) ) {
854 lightmaps_brightness->select(0x01);
856 selectnode = selectnode | 0x000001;
857 if (selectnode > 0xFFFFFF) selectnode = 1;
858 lightmaps_sequence->select(selectnode);
860 lightmaps_brightness->select(0x00);
861 lightmaps_sequence->select(0x000000);
863 } // end of GL_EXT_point_parameters section
865 } // end of runway lights section
871 // Set up lights rendering call backs
872 static int fgLightsPredraw( ssgEntity *e ) {
874 #ifdef GL_EXT_point_parameters
875 if (glutExtensionSupported("GL_EXT_point_parameters")) {
876 static float quadratic[3] = {1.0, 0.01, 0.0001};
877 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
878 glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0);
886 static int fgLightsPostdraw( ssgEntity *e ) {
888 #ifdef GL_EXT_point_parameters
889 if (glutExtensionSupported("GL_EXT_point_parameters")) {
890 static float default_attenuation[3] = {1.0, 0.0, 0.0};
891 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
892 default_attenuation);
901 ssgLeaf* FGTileEntry::gen_lights( ssgVertexArray *lights, int inc, float bright ) {
902 // generate a repeatable random seed
903 float *p1 = lights->get( 0 );
904 unsigned int *seed = (unsigned int *)p1;
907 int size = lights->getNum() / inc;
909 // Allocate ssg structure
910 ssgVertexArray *vl = new ssgVertexArray( size + 1 );
911 ssgNormalArray *nl = NULL;
912 ssgTexCoordArray *tl = NULL;
913 ssgColourArray *cl = new ssgColourArray( size + 1 );
916 for ( int i = 0; i < lights->getNum(); ++i ) {
917 // this loop is slightly less efficient than it otherwise
918 // could be, but we want a red light to always be red, and a
919 // yellow light to always be yellow, etc. so we are trying to
920 // preserve the random sequence.
921 float zombie = sg_random();
922 if ( i % inc == 0 ) {
923 vl->add( lights->get(i) );
925 // factor = sg_random() ^ 2, range = 0 .. 1 concentrated towards 0
926 float factor = sg_random();
929 if ( zombie > 0.5 ) {
930 // 50% chance of yellowish
931 sgSetVec4( color, 0.9, 0.9, 0.3, bright - factor * 0.2 );
932 } else if ( zombie > 0.15 ) {
933 // 35% chance of whitish
934 sgSetVec4( color, 0.9, 0.9, 0.8, bright - factor * 0.2 );
935 } else if ( zombie > 0.05 ) {
936 // 10% chance of orangish
937 sgSetVec4( color, 0.9, 0.6, 0.2, bright - factor * 0.2 );
939 // 5% chance of redish
940 sgSetVec4( color, 0.9, 0.2, 0.2, bright - factor * 0.2 );
948 new ssgVtxTable ( GL_POINTS, vl, nl, tl, cl );
951 FGNewMat *newmat = material_lib.find( "LIGHTS" );
952 leaf->setState( newmat->get_state() );
953 leaf->setCallback( SSG_CALLBACK_PREDRAW, fgLightsPredraw );
954 leaf->setCallback( SSG_CALLBACK_POSTDRAW, fgLightsPostdraw );
961 FGTileEntry::obj_load( const std::string& path,
962 ssgVertexArray* lights, bool is_base )
964 ssgBranch* result = 0;
966 // try loading binary format
967 result = fgBinObjLoad( path, this, lights, is_base );
968 if ( result == NULL ) {
969 // next try the older ascii format
970 result = fgAsciiObjLoad( path, this, lights, is_base );
971 if ( result == NULL ) {
972 // default to an ocean tile
973 result = fgGenTile( path, this );
982 FGTileEntry::load( const SGPath& base, bool is_base )
984 SG_LOG( SG_TERRAIN, SG_INFO, "load() base = " << base.str() );
986 // Generate names for later use
987 string index_str = tile_bucket.gen_index_str();
989 SGPath tile_path = base;
990 tile_path.append( tile_bucket.gen_base_path() );
992 SGPath basename = tile_path;
993 basename.append( index_str );
994 // string path = basename.str();
996 SG_LOG( SG_TERRAIN, SG_INFO, "Loading tile " << basename.str() );
998 #define FG_MAX_LIGHTS 1000
1000 // obj_load() will generate ground lighting for us ...
1001 ssgVertexArray *light_pts = new ssgVertexArray( 100 );
1004 ssgVertexArray *lights_rway = new ssgVertexArray( 100 );
1005 ssgVertexArray *lights_dir = new ssgVertexArray( 100 );
1006 ssgVertexArray *lights_normal = new ssgVertexArray( 100 );
1007 int lights_type[FG_MAX_LIGHTS];
1010 ssgBranch* new_tile = new ssgBranch;
1012 // Check for master .stg (scene terra gear) file
1013 SGPath stg_name = basename;
1014 stg_name.concat( ".stg" );
1016 sg_gzifstream in( stg_name.str() );
1018 if ( in.is_open() ) {
1021 while ( ! in.eof() ) {
1024 if ( token == "OBJECT_BASE" ) {
1025 in >> name >> ::skipws;
1026 SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
1027 << " name = " << name );
1029 SGPath custom_path = tile_path;
1030 custom_path.append( name );
1032 ssgBranch *custom_obj
1033 = obj_load( custom_path.str(), light_pts, true );
1035 if ( custom_obj != NULL ) {
1036 new_tile -> addKid( custom_obj );
1038 } else if ( token == "OBJECT" ) {
1039 in >> name >> ::skipws;
1040 SG_LOG( SG_TERRAIN, SG_DEBUG, "token = " << token
1041 << " name = " << name );
1043 SGPath custom_path = tile_path;
1044 custom_path.append( name );
1046 ssgBranch *custom_obj
1047 = obj_load( custom_path.str(), NULL, false );
1048 if ( custom_obj != NULL ) {
1049 new_tile -> addKid( custom_obj );
1052 } else if ( token == "OBJECT_STATIC" ) {
1054 double lon, lat, elev, hdg;
1055 in >> name >> lon >> lat >> elev >> hdg >> ::skipws;
1056 SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
1057 << " name = " << name
1058 << " pos = " << lon << ", " << lat
1059 << " elevation = " << elev
1060 << " heading = " << hdg );
1062 // object loading is deferred to main render thread,
1063 // but lets figure out the paths right now.
1064 SGPath custom_path = tile_path;
1065 custom_path.append( name );
1068 WorldCoordinate( &obj_pos, center, lat, lon, elev, hdg );
1070 ssgTransform *obj_trans = new ssgTransform;
1071 obj_trans->setTransform( &obj_pos );
1073 // wire as much of the scene graph together as we can
1074 new_tile->addKid( obj_trans );
1076 // bump up the pending models count
1079 // push an entry onto the model load queue
1081 = new FGDeferredModel( custom_path.str(), tile_path.str(),
1083 FGTileMgr::model_ready( dm );
1084 } else if ( token == "OBJECT_TAXI_SIGN" ) {
1086 double lon, lat, elev, hdg;
1087 in >> name >> lon >> lat >> elev >> hdg >> ::skipws;
1088 SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
1089 << " name = " << name
1090 << " pos = " << lon << ", " << lat
1091 << " elevation = " << elev
1092 << " heading = " << hdg );
1094 // load the object itself
1095 SGPath custom_path = tile_path;
1096 custom_path.append( name );
1099 WorldCoordinate( &obj_pos, center, lat, lon, elev, hdg );
1101 ssgTransform *obj_trans = new ssgTransform;
1102 obj_trans->setTransform( &obj_pos );
1104 ssgBranch *custom_obj
1105 = gen_taxi_sign( custom_path.str(), name );
1107 // wire the pieces together
1108 if ( custom_obj != NULL ) {
1109 obj_trans -> addKid( custom_obj );
1111 new_tile->addKid( obj_trans );
1112 } else if ( token == "OBJECT_RUNWAY_SIGN" ) {
1114 double lon, lat, elev, hdg;
1115 in >> name >> lon >> lat >> elev >> hdg >> ::skipws;
1116 SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
1117 << " name = " << name
1118 << " pos = " << lon << ", " << lat
1119 << " elevation = " << elev
1120 << " heading = " << hdg );
1122 // load the object itself
1123 SGPath custom_path = tile_path;
1124 custom_path.append( name );
1127 WorldCoordinate( &obj_pos, center, lat, lon, elev, hdg );
1129 ssgTransform *obj_trans = new ssgTransform;
1130 obj_trans->setTransform( &obj_pos );
1132 ssgBranch *custom_obj
1133 = gen_runway_sign( custom_path.str(), name );
1135 // wire the pieces together
1136 if ( custom_obj != NULL ) {
1137 obj_trans -> addKid( custom_obj );
1139 new_tile->addKid( obj_trans );
1140 } else if ( token == "RWY_LIGHTS" ) {
1141 double lon, lat, hdg, len, width;
1142 string common, end1, end2;
1143 in >> lon >> lat >> hdg >> len >> width
1144 >> common >> end1 >> end2;
1145 SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
1146 << " pos = " << lon << ", " << lat
1148 << " size = " << len << ", " << width
1149 << " codes = " << common << " "
1150 << end1 << " " << end2 );
1152 SG_LOG( SG_TERRAIN, SG_ALERT,
1153 "Unknown token " << token << " in "
1154 << stg_name.str() );
1159 // no .stg file so this must be old scenery
1161 new_tile = obj_load( basename.str(), light_pts, true );
1163 // load custom objects
1164 SG_LOG( SG_TERRAIN, SG_DEBUG, "Checking for custom objects ..." );
1166 SGPath index_path = tile_path;
1167 index_path.append( index_str );
1168 index_path.concat( ".ind" );
1170 SG_LOG( SG_TERRAIN, SG_DEBUG, "Looking in " << index_path.str() );
1172 sg_gzifstream in( index_path.str() );
1174 if ( in.is_open() ) {
1177 while ( ! in.eof() ) {
1180 if ( token == "OBJECT" ) {
1181 in >> name >> ::skipws;
1182 SG_LOG( SG_TERRAIN, SG_DEBUG, "token = " << token
1183 << " name = " << name );
1185 SGPath custom_path = tile_path;
1186 custom_path.append( name );
1187 ssgBranch *custom_obj
1188 = obj_load( custom_path.str(), NULL, false );
1189 if ( (new_tile != NULL) && (custom_obj != NULL) ) {
1190 new_tile -> addKid( custom_obj );
1192 } else if ( token == "OBJECT_STATIC" ) {
1194 double lon, lat, elev, hdg;
1195 in >> name >> lon >> lat >> elev >> hdg >> ::skipws;
1196 SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
1197 << " name = " << name
1198 << " pos = " << lon << ", " << lat
1199 << " elevation = " << elev
1200 << " heading = " << hdg );
1202 // object loading is deferred to main render thread,
1203 // but lets figure out the paths right now.
1204 SGPath custom_path = tile_path;
1205 custom_path.append( name );
1208 WorldCoordinate( &obj_pos, center, lat, lon, elev, hdg );
1210 ssgTransform *obj_trans = new ssgTransform;
1211 obj_trans->setTransform( &obj_pos );
1213 // wire as much of the scene graph together as we can
1214 new_tile->addKid( obj_trans );
1216 // bump up the pending models count
1219 // push an entry onto the model load queue
1221 = new FGDeferredModel( custom_path.str(),
1224 FGTileMgr::model_ready( dm );
1225 } else if ( token == "OBJECT_TAXI_SIGN" ) {
1227 double lon, lat, elev, hdg;
1228 in >> name >> lon >> lat >> elev >> hdg >> ::skipws;
1229 SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
1230 << " name = " << name
1231 << " pos = " << lon << ", " << lat
1232 << " elevation = " << elev
1233 << " heading = " << hdg );
1235 // load the object itself
1236 SGPath custom_path = tile_path;
1237 custom_path.append( name );
1240 WorldCoordinate( &obj_pos, center, lat, lon, elev, hdg );
1242 ssgTransform *obj_trans = new ssgTransform;
1243 obj_trans->setTransform( &obj_pos );
1245 ssgBranch *custom_obj
1246 = gen_taxi_sign( custom_path.str(), name );
1248 // wire the pieces together
1249 if ( (new_tile != NULL) && (custom_obj != NULL) ) {
1250 obj_trans -> addKid( custom_obj );
1252 new_tile->addKid( obj_trans );
1253 } else if ( token == "OBJECT_RUNWAY_SIGN" ) {
1255 double lon, lat, elev, hdg;
1256 in >> name >> lon >> lat >> elev >> hdg >> ::skipws;
1257 SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
1258 << " name = " << name
1259 << " pos = " << lon << ", " << lat
1260 << " elevation = " << elev
1261 << " heading = " << hdg );
1263 // load the object itself
1264 SGPath custom_path = tile_path;
1265 custom_path.append( name );
1268 WorldCoordinate( &obj_pos, center, lat, lon, elev, hdg );
1270 ssgTransform *obj_trans = new ssgTransform;
1271 obj_trans->setTransform( &obj_pos );
1273 ssgBranch *custom_obj
1274 = gen_runway_sign( custom_path.str(), name );
1276 // wire the pieces together
1277 if ( (new_tile != NULL) && (custom_obj != NULL) ) {
1278 obj_trans -> addKid( custom_obj );
1280 new_tile->addKid( obj_trans );
1282 SG_LOG( SG_TERRAIN, SG_ALERT,
1283 "Unknown token " << token << " in "
1284 << index_path.str() );
1291 if ( new_tile != NULL ) {
1292 terra_range->addKid( new_tile );
1295 terra_transform->addKid( terra_range );
1297 // calculate initial tile offset
1298 SetOffset( scenery.get_center() );
1300 sgSetCoord( &sgcoord,
1301 offset.x(), offset.y(), offset.z(),
1303 terra_transform->setTransform( &sgcoord );
1304 // terrain->addKid( terra_transform );
1306 // Add ground lights to scene graph if any exist
1307 gnd_lights_transform = NULL;
1308 gnd_lights_range = NULL;
1309 if ( light_pts->getNum() ) {
1310 SG_LOG( SG_TERRAIN, SG_DEBUG, "generating lights" );
1311 gnd_lights_transform = new ssgTransform;
1312 gnd_lights_range = new ssgRangeSelector;
1313 gnd_lights_brightness = new ssgSelector;
1316 lights = gen_lights( light_pts, 4, 0.7 );
1317 gnd_lights_brightness->addKid( lights );
1319 lights = gen_lights( light_pts, 2, 0.85 );
1320 gnd_lights_brightness->addKid( lights );
1322 lights = gen_lights( light_pts, 1, 1.0 );
1323 gnd_lights_brightness->addKid( lights );
1325 gnd_lights_range->addKid( gnd_lights_brightness );
1326 gnd_lights_transform->addKid( gnd_lights_range );
1327 gnd_lights_transform->setTransform( &sgcoord );
1328 // ground->addKid( gnd_lights_transform );
1332 // Create runway lights - 23 Mar 2001
1333 lightmaps_transform = NULL;
1334 lightmaps_sequence = NULL;
1335 ols_transform = NULL;
1336 // lightmaps_range = NULL;
1338 if ( lights_rway->getNum() ) {
1339 SG_LOG( SG_TERRAIN, SG_DEBUG, "generating airport lights" );
1340 lightmaps_transform = new ssgTransform;
1341 // lightmaps_range = new ssgRangeSelector;
1342 lightmaps_brightness = new ssgSelector;
1343 lightmaps_sequence = new ssgSelector;
1344 ols_transform = new ssgTransform;
1345 ssgBranch *lightmaps_branch;
1347 // call function to generate the runway lights
1348 lightmaps_branch = gen_runway_lights( lights_rway,
1349 lights_normal, lights_dir, lights_type);
1350 lightmaps_brightness->addKid( lightmaps_branch );
1352 // build the runway lights' scene
1353 // lightmaps_range->addKid( lightmaps_brightness ); //dont know why this doesnt work !!
1354 // lightmaps_transform->addKid( lightmaps_range ); //dont know why this doesnt work !!
1355 lightmaps_transform->addKid( lightmaps_brightness );
1356 lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
1357 lightmaps_transform->addKid( lightmaps_sequence );
1358 lightmaps_transform->setTransform( &sgcoord );
1365 FGTileEntry::add_ssg_nodes( ssgBranch* terrain, ssgBranch* ground )
1367 // bump up the ref count so we can remove this later without
1368 // having ssg try to free the memory.
1369 terra_transform->ref();
1370 terrain->addKid( terra_transform );
1372 SG_LOG( SG_TERRAIN, SG_DEBUG,
1373 "connected a tile into scene graph. terra_transform = "
1374 << terra_transform );
1375 SG_LOG( SG_TERRAIN, SG_DEBUG, "num parents now = "
1376 << terra_transform->getNumParents() );
1378 if ( gnd_lights_transform != 0 ) {
1379 // bump up the ref count so we can remove this later without
1380 // having ssg try to free the memory.
1381 gnd_lights_transform->ref();
1382 ground->addKid( gnd_lights_transform );
1386 if ( lightmaps_transform != 0 ) {
1387 // bump up the ref count so we can remove this later without
1388 // having ssg try to free the memory.
1389 lightmaps_transform->ref();
1390 ground->addKid( lightmaps_transform );
1399 FGTileEntry::disconnect_ssg_nodes()
1401 SG_LOG( SG_TERRAIN, SG_INFO, "disconnecting ssg nodes" );
1404 SG_LOG( SG_TERRAIN, SG_INFO, "removing a not-fully loaded tile!" );
1406 SG_LOG( SG_TERRAIN, SG_INFO, "removing a fully loaded tile! terra_transform = " << terra_transform );
1409 // find the terrain branch parent
1410 int pcount = terra_transform->getNumParents();
1412 // find the first parent (should only be one)
1413 ssgBranch *parent = terra_transform->getParent( 0 ) ;
1415 // disconnect the tile (we previously ref()'d it so it
1416 // won't get freed now)
1417 parent->removeKid( terra_transform );
1419 SG_LOG( SG_TERRAIN, SG_ALERT,
1420 "parent pointer is NULL! Dying" );
1424 SG_LOG( SG_TERRAIN, SG_ALERT,
1425 "Parent count is zero for an ssg tile! Dying" );
1429 // find the terrain lighting branch
1430 if ( gnd_lights_transform ) {
1431 pcount = gnd_lights_transform->getNumParents();
1433 // find the first parent (should only be one)
1434 ssgBranch *parent = gnd_lights_transform->getParent( 0 ) ;
1436 // disconnect the light branch (we previously ref()'d
1437 // it so it won't get freed now)
1438 parent->removeKid( gnd_lights_transform );
1440 SG_LOG( SG_TERRAIN, SG_ALERT,
1441 "parent pointer is NULL! Dying" );
1445 SG_LOG( SG_TERRAIN, SG_ALERT,
1446 "Parent count is zero for an ssg light tile! Dying" );
1452 //runway lights - 23 Mar 2001
1453 // Delete runway lights and free memory
1454 if ( lightmaps_transform ) {
1455 // delete the runway lighting branch
1456 pcount = lightmaps_transform->getNumParents();
1458 // find the first parent (should only be one)
1459 ssgBranch *parent = lightmaps_transform->getParent( 0 ) ;
1461 parent->removeKid( lightmaps_transform );
1462 lightmaps_transform = NULL;
1464 SG_LOG( SG_TERRAIN, SG_ALERT,
1465 "lightmaps parent pointer is NULL! Dying" );
1469 SG_LOG( SG_TERRAIN, SG_ALERT,
1470 "Parent count is zero for an ssg lightmap tile! Dying" );