Math/bucket/tiling updates contributed by Norman Vine.

Texture coordinate calculation updates by Curt.
This commit is contained in:
curt
2000-06-16 00:28:19 +00:00
parent b72d36d96f
commit 2ed07850c6
5 changed files with 70 additions and 28 deletions
+10 -12
View File
@@ -73,7 +73,7 @@ private:
int y; // y subdivision (0 to 7) int y; // y subdivision (0 to 7)
public: public:
// default constructor // default constructor
FGBucket(); FGBucket();
@@ -90,6 +90,10 @@ public:
// Set the bucket params for the specified lat and lon // Set the bucket params for the specified lat and lon
void set_bucket( double dlon, double dlat ); void set_bucket( double dlon, double dlat );
void set_bucket( double *lonlat ) {
set_bucket( lonlat[0], lonlat[1] );
}
void make_bad ( void ); void make_bad ( void );
// Generate the unique scenery tile index for this bucket // Generate the unique scenery tile index for this bucket
@@ -227,7 +231,7 @@ inline FGBucket::FGBucket(const bool is_good) {
lon = -1000; lon = -1000;
} }
} }
// Parse a unique scenery tile index and find the lon, lat, x, and y // Parse a unique scenery tile index and find the lon, lat, x, and y
inline FGBucket::FGBucket(const long int bindex) { inline FGBucket::FGBucket(const long int bindex) {
@@ -236,11 +240,11 @@ inline FGBucket::FGBucket(const long int bindex) {
lon = index >> 14; lon = index >> 14;
index -= lon << 14; index -= lon << 14;
lon -= 180; lon -= 180;
lat = index >> 6; lat = index >> 6;
index -= lat << 6; index -= lat << 6;
lat -= 90; lat -= 90;
y = index >> 3; y = index >> 3;
index -= y << 3; index -= y << 3;
@@ -310,9 +314,9 @@ inline double FGBucket::get_height() const {
// create an impossible bucket // create an impossible bucket
inline void FGBucket::make_bad( void ) { inline void FGBucket::make_bad( void ) {
set_bucket(0.0, 0.0); set_bucket(0.0, 0.0);
lon = -1000; lon = -1000;
} }
// offset a bucket struct by the specified tile units in the X & Y // offset a bucket struct by the specified tile units in the X & Y
// direction // 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 ); 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& inline ostream&
operator<< ( ostream& out, const FGBucket& b ) operator<< ( ostream& out, const FGBucket& b )
{ {
+16 -6
View File
@@ -35,18 +35,13 @@ double sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0,
const sgVec3 d ) { const sgVec3 d ) {
sgVec3 u, u1, v; sgVec3 u, u1, v;
double ud, dd, tmp;
// u = p - p0 // u = p - p0
sgSubVec3(u, p, p0); sgSubVec3(u, p, p0);
// calculate the projection, u1, of u along d. // calculate the projection, u1, of u along d.
// u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d; // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
ud = sgScalarProductVec3(u, d); sgScaleVec3( u1, d, sgScalarProductVec3(u,d) / sgScalarProductVec3(d,d) );
dd = sgScalarProductVec3(d, d);
tmp = ud / dd;
sgScaleVec3(u1, d, tmp);;
// v = u - u1 = vector from closest point on line, p1, to the // v = u - u1 = vector from closest point on line, p1, to the
// original point, p. // original point, p.
@@ -81,3 +76,18 @@ double sgdPointLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
return ( sgdScalarProductVec3(v, v) ); 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]);
}
}
}
+12
View File
@@ -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, // Given a point p, and a line through p0 with direction vector d,
// find the shortest distance (squared) from the point to the line // find the shortest distance (squared) from the point to the line
double sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0, 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, double sgdPointLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
const sgdVec3 d ); 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 #endif // _VECTOR_HXX
+32 -8
View File
@@ -113,17 +113,40 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes,
// cout << "dx = " << dx << " dy = " << dy << endl; // cout << "dx = " << dx << " dy = " << dy << endl;
bool do_shift = false; bool do_shift = false;
Point3D mod_shift; // Point3D mod_shift;
if ( (dx > HALF_MAX_TEX_COORD) || (dy > HALF_MAX_TEX_COORD) ) { if ( (dx > HALF_MAX_TEX_COORD) || (dy > HALF_MAX_TEX_COORD) ) {
// structure is too big, we'll just have to shift it so that // structure is too big, we'll just have to shift it so that
// tmin = (0,0). This messes up subsequent texture scaling, // tmin = (0,0). This messes up subsequent texture scaling,
// but is the best we can do. // but is the best we can do.
// cout << "SHIFTING" << endl; // cout << "SHIFTING" << endl;
do_shift = true; do_shift = true;
tmin.setx( (double)( (int)tmin.x() + 1 ) ); if ( tmin.x() < 0 ) {
tmin.sety( (double)( (int)tmin.y() + 1 ) ); 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; // cout << "found tmin = " << tmin << endl;
} else { } 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 // structure is small enough ... we can mod it so we can
// properly scale the texture coordinates later. // properly scale the texture coordinates later.
// cout << "MODDING" << endl; // 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 // At this point we know that the object is < 16 wide in
// texture coordinate space. If the modulo of the tmin is > // texture coordinate space. If the modulo of the tmin is >
// the mod of the tmax at this point, then we know that the // 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. // everything down by 16 and get it within the 0-32 range.
if ( x1 > x2 ) { if ( x1 > x2 ) {
@@ -156,7 +179,7 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes,
} else { } else {
mod_shift.sety( 0.0 ); mod_shift.sety( 0.0 );
} }
#endif
// cout << "mod_shift = " << mod_shift << endl; // 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 ); t = basic_tex_coord( p, degree_width, degree_height, scale );
// cout << "second t = " << t << endl; // cout << "second t = " << t << endl;
if ( do_shift ) { // if ( do_shift ) {
adjusted_t = t - tmin; adjusted_t = t - tmin;
#if 0
} else { } else {
adjusted_t.setx( fmod(t.x() + mod_shift.x(), MAX_TEX_COORD) ); adjusted_t.setx( fmod(t.x() + mod_shift.x(), MAX_TEX_COORD) );
while ( adjusted_t.x() < 0 ) { 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; // cout << "adjusted_t " << adjusted_t << endl;
} }
#endif
if ( adjusted_t.x() < FG_EPSILON ) { if ( adjusted_t.x() < FG_EPSILON ) {
adjusted_t.setx( 0.0 ); adjusted_t.setx( 0.0 );
} }
-2
View File
@@ -41,5 +41,3 @@ point_list calc_tex_coords( const FGBucket& b, const point_list& geod_nodes,
#endif // _TEXCOORD_HXX #endif // _TEXCOORD_HXX