From: curt Date: Tue, 30 Dec 2003 05:53:50 +0000 (+0000) Subject: Track some additional data required for computing vasi/papi colors. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a43f5c8d21e957e96c019d91b9a8afd19e5008d1;p=simgear.git Track some additional data required for computing vasi/papi colors. --- diff --git a/simgear/scene/tgdb/Makefile.am b/simgear/scene/tgdb/Makefile.am index 91a62853..bdc8cf53 100644 --- a/simgear/scene/tgdb/Makefile.am +++ b/simgear/scene/tgdb/Makefile.am @@ -9,7 +9,8 @@ include_HEADERS = \ leaf.hxx \ obj.hxx \ pt_lights.hxx \ - userdata.hxx + userdata.hxx \ + vasi.hxx libsgtgdb_a_SOURCES = \ apt_signs.cxx \ diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index d8084de0..7ec65041 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -351,8 +351,8 @@ bool sgBinObjLoad( const string& path, const bool is_base, // cout << "pts_v.size() = " << pts_v.size() << endl; if ( pt_materials[i].substr(0, 3) == "RWY" ) { // airport environment lighting - sgVec3 up; - sgSetVec3( up, center->x(), center->y(), center->z() ); + sgdVec3 up; + sgdSetVec3( up, center->x(), center->y(), center->z() ); // returns a transform -> lod -> leaf structure ssgBranch *branch = sgMakeDirectionalLights( nodes, normals, pts_v[i], pts_n[i], diff --git a/simgear/scene/tgdb/pt_lights.cxx b/simgear/scene/tgdb/pt_lights.cxx index 539c99e0..6512a9e0 100644 --- a/simgear/scene/tgdb/pt_lights.cxx +++ b/simgear/scene/tgdb/pt_lights.cxx @@ -26,6 +26,8 @@ #include #include +#include "vasi.hxx" + #include "pt_lights.hxx" @@ -161,7 +163,7 @@ static ssgTransform *gen_dir_light_group( const point_list &nodes, const int_list &pnt_i, const int_list &nml_i, const SGMaterial *mat, - sgVec3 up, bool vertical = false ) + sgVec3 up, bool vertical ) { sgVec3 center; calc_center_point( nodes, pnt_i, center ); @@ -548,7 +550,8 @@ static ssgTransform *gen_rabbit_lights( const point_list &nodes, #if 0 // debugging infrastructure // Generate a normal line static ssgLeaf *gen_normal_line( SGMaterialLib *matlib, - sgVec3 pt, sgVec3 dir, sgVec3 up ) { + sgVec3 pt, sgVec3 dir, sgVec3 up ) +{ ssgVertexArray *vl = new ssgVertexArray( 3 ); ssgColourArray *cl = new ssgColourArray( 3 ); @@ -581,8 +584,11 @@ ssgBranch *sgMakeDirectionalLights( const point_list &nodes, const int_list &nml_i, SGMaterialLib *matlib, const string &material, - sgVec3 up ) + sgdVec3 dup ) { + sgVec3 up; + sgSetVec3( up, dup ); + sgVec3 nup; sgNormalizeVec3( nup, up ); @@ -604,6 +610,35 @@ ssgBranch *sgMakeDirectionalLights( const point_list &nodes, pnt_i, nml_i, matlib, up ); return rabbit; + } else if ( material == "RWY_VASI_LIGHTS" ) { + ssgTransform *light_group = gen_dir_light_group( nodes, normals, pnt_i, + nml_i, mat, up, + false ); + + // calculate the geocentric position of this vasi and use it + // to init the vasi structure and save it in the userdata slot + sgdVec3 pos; + sgdSetVec3( pos, nodes[pnt_i[0]][0], nodes[pnt_i[0]][1], + nodes[pnt_i[0]][2] ); + // dup is the double version of the "up" vector which is also + // the reference center point of this tile. The reference + // center + the coordinate of the first light gives the actual + // location of the first light. + sgdAddVec3( pos, dup ); + + // extract a pointer to the leaf node so a) we can set the + // phat light call back and b) we can pass this to the vasi + // structure. + ssgRangeSelector *lod = (ssgRangeSelector *)light_group->getKid(0); + ssgLeaf *leaf = (ssgLeaf *)lod->getKid(0); + leaf->setCallback( SSG_CALLBACK_PREDRAW, StrobePreDraw ); + leaf->setCallback( SSG_CALLBACK_POSTDRAW, StrobePostDraw ); + + SGVASIUserData *vasi = new SGVASIUserData( pos, leaf ); + + light_group->setUserData( vasi ); + + return light_group; } else if ( material == "RWY_BLUE_TAXIWAY_LIGHTS" ) { ssgTransform *light_group = gen_dir_light_group( nodes, normals, pnt_i, nml_i, mat, up, @@ -611,7 +646,8 @@ ssgBranch *sgMakeDirectionalLights( const point_list &nodes, return light_group; } else { ssgTransform *light_group = gen_dir_light_group( nodes, normals, pnt_i, - nml_i, mat, up ); + nml_i, mat, up, + false ); return light_group; } diff --git a/simgear/scene/tgdb/pt_lights.hxx b/simgear/scene/tgdb/pt_lights.hxx index 9bf2606e..6cce5873 100644 --- a/simgear/scene/tgdb/pt_lights.hxx +++ b/simgear/scene/tgdb/pt_lights.hxx @@ -87,7 +87,7 @@ ssgBranch *sgMakeDirectionalLights( const point_list &nodes, const int_list &nml_i, SGMaterialLib *matlib, const string &material, - sgVec3 up ); + sgdVec3 dup ); #endif // _SG_PT_LIGHTS_HXX diff --git a/simgear/scene/tgdb/vasi.hxx b/simgear/scene/tgdb/vasi.hxx new file mode 100644 index 00000000..388aecfa --- /dev/null +++ b/simgear/scene/tgdb/vasi.hxx @@ -0,0 +1,80 @@ +// vasi.hxx -- a class to hold some critical vasi data +// +// Written by Curtis Olson, started December 2003. +// +// Copyright (C) 2003 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifndef _SG_VASI_HXX +#define _SG_VASI_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#include + +#include STL_STRING +SG_USING_STD(string); + +#include // plib include + +#include + + +class SGVASIUserData : public ssgBase +{ + +private: + + sgdVec3 abs_pos; + double alt_m; + ssgLeaf *leaf; + +public: + + SGVASIUserData( sgdVec3 pos_cart, ssgLeaf *l ) { + sgdCopyVec3( abs_pos, pos_cart ); + + double lat, lon; + sgCartToGeod( abs_pos, &lat, &lon, &alt_m ); + + leaf = l; + } + + ~SGVASIUserData() {} + + double get_alt_m() { return alt_m; } + double *get_abs_pos() { return abs_pos; } + + // color is a number in the range of 0.0 = full red, 1.0 = full white + void set_color( float color ) { + int count = leaf->getNumColours(); + for ( int i = 0; i < count; ++i ) { + float *entry = leaf->getColour( i ); + entry[1] = color; + entry[2] = color; + } + } +}; + + +#endif // _SG_VASI_HXX