1998-09-14 02:14:00 +00:00
|
|
|
//
|
1999-02-01 21:08:33 +00:00
|
|
|
// genapt.cxx -- generate airport scenery from the given definition file
|
1998-09-14 02:14:00 +00:00
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started September 1998.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
|
|
|
//
|
|
|
|
// 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$
|
|
|
|
|
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#include <Include/compiler.h>
|
1998-09-14 02:14:00 +00:00
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#include STL_STRING
|
|
|
|
#include <vector>
|
1998-09-14 02:14:00 +00:00
|
|
|
|
1998-11-23 21:48:09 +00:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
# define exception c_exception
|
|
|
|
#endif
|
|
|
|
#include <math.h>
|
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#ifdef FG_HAVE_NATIVE_SGI_COMPILERS
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
1998-11-06 21:17:31 +00:00
|
|
|
#include <Debug/logstream.hxx>
|
1998-10-16 00:51:46 +00:00
|
|
|
// #include <Include/fg_types.h>
|
1998-10-16 23:26:44 +00:00
|
|
|
#include <Math/fg_geodesy.hxx>
|
1998-09-14 02:14:00 +00:00
|
|
|
#include <Math/mat3.h>
|
1998-10-16 00:51:46 +00:00
|
|
|
#include <Math/point3d.hxx>
|
1998-09-14 02:14:00 +00:00
|
|
|
#include <Math/polar3d.hxx>
|
|
|
|
#include <Misc/fgstream.hxx>
|
1999-05-12 04:24:55 +00:00
|
|
|
#include <Objects/materialmgr.hxx>
|
1998-09-14 02:14:00 +00:00
|
|
|
|
|
|
|
// #include <gpc/gpc.h>
|
|
|
|
|
|
|
|
#include "genapt.hxx"
|
|
|
|
|
1999-03-02 01:02:31 +00:00
|
|
|
FG_USING_STD(string);
|
|
|
|
FG_USING_STD(vector);
|
1999-02-26 22:08:34 +00:00
|
|
|
|
1998-09-14 02:14:00 +00:00
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
typedef vector < Point3D > container;
|
1998-09-14 02:14:00 +00:00
|
|
|
typedef container::iterator iterator;
|
|
|
|
typedef container::const_iterator const_iterator;
|
|
|
|
|
|
|
|
|
|
|
|
#define FG_APT_BASE_TEX_CONSTANT 2000.0
|
|
|
|
|
1998-09-14 12:44:30 +00:00
|
|
|
// Calculate texture coordinates for a given point.
|
1998-10-16 00:51:46 +00:00
|
|
|
static Point3D calc_tex_coords(double *node, const Point3D& ref) {
|
|
|
|
Point3D cp;
|
|
|
|
Point3D pp;
|
1998-09-14 12:44:30 +00:00
|
|
|
|
1998-10-18 01:17:16 +00:00
|
|
|
cp = Point3D( node[0] + ref.x(), node[1] + ref.y(), node[2] + ref.z() );
|
1998-09-14 12:44:30 +00:00
|
|
|
|
|
|
|
pp = fgCartToPolar3d(cp);
|
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
pp.setx( fmod(FG_APT_BASE_TEX_CONSTANT * pp.x(), 10.0) );
|
|
|
|
pp.sety( fmod(FG_APT_BASE_TEX_CONSTANT * pp.y(), 10.0) );
|
1998-09-14 12:44:30 +00:00
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
if ( pp.x() < 0.0 ) {
|
|
|
|
pp.setx( pp.x() + 10.0 );
|
1998-09-14 12:44:30 +00:00
|
|
|
}
|
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
if ( pp.y() < 0.0 ) {
|
|
|
|
pp.sety( pp.y() + 10.0 );
|
1998-09-14 12:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(pp);
|
|
|
|
}
|
1998-09-14 02:14:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
// generate the actual base area for the airport
|
|
|
|
static void
|
1998-10-16 00:51:46 +00:00
|
|
|
gen_base( const Point3D& average, const container& perimeter, fgTILE *t)
|
1998-09-14 02:14:00 +00:00
|
|
|
{
|
|
|
|
GLint display_list;
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D cart, cart_trans, tex;
|
1998-09-14 02:14:00 +00:00
|
|
|
MAT3vec normal;
|
|
|
|
double dist, max_dist, temp;
|
|
|
|
int center_num, i;
|
|
|
|
|
|
|
|
fgFRAGMENT fragment;
|
|
|
|
|
|
|
|
max_dist = 0.0;
|
|
|
|
|
1998-11-07 19:07:06 +00:00
|
|
|
FG_LOG( FG_TERRAIN, FG_INFO,
|
|
|
|
"generating airport base for size = " << perimeter.size() );
|
1998-09-14 02:14:00 +00:00
|
|
|
|
|
|
|
fragment.init();
|
|
|
|
fragment.tile_ptr = t;
|
|
|
|
|
|
|
|
// find airport base material in the properties list
|
|
|
|
if ( ! material_mgr.find( APT_BASE_MATERIAL, fragment.material_ptr )) {
|
1998-11-06 21:17:31 +00:00
|
|
|
FG_LOG( FG_TERRAIN, FG_ALERT,
|
|
|
|
"Ack! unknown material name = " << APT_BASE_MATERIAL
|
|
|
|
<< " in fgAptGenerat()" );
|
1998-09-14 02:14:00 +00:00
|
|
|
}
|
|
|
|
|
1998-11-07 19:07:06 +00:00
|
|
|
FG_LOG( FG_TERRAIN, FG_INFO,
|
|
|
|
" tile center = "
|
|
|
|
<< t->center.x() << " " << t->center.y() << " " << t->center.z() );
|
|
|
|
FG_LOG( FG_TERRAIN, FG_INFO,
|
|
|
|
" airport center = "
|
|
|
|
<< average.x() << " " << average.y() << " " << average.z() );
|
1998-10-16 00:51:46 +00:00
|
|
|
fragment.center = average;
|
|
|
|
|
|
|
|
normal[0] = average.x();
|
|
|
|
normal[1] = average.y();
|
|
|
|
normal[2] = average.z();
|
1998-09-14 02:14:00 +00:00
|
|
|
MAT3_NORMALIZE_VEC(normal, temp);
|
|
|
|
|
|
|
|
display_list = xglGenLists(1);
|
|
|
|
xglNewList(display_list, GL_COMPILE);
|
|
|
|
xglBegin(GL_TRIANGLE_FAN);
|
|
|
|
|
1998-09-14 12:44:30 +00:00
|
|
|
// first point center of fan
|
1998-10-16 00:51:46 +00:00
|
|
|
cart_trans = average - t->center;
|
|
|
|
t->nodes[t->ncount][0] = cart_trans.x();
|
|
|
|
t->nodes[t->ncount][1] = cart_trans.y();
|
|
|
|
t->nodes[t->ncount][2] = cart_trans.z();
|
1998-09-14 12:44:30 +00:00
|
|
|
center_num = t->ncount;
|
1998-09-14 02:14:00 +00:00
|
|
|
t->ncount++;
|
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
tex = calc_tex_coords( t->nodes[t->ncount-1], t->center );
|
|
|
|
xglTexCoord2f(tex.x(), tex.y());
|
1998-09-14 02:14:00 +00:00
|
|
|
xglNormal3dv(normal);
|
1998-09-14 12:44:30 +00:00
|
|
|
xglVertex3dv(t->nodes[t->ncount-1]);
|
1998-09-14 02:14:00 +00:00
|
|
|
|
1998-09-14 12:44:30 +00:00
|
|
|
// first point on perimeter
|
1998-10-16 00:51:46 +00:00
|
|
|
const_iterator current = perimeter.begin();
|
1998-10-16 23:26:44 +00:00
|
|
|
cart = fgGeodToCart( *current );
|
1998-10-16 00:51:46 +00:00
|
|
|
cart_trans = cart - t->center;
|
|
|
|
t->nodes[t->ncount][0] = cart_trans.x();
|
|
|
|
t->nodes[t->ncount][1] = cart_trans.y();
|
|
|
|
t->nodes[t->ncount][2] = cart_trans.z();
|
1998-09-14 02:14:00 +00:00
|
|
|
t->ncount++;
|
|
|
|
|
1998-09-14 12:44:30 +00:00
|
|
|
i = 1;
|
1998-10-16 00:51:46 +00:00
|
|
|
tex = calc_tex_coords( t->nodes[i], t->center );
|
1999-02-01 21:08:33 +00:00
|
|
|
dist = cart.distance3Dsquared(average);
|
1998-09-14 02:14:00 +00:00
|
|
|
if ( dist > max_dist ) {
|
|
|
|
max_dist = dist;
|
|
|
|
}
|
1998-10-16 00:51:46 +00:00
|
|
|
xglTexCoord2f(tex.x(), tex.y());
|
1998-09-14 12:44:30 +00:00
|
|
|
xglVertex3dv(t->nodes[i]);
|
|
|
|
++current;
|
|
|
|
++i;
|
1998-09-14 02:14:00 +00:00
|
|
|
|
|
|
|
const_iterator last = perimeter.end();
|
|
|
|
for ( ; current != last; ++current ) {
|
1998-10-16 23:26:44 +00:00
|
|
|
cart = fgGeodToCart( *current );
|
1998-10-16 00:51:46 +00:00
|
|
|
cart_trans = cart - t->center;
|
|
|
|
t->nodes[t->ncount][0] = cart_trans.x();
|
|
|
|
t->nodes[t->ncount][1] = cart_trans.y();
|
|
|
|
t->nodes[t->ncount][2] = cart_trans.z();
|
1998-09-14 02:14:00 +00:00
|
|
|
t->ncount++;
|
1998-09-14 12:44:30 +00:00
|
|
|
fragment.add_face(center_num, i - 1, i);
|
1998-09-14 02:14:00 +00:00
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
tex = calc_tex_coords( t->nodes[i], t->center );
|
1999-02-01 21:08:33 +00:00
|
|
|
dist = cart.distance3Dsquared(average);
|
1998-09-14 02:14:00 +00:00
|
|
|
if ( dist > max_dist ) {
|
|
|
|
max_dist = dist;
|
|
|
|
}
|
1998-10-16 00:51:46 +00:00
|
|
|
xglTexCoord2f(tex.x(), tex.y());
|
1998-09-14 12:44:30 +00:00
|
|
|
xglVertex3dv(t->nodes[i]);
|
|
|
|
i++;
|
1998-09-14 02:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// last point (first point in perimeter list)
|
|
|
|
current = perimeter.begin();
|
1998-10-16 23:26:44 +00:00
|
|
|
cart = fgGeodToCart( *current );
|
1998-10-16 00:51:46 +00:00
|
|
|
cart_trans = cart - t->center;
|
1998-09-14 12:44:30 +00:00
|
|
|
fragment.add_face(center_num, i - 1, 1);
|
1998-09-14 02:14:00 +00:00
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
tex = calc_tex_coords( t->nodes[1], t->center );
|
|
|
|
xglTexCoord2f(tex.x(), tex.y());
|
1998-09-14 12:44:30 +00:00
|
|
|
xglVertex3dv(t->nodes[1]);
|
1998-09-14 02:14:00 +00:00
|
|
|
|
|
|
|
xglEnd();
|
|
|
|
xglEndList();
|
|
|
|
|
1999-02-01 21:08:33 +00:00
|
|
|
fragment.bounding_radius = sqrt(max_dist);
|
1998-09-14 02:14:00 +00:00
|
|
|
fragment.display_list = display_list;
|
|
|
|
|
|
|
|
t->fragment_list.push_back(fragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Load a .apt file and register the GL fragments with the
|
|
|
|
// corresponding tile
|
|
|
|
int
|
|
|
|
fgAptGenerate(const string& path, fgTILE *tile)
|
|
|
|
{
|
|
|
|
string token;
|
|
|
|
string apt_id, apt_name;
|
|
|
|
char c;
|
1998-09-21 20:55:00 +00:00
|
|
|
int i = 1;
|
1998-09-14 02:14:00 +00:00
|
|
|
|
|
|
|
// face list (this indexes into the master tile vertex list)
|
|
|
|
container perimeter;
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D p, average;
|
|
|
|
double avex = 0.0, avey = 0.0, avez = 0.0;
|
1998-09-14 02:14:00 +00:00
|
|
|
int size;
|
|
|
|
|
|
|
|
// gpc_vertex p_2d, list_2d[MAX_PERIMETER];
|
|
|
|
// gpc_vertex_list perimeter_2d;
|
|
|
|
|
|
|
|
fg_gzifstream in( path );
|
1999-06-05 12:45:40 +00:00
|
|
|
if ( !in.is_open() ) {
|
|
|
|
// return immediately assuming an airport file for this tile
|
1998-09-14 02:14:00 +00:00
|
|
|
// doesn't exist.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
apt_id = "";
|
|
|
|
|
|
|
|
// read in each line of the file
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> skipcomment;
|
1998-09-14 02:14:00 +00:00
|
|
|
while ( ! in.eof() )
|
|
|
|
{
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> token;
|
1998-09-14 02:14:00 +00:00
|
|
|
|
|
|
|
if ( token == "a" ) {
|
|
|
|
// airport info record (start of airport)
|
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
if ( apt_id.length() > 0 ) {
|
1998-09-14 02:14:00 +00:00
|
|
|
// we have just finished reading and airport record.
|
|
|
|
// process the info
|
|
|
|
gen_base(average, perimeter, tile);
|
|
|
|
}
|
|
|
|
|
1998-11-07 19:07:06 +00:00
|
|
|
FG_LOG( FG_TERRAIN, FG_INFO, "Reading airport record" );
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> apt_id;
|
1998-09-14 02:14:00 +00:00
|
|
|
apt_name = "";
|
1998-09-21 20:55:00 +00:00
|
|
|
i = 1;
|
1998-10-16 00:51:46 +00:00
|
|
|
avex = avey = avez = 0.0;
|
1998-09-14 02:14:00 +00:00
|
|
|
perimeter.erase( perimeter.begin(), perimeter.end() );
|
|
|
|
// skip to end of line.
|
|
|
|
while ( in.get(c) && c != '\n' ) {
|
|
|
|
apt_name += c;
|
|
|
|
}
|
1998-11-07 19:07:06 +00:00
|
|
|
FG_LOG( FG_TERRAIN, FG_INFO,
|
|
|
|
"\tID = " << apt_id << " Name = " << apt_name );
|
1998-09-14 02:14:00 +00:00
|
|
|
} else if ( token == "p" ) {
|
|
|
|
// airport area bounding polygon coordinate. These
|
|
|
|
// specify a convex hull that should already have been cut
|
|
|
|
// out of the base terrain. The points are given in
|
|
|
|
// counter clockwise order and are specified in lon/lat
|
|
|
|
// degrees.
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> p;
|
1998-10-16 00:51:46 +00:00
|
|
|
avex += tile->nodes[i][0];
|
|
|
|
avey += tile->nodes[i][1];
|
|
|
|
avez += tile->nodes[i][2];
|
1998-09-14 02:14:00 +00:00
|
|
|
perimeter.push_back(p);
|
1998-09-21 20:55:00 +00:00
|
|
|
++i;
|
1998-09-14 02:14:00 +00:00
|
|
|
} else if ( token == "r" ) {
|
|
|
|
// runway record
|
|
|
|
// skip for now
|
|
|
|
while ( in.get(c) && c != '\n' );
|
|
|
|
}
|
|
|
|
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> skipcomment;
|
1998-09-14 02:14:00 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
if ( apt_id.length() > 0 ) {
|
1998-09-14 02:14:00 +00:00
|
|
|
// we have just finished reading and airport record.
|
|
|
|
// process the info
|
|
|
|
size = perimeter.size();
|
1998-10-18 01:17:16 +00:00
|
|
|
average = Point3D( avex / (double)size + tile->center.x(),
|
|
|
|
avey / (double)size + tile->center.y(),
|
|
|
|
avez / (double)size + tile->center.z() );
|
1998-09-14 02:14:00 +00:00
|
|
|
|
|
|
|
gen_base(average, perimeter, tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|