X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=simgear%2Fmisc%2Ftexcoord.cxx;h=4a19fb44740dbe5674019ee80156c657bfc8f428;hb=2a2e2716bdfbecb3494ab935171ed6224a178470;hp=3c9f762e89905bf264cad879d495a695126b7d6f;hpb=c0a633ea1d9240b467640975167fbcbee576b32b;p=simgear.git diff --git a/simgear/misc/texcoord.cxx b/simgear/misc/texcoord.cxx index 3c9f762e..4a19fb44 100644 --- a/simgear/misc/texcoord.cxx +++ b/simgear/misc/texcoord.cxx @@ -2,7 +2,7 @@ // // Written by Curtis Olson, started March 1999. // -// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org +// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -14,10 +14,9 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. +// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ @@ -140,14 +139,18 @@ enter this in the official comments in case I forget again. :-) */ +#ifdef HAVE_CONFIG_H +# include +#endif + #include -// #include STL_IOSTREAM +// #include #include "texcoord.hxx" -// SG_USING_STD(cout); -// SG_USING_STD(endl); +// using std::cout; +// using std::endl; #define FG_STANDARD_TEXTURE_DIMENSION 1000.0 // meters @@ -156,22 +159,28 @@ enter this in the official comments in case I forget again. :-) // return the basic unshifted/unmoded texture coordinate for a lat/lon -static inline Point3D basic_tex_coord( const Point3D& p, +static inline SGVec2f basic_tex_coord( const SGGeod& p, double degree_width, double degree_height, double scale ) { - return Point3D( p.x() * ( degree_width * scale / + return SGVec2f( p.getLongitudeDeg() * ( degree_width * scale / FG_STANDARD_TEXTURE_DIMENSION ), - p.y() * ( degree_height * scale / - FG_STANDARD_TEXTURE_DIMENSION ), - 0.0 ); + p.getLatitudeDeg() * ( degree_height * scale / + FG_STANDARD_TEXTURE_DIMENSION ) + ); } // traverse the specified fan/strip/list of vertices and attempt to // calculate "none stretching" texture coordinates -point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, +std::vector sgCalcTexCoords( const SGBucket& b, const std::vector& geod_nodes, + const int_list& fan, double scale ) +{ + return sgCalcTexCoords(b.get_center_lat(), geod_nodes, fan, scale); +} + +std::vector sgCalcTexCoords( double centerLat, const std::vector& geod_nodes, const int_list& fan, double scale ) { // cout << "calculating texture coordinates for a specific fan of size = " @@ -179,7 +188,7 @@ point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, // calculate perimeter based on center of this degree (not center // of bucket) - double clat = (int)b.get_center_lat(); + double clat = (int)centerLat; if ( clat > 0 ) { clat = (int)clat + 0.5; } else { @@ -189,7 +198,7 @@ point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, double clat_rad = clat * SGD_DEGREES_TO_RADIANS; double cos_lat = cos( clat_rad ); double local_radius = cos_lat * SG_EQUATORIAL_RADIUS_M; - double local_perimeter = 2.0 * local_radius * SGD_PI; + double local_perimeter = local_radius * SGD_2PI; double degree_width = local_perimeter / 360.0; // cout << "clat = " << clat << endl; @@ -199,21 +208,21 @@ point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, // cout << "local_perimeter = " << local_perimeter << endl; // cout << "degree_width = " << degree_width << endl; - double perimeter = 2.0 * SG_EQUATORIAL_RADIUS_M * SGD_PI; + double perimeter = SG_EQUATORIAL_RADIUS_M * SGD_2PI; double degree_height = perimeter / 360.0; // cout << "degree_height = " << degree_height << endl; // find min/max of fan - Point3D tmin, tmax, p, t; + SGVec2f tmin, tmax; bool first = true; int i; for ( i = 0; i < (int)fan.size(); ++i ) { - p = geod_nodes[ fan[i] ]; + SGGeod p = geod_nodes[ fan[i] ]; // cout << "point p = " << p << endl; - t = basic_tex_coord( p, degree_width, degree_height, scale ); + SGVec2f t = basic_tex_coord( p, degree_width, degree_height, scale ); // cout << "basic_tex_coord = " << t << endl; if ( first ) { @@ -221,16 +230,16 @@ point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, first = false; } else { if ( t.x() < tmin.x() ) { - tmin.setx( t.x() ); + tmin.x() = t.x(); } if ( t.y() < tmin.y() ) { - tmin.sety( t.y() ); + tmin.y() = t.y(); } if ( t.x() > tmax.x() ) { - tmax.setx( t.x() ); + tmax.x() = t.x(); } if ( t.y() > tmax.y() ) { - tmax.sety( t.y() ); + tmax.y() = t.y(); } } } @@ -246,30 +255,31 @@ point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, // but is the best we can do. // cout << "SHIFTING" << endl; if ( tmin.x() < 0 ) { - tmin.setx( (double)( (int)tmin.x() - 1 ) ); + tmin.x() = (double)( (int)tmin.x() - 1 ) ; } else { - tmin.setx( (int)tmin.x() ); + tmin.x() = (int)tmin.x(); } + if ( tmin.y() < 0 ) { - tmin.sety( (double)( (int)tmin.y() - 1 ) ); + tmin.y() = (double)( (int)tmin.y() - 1 ); } else { - tmin.sety( (int)tmin.y() ); + tmin.y() = (int)tmin.y(); } // cout << "found tmin = " << tmin << endl; } else { if ( tmin.x() < 0 ) { - tmin.setx( ( (int)(tmin.x() / HALF_MAX_TEX_COORD) - 1 ) - * HALF_MAX_TEX_COORD ); + tmin.x() = ( (int)(tmin.x() / HALF_MAX_TEX_COORD) - 1 ) + * HALF_MAX_TEX_COORD ; } else { - tmin.setx( ( (int)(tmin.x() / HALF_MAX_TEX_COORD) ) - * HALF_MAX_TEX_COORD ); + tmin.x() = ( (int)(tmin.x() / HALF_MAX_TEX_COORD) ) + * HALF_MAX_TEX_COORD ; } if ( tmin.y() < 0 ) { - tmin.sety( ( (int)(tmin.y() / HALF_MAX_TEX_COORD) - 1 ) - * HALF_MAX_TEX_COORD ); + tmin.y() = ( (int)(tmin.y() / HALF_MAX_TEX_COORD) - 1 ) + * HALF_MAX_TEX_COORD ; } else { - tmin.sety( ( (int)(tmin.y() / HALF_MAX_TEX_COORD) ) - * HALF_MAX_TEX_COORD ); + tmin.y() = ( (int)(tmin.y() / HALF_MAX_TEX_COORD) ) + * HALF_MAX_TEX_COORD ; } #if 0 // structure is small enough ... we can mod it so we can @@ -309,12 +319,12 @@ point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, } // generate tex_list - Point3D adjusted_t; - point_list tex; + SGVec2f adjusted_t; + std::vector tex; tex.clear(); for ( i = 0; i < (int)fan.size(); ++i ) { - p = geod_nodes[ fan[i] ]; - t = basic_tex_coord( p, degree_width, degree_height, scale ); + SGGeod p = geod_nodes[ fan[i] ]; + SGVec2f t = basic_tex_coord( p, degree_width, degree_height, scale ); // cout << "second t = " << t << endl; adjusted_t = t - tmin; @@ -332,12 +342,12 @@ point_list sgCalcTexCoords( const SGBucket& b, const point_list& geod_nodes, } #endif if ( adjusted_t.x() < SG_EPSILON ) { - adjusted_t.setx( 0.0 ); + adjusted_t.x() = 0.0; } if ( adjusted_t.y() < SG_EPSILON ) { - adjusted_t.sety( 0.0 ); + adjusted_t.y() = 0.0; } - adjusted_t.setz( 0.0 ); + // cout << "adjusted_t = " << adjusted_t << endl; tex.push_back( adjusted_t );