From 2ed07850c616705695f2add269d187f981f8d09d Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 16 Jun 2000 00:28:19 +0000 Subject: [PATCH] Math/bucket/tiling updates contributed by Norman Vine. Texture coordinate calculation updates by Curt. --- simgear/bucket/newbucket.hxx | 22 +++++++++----------- simgear/math/vector.cxx | 22 ++++++++++++++------ simgear/math/vector.hxx | 12 +++++++++++ simgear/misc/texcoord.cxx | 40 ++++++++++++++++++++++++++++-------- simgear/misc/texcoord.hxx | 2 -- 5 files changed, 70 insertions(+), 28 deletions(-) diff --git a/simgear/bucket/newbucket.hxx b/simgear/bucket/newbucket.hxx index 64677680..9aff115b 100644 --- a/simgear/bucket/newbucket.hxx +++ b/simgear/bucket/newbucket.hxx @@ -73,7 +73,7 @@ private: int y; // y subdivision (0 to 7) public: - + // default constructor FGBucket(); @@ -90,6 +90,10 @@ public: // Set the bucket params for the specified lat and lon void set_bucket( double dlon, double dlat ); + void set_bucket( double *lonlat ) { + set_bucket( lonlat[0], lonlat[1] ); + } + void make_bad ( void ); // Generate the unique scenery tile index for this bucket @@ -227,7 +231,7 @@ inline FGBucket::FGBucket(const bool is_good) { lon = -1000; } } - + // Parse a unique scenery tile index and find the lon, lat, x, and y inline FGBucket::FGBucket(const long int bindex) { @@ -236,11 +240,11 @@ inline FGBucket::FGBucket(const long int bindex) { lon = index >> 14; index -= lon << 14; lon -= 180; - + lat = index >> 6; index -= lat << 6; lat -= 90; - + y = index >> 3; index -= y << 3; @@ -310,9 +314,9 @@ inline double FGBucket::get_height() const { // create an impossible bucket inline void FGBucket::make_bad( void ) { set_bucket(0.0, 0.0); - lon = -1000; + lon = -1000; } - + // offset a bucket struct by the specified tile units in the X & Y // direction @@ -323,12 +327,6 @@ FGBucket fgBucketOffset( double dlon, double dlat, int x, int y ); void fgBucketDiff( const FGBucket& b1, const FGBucket& b2, int *dx, int *dy ); -/* -// Given a lat/lon, fill in the local tile index array -void fgBucketGenIdxArray(fgBUCKET *p1, fgBUCKET *tiles, int width, int height); -*/ - - inline ostream& operator<< ( ostream& out, const FGBucket& b ) { diff --git a/simgear/math/vector.cxx b/simgear/math/vector.cxx index 75a0cb7a..7c6f2c3c 100644 --- a/simgear/math/vector.cxx +++ b/simgear/math/vector.cxx @@ -35,18 +35,13 @@ double sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0, const sgVec3 d ) { sgVec3 u, u1, v; - double ud, dd, tmp; // u = p - p0 sgSubVec3(u, p, p0); // calculate the projection, u1, of u along d. // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d; - ud = sgScalarProductVec3(u, d); - dd = sgScalarProductVec3(d, d); - tmp = ud / dd; - - sgScaleVec3(u1, d, tmp);; + sgScaleVec3( u1, d, sgScalarProductVec3(u,d) / sgScalarProductVec3(d,d) ); // v = u - u1 = vector from closest point on line, p1, to the // original point, p. @@ -81,3 +76,18 @@ double sgdPointLineDistSquared( const sgdVec3 p, const sgdVec3 p0, return ( sgdScalarProductVec3(v, v) ); } + + +// This is a quicker form of +// sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans ) +// sgPostMultMat4( sgMat, sgTRANS ); +void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans ) +{ + for( int i=0; i<4; i++) { + for( int j=0; j<3; j++ ) { + src[i][j] += (src[i][3] * trans[j]); + } + } +} + + diff --git a/simgear/math/vector.hxx b/simgear/math/vector.hxx index f27f8b60..2d3feedc 100644 --- a/simgear/math/vector.hxx +++ b/simgear/math/vector.hxx @@ -83,6 +83,14 @@ inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal, } +inline void sgCopyNegateVec4( sgVec4 dst, sgVec4 src ) +{ + dst [ 0 ] = -src [ 0 ] ; + dst [ 1 ] = -src [ 1 ] ; + dst [ 2 ] = -src [ 2 ] ; + dst [ 3 ] = -src [ 3 ] ; +} + // Given a point p, and a line through p0 with direction vector d, // find the shortest distance (squared) from the point to the line double sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0, @@ -93,6 +101,10 @@ double sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0, double sgdPointLineDistSquared( const sgdVec3 p, const sgdVec3 p0, const sgdVec3 d ); +// This is same as +// sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans ) +// sgPostMultMat4( sgMat, sgTRANS ); +void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans ); #endif // _VECTOR_HXX diff --git a/simgear/misc/texcoord.cxx b/simgear/misc/texcoord.cxx index 789fd9d9..983fd30c 100644 --- a/simgear/misc/texcoord.cxx +++ b/simgear/misc/texcoord.cxx @@ -113,17 +113,40 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes, // cout << "dx = " << dx << " dy = " << dy << endl; bool do_shift = false; - Point3D mod_shift; + // Point3D mod_shift; if ( (dx > HALF_MAX_TEX_COORD) || (dy > HALF_MAX_TEX_COORD) ) { // structure is too big, we'll just have to shift it so that // tmin = (0,0). This messes up subsequent texture scaling, // but is the best we can do. // cout << "SHIFTING" << endl; do_shift = true; - tmin.setx( (double)( (int)tmin.x() + 1 ) ); - tmin.sety( (double)( (int)tmin.y() + 1 ) ); + if ( tmin.x() < 0 ) { + tmin.setx( (double)( (int)tmin.x() - 1 ) ); + } else { + tmin.setx( (int)tmin.x() ); + } + if ( tmin.y() < 0 ) { + tmin.sety( (double)( (int)tmin.y() - 1 ) ); + } else { + tmin.sety( (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 ); + } else { + tmin.setx( ( (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 ); + } else { + tmin.sety( ( (int)(tmin.y() / HALF_MAX_TEX_COORD) ) + * HALF_MAX_TEX_COORD ); + } +#if 0 // structure is small enough ... we can mod it so we can // properly scale the texture coordinates later. // cout << "MODDING" << endl; @@ -142,7 +165,7 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes, // At this point we know that the object is < 16 wide in // texture coordinate space. If the modulo of the tmin is > // the mod of the tmax at this point, then we know that the - // starting tex coordinate for the tmin > 16 so we can shift + // starting tex coordinate for the tmax > 16 so we can shift // everything down by 16 and get it within the 0-32 range. if ( x1 > x2 ) { @@ -156,7 +179,7 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes, } else { mod_shift.sety( 0.0 ); } - +#endif // cout << "mod_shift = " << mod_shift << endl; } @@ -169,8 +192,9 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes, t = basic_tex_coord( p, degree_width, degree_height, scale ); // cout << "second t = " << t << endl; - if ( do_shift ) { - adjusted_t = t - tmin; + // if ( do_shift ) { + adjusted_t = t - tmin; +#if 0 } else { adjusted_t.setx( fmod(t.x() + mod_shift.x(), MAX_TEX_COORD) ); while ( adjusted_t.x() < 0 ) { @@ -182,7 +206,7 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes, } // cout << "adjusted_t " << adjusted_t << endl; } - +#endif if ( adjusted_t.x() < FG_EPSILON ) { adjusted_t.setx( 0.0 ); } diff --git a/simgear/misc/texcoord.hxx b/simgear/misc/texcoord.hxx index 36c7c803..50d9945a 100644 --- a/simgear/misc/texcoord.hxx +++ b/simgear/misc/texcoord.hxx @@ -41,5 +41,3 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes, #endif // _TEXCOORD_HXX - - -- 2.39.5