Texture coordinate calculation updates by Curt.
int y; // y subdivision (0 to 7)
public:
-
+
// default constructor
FGBucket();
// 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
lon = -1000;
}
}
-
+
// Parse a unique scenery tile index and find the lon, lat, x, and y
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;
// 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
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 )
{
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.
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]);
+ }
+ }
+}
+
+
}
+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,
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
// 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;
// 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 ) {
} else {
mod_shift.sety( 0.0 );
}
-
+#endif
// cout << "mod_shift = " << mod_shift << endl;
}
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 ) {
}
// cout << "adjusted_t " << adjusted_t << endl;
}
-
+#endif
if ( adjusted_t.x() < FG_EPSILON ) {
adjusted_t.setx( 0.0 );
}
#endif // _TEXCOORD_HXX
-
-