1
0
Fork 0

Simplify runway texture coordinate generation.

This commit is contained in:
curt 2002-10-25 16:52:01 +00:00
parent 8817ba7454
commit 53a2f9c347
4 changed files with 71 additions and 86 deletions

View file

@ -85,14 +85,14 @@ static FGPolygon rwy_section_tex_coords( const FGPolygon& in_poly,
// double length = rwy.length * SG_FEET_TO_METER;
// double width = rwy.width * SG_FEET_TO_METER;
Point3D center = tp.get_center();
Point3D min = tp.get_min();
Point3D max = tp.get_max();
double angle = tp.get_angle();
SG_LOG(SG_GENERAL, SG_DEBUG, "section heading = " << angle);
SG_LOG(SG_GENERAL, SG_DEBUG, "center = " << center);
SG_LOG(SG_GENERAL, SG_DEBUG, "min = " << min);
SG_LOG(SG_GENERAL, SG_DEBUG, "max = " << max);
Point3D ref = tp.get_ref();
double width = tp.get_width();
double length = tp.get_length();
double heading = tp.get_heading();
SG_LOG( SG_GENERAL, SG_INFO, "section ref = " << ref );
SG_LOG( SG_GENERAL, SG_INFO, " width = " << width );
SG_LOG( SG_GENERAL, SG_INFO, " length = " << length );
SG_LOG( SG_GENERAL, SG_INFO, " heading = " << heading );
Point3D p, t;
double x, y, tx, ty;
@ -110,38 +110,36 @@ static FGPolygon rwy_section_tex_coords( const FGPolygon& in_poly,
// and ending az1, az2 and distance (s). Lat, lon, and
// azimuth are in degrees. distance in meters
double az1, az2, dist;
geo_inverse_wgs_84( 0, center.y(), center.x(), p.y(), p.x(),
geo_inverse_wgs_84( 0, ref.y(), ref.x(), p.y(), p.x(),
&az1, &az2, &dist );
// SG_LOG(SG_GENERAL, SG_DEBUG, "basic course = " << az1);
SG_LOG(SG_GENERAL, SG_INFO, "basic course = " << az2);
//
// 2. Rotate this back into a coordinate system where Y
// runs the length of the runway and X runs crossways.
//
double course = az1 - angle + 90;
// SG_LOG(SG_GENERAL, SG_DEBUG, "course = " << course);
double course = az2 - heading;
while ( course < -360 ) { course += 360; }
while ( course > 360 ) { course -= 360; }
// SG_LOG(SG_GENERAL, SG_DEBUG, "Dist = " << dist);
// SG_LOG(SG_GENERAL, SG_DEBUG, " Course = " << course * 180.0 / SGD_PI);
SG_LOG( SG_GENERAL, SG_INFO,
" course = " << course << " dist = " << dist );
//
// 3. Convert from polar to cartesian coordinates
//
x = cos( course * SGD_DEGREES_TO_RADIANS ) * dist;
y = sin( course * SGD_DEGREES_TO_RADIANS ) * dist;
SG_LOG(SG_GENERAL, SG_DEBUG, " x = " << x << " y = " << y);
SG_LOG(SG_GENERAL, SG_DEBUG, " min = " << min);
SG_LOG(SG_GENERAL, SG_DEBUG, " max = " << max);
x = sin( course * SGD_DEGREES_TO_RADIANS ) * dist;
y = cos( course * SGD_DEGREES_TO_RADIANS ) * dist;
SG_LOG(SG_GENERAL, SG_INFO, " x = " << x << " y = " << y);
//
// 4. Map x, y point into texture coordinates
//
tx = (x - min.x()) / (max.x() - min.x());
tx = ((int)(tx * 100)) / 100.0;
SG_LOG(SG_GENERAL, SG_DEBUG, " (" << tx << ")");
tx = x / width;
// tx = ((int)(tx * 100)) / 100.0;
SG_LOG(SG_GENERAL, SG_INFO, " (" << tx << ")");
if ( clip_result ) {
if ( tx < 0.0 ) { tx = 0.0; }
@ -149,9 +147,9 @@ static FGPolygon rwy_section_tex_coords( const FGPolygon& in_poly,
}
// ty = (y - min.y()) / (max.y() - min.y());
ty = (max.y() - y) / (max.y() - min.y());
ty = ((int)(ty * 100)) / 100.0;
SG_LOG(SG_GENERAL, SG_DEBUG, " (" << ty << ")");
ty = y / length;
// ty = ((int)(ty * 100)) / 100.0;
SG_LOG(SG_GENERAL, SG_INFO, " (" << ty << ")");
if ( clip_result ) {
if ( ty < 0.0 ) { ty = 0.0; }
@ -279,10 +277,10 @@ void build_runway( const FGRunway& rwy_info,
if ( !rwy_info.really_taxiway ) {
material = "pc_"; // concrete
} else {
if ( rwy_info.width > 150 ) {
material = "pc_tiedown";
} else {
if ( rwy_info.width <= 150 ) {
material = "pc_taxiway";
} else {
material = "pc_tiedown";
}
}
} else if ( surface_flag == "D" ) {
@ -713,7 +711,7 @@ void build_airport( string airport_raw, float alt_m, string_list& runways_raw,
// tesselate the polygons and prepair them for final output
for ( i = 0; i < (int)rwy_polys.size(); ++i ) {
SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating section = " << i);
SG_LOG(SG_GENERAL, SG_INFO, "Tesselating section = " << i);
FGPolygon poly = rwy_polys[i].get_poly();
SG_LOG(SG_GENERAL, SG_DEBUG, "total size before = " << poly.total_size());

View file

@ -225,25 +225,19 @@ void gen_runway_section( const FGRunway& rwy_info,
// lines on the texture back to the edge of the runway where they
// belong.
double len = rwy_info.length / 2.0 + 2;
double start_len = len - ( len * startl_pct );
double end_len = len - ( len * endl_pct );
double sect_len = len * ( endl_pct - startl_pct );
// we add 2' to both sides of the runway (4' total) for texture
// overlap. This puts the lines on the texture back to the edge
// of the runway where they belong.
double wid = rwy_info.width + 4;
double start_wid = -wid / 2.0 + wid * startw_pct;
double end_wid = -wid / 2.0 + wid * endw_pct;
double sect_wid = wid * ( endw_pct - startw_pct );
FGTexParams tp;
tp = FGTexParams( Point3D( rwy_info.lon, rwy_info.lat, 0 ),
Point3D( start_wid * SG_FEET_TO_METER,
end_len * SG_FEET_TO_METER,
0.0 ),
Point3D( end_wid * SG_FEET_TO_METER,
start_len * SG_FEET_TO_METER,
0.0 ),
heading );
tp = FGTexParams( p0,
sect_wid * SG_FEET_TO_METER,
sect_len * SG_FEET_TO_METER,
heading );
texparams->push_back( tp );
// print runway points

View file

@ -28,6 +28,7 @@
#include "poly_extra.hxx"
#include "rwy_common.hxx"
#include "texparams.hxx"
#include "taxiway.hxx"
@ -73,37 +74,33 @@ void gen_taxiway( const FGRunway& rwy_info, const string& material,
FGSuperPoly sp;
FGTexParams tp;
double xfactor = 1.0;
double yfactor = 1.0;
if ( fabs(rwy_info.width) > SG_EPSILON ) {
xfactor = 150.0 / rwy_info.width;
SG_LOG(SG_GENERAL, SG_DEBUG, "xfactor = " << xfactor);
}
if ( fabs(rwy_info.length) > SG_EPSILON ) {
yfactor = 150.0 / rwy_info.length;
SG_LOG(SG_GENERAL, SG_DEBUG, "yfactor = " << yfactor);
}
SG_LOG(SG_GENERAL, SG_DEBUG, "len = " << rwy_info.length);
SG_LOG(SG_GENERAL, SG_DEBUG, "width = " << rwy_info.width);
double twid;
if ( rwy_info.width <= 150 ) {
// narrower taxiways are more likely directional
twid = rwy_info.width;
} else {
// wider taxiways are more likely large / non-directional
// concrete areas
twid = 250.0;
}
FGPolygon clipped_a = polygon_diff( runway_a, *accum );
FGPolygon split_a = split_long_edges( clipped_a, 400.0 );
sp.erase();
sp.set_poly( split_a );
sp.set_material( material );
sp.set_flag( 1 ); // mark as a taxiway
rwy_polys->push_back( sp );
SG_LOG(SG_GENERAL, SG_DEBUG, "clipped_a = " << clipped_a.contours());
*accum = polygon_union( runway_a, *accum );
tp = FGTexParams( Point3D( rwy_info.lon, rwy_info.lat, 0 ),
Point3D( (-250 / 2.0) * SG_FEET_TO_METER,
0.0,
0 ),
Point3D( (250 / 2.0) * SG_FEET_TO_METER,
(250 / 2.0) * SG_FEET_TO_METER,
0.0 ),
rwy_info.heading );
tp = FGTexParams( runway_a.get_pt(0,0),
twid * SG_FEET_TO_METER,
250 * SG_FEET_TO_METER,
rwy_info.heading );
texparams->push_back( tp );
FGPolygon clipped_b = polygon_diff( runway_b, *accum );
@ -114,14 +111,10 @@ void gen_taxiway( const FGRunway& rwy_info, const string& material,
rwy_polys->push_back( sp );
SG_LOG(SG_GENERAL, SG_DEBUG, "clipped_b = " << clipped_b.contours());
*accum = polygon_union( runway_b, *accum );
tp = FGTexParams( Point3D( rwy_info.lon, rwy_info.lat, 0 ),
Point3D( (-250 / 2.0) * SG_FEET_TO_METER,
0.0,
0 ),
Point3D( (250 / 2.0) * SG_FEET_TO_METER,
(250 / 2.0) * SG_FEET_TO_METER,
0.0 ),
rwy_info.heading + 180.0 );
tp = FGTexParams( runway_b.get_pt(0,0),
twid * SG_FEET_TO_METER,
250 * SG_FEET_TO_METER,
rwy_info.heading + 180.0 );
texparams->push_back( tp );
#if 0

View file

@ -43,35 +43,35 @@ class FGTexParams {
private:
Point3D center;
Point3D min;
Point3D max;
double angle;
Point3D ref;
double width;
double length;
double heading;
public:
// Constructor and destructor
inline FGTexParams( void ) { }
inline FGTexParams( const Point3D &c, const Point3D &mn, const Point3D &mx,
const double a ) {
center = c;
min = mn;
max = mx;
angle = a;
inline FGTexParams( const Point3D &r, const double w, const double l,
const double h ) {
ref = r;
width = w;
length = l;
heading = h;
}
inline ~FGTexParams( void ) { }
inline Point3D get_center() const { return center; }
inline void set_center( const Point3D &p ) { center = p; }
inline Point3D get_ref() const { return ref; }
inline void set_ref( const Point3D &r ) { ref = r; }
inline Point3D get_min() const { return min; }
inline void set_min( const Point3D &p ) { min = p; }
inline double get_width() const { return width; }
inline void set_width( const double w ) { width = w; }
inline Point3D get_max() const { return max; }
inline void set_max( const Point3D &p ) { max = p; }
inline double get_length() const { return length; }
inline void set_length( const double l ) { length = l; }
inline double get_angle() const { return angle; }
inline void set_angle( const double a ) { angle = a; }
inline double get_heading() const { return heading; }
inline void set_heading( const double h ) { heading = h; }
};