1
0
Fork 0

Fix a terrain intersection calculating bug. The code wasn't quite handling

traingle strips right ... it was mixing up the vertex ordering slightly.
Oh what the heck, it was really screwing up tristrips.  Everything else looks
correct though. :-)  Hurray for the red book.
This commit is contained in:
curt 2003-11-21 03:13:52 +00:00
parent c05a2c2bcc
commit 0f1c24bbed

View file

@ -243,7 +243,11 @@ int FGHitList::IntersectLeaf( ssgLeaf *leaf, sgdMat4 m,
switch ( primType ) switch ( primType )
{ {
case GL_POLYGON : case GL_POLYGON :
SG_LOG( SG_TERRAIN, SG_ALERT,
"WARNING: dubiously handled GL_POLYGON" );
case GL_TRIANGLE_FAN : case GL_TRIANGLE_FAN :
/* SG_LOG( SG_TERRAIN, SG_ALERT,
"IntersectLeaf: GL_TRIANGLE_FAN" ); */
if ( !n ) { if ( !n ) {
sgdSetVec3( tri[0], leaf->getVertex( short(0) ) ); sgdSetVec3( tri[0], leaf->getVertex( short(0) ) );
sgdSetVec3( tri[1], leaf->getVertex( short(1) ) ); sgdSetVec3( tri[1], leaf->getVertex( short(1) ) );
@ -254,35 +258,42 @@ int FGHitList::IntersectLeaf( ssgLeaf *leaf, sgdMat4 m,
} }
break; break;
case GL_TRIANGLES : case GL_TRIANGLES :
/* SG_LOG( SG_TERRAIN, SG_DEBUG,
"IntersectLeaf: GL_TRIANGLES" ); */
sgdSetVec3( tri[0], leaf->getVertex( short(n*3) ) ); sgdSetVec3( tri[0], leaf->getVertex( short(n*3) ) );
sgdSetVec3( tri[1], leaf->getVertex( short(n*3+1) ) ); sgdSetVec3( tri[1], leaf->getVertex( short(n*3+1) ) );
sgdSetVec3( tri[2], leaf->getVertex( short(n*3+2) ) ); sgdSetVec3( tri[2], leaf->getVertex( short(n*3+2) ) );
break; break;
case GL_TRIANGLE_STRIP :
case GL_QUAD_STRIP : case GL_QUAD_STRIP :
SG_LOG( SG_TERRAIN, SG_ALERT,
"WARNING: dubiously handled GL_QUAD_STRIP" );
case GL_TRIANGLE_STRIP :
/* SG_LOG( SG_TERRAIN, SG_ALERT,
"IntersectLeaf: GL_TRIANGLE_STRIP" ); */
if ( !n ) { if ( !n ) {
sgdSetVec3( tri[0], leaf->getVertex( short(0) ) ); sgdSetVec3( tri[0], leaf->getVertex( short(0) ) );
sgdSetVec3( tri[1], leaf->getVertex( short(1) ) ); sgdSetVec3( tri[1], leaf->getVertex( short(1) ) );
sgdSetVec3( tri[2], leaf->getVertex( short(2) ) ); sgdSetVec3( tri[2], leaf->getVertex( short(2) ) );
} else { } else {
if ( n & 1 ) { if ( n & 1 ) {
sgdSetVec3( tri[0], leaf->getVertex( short(n+2) ) ); sgdCopyVec3( tri[0], tri[2] );
sgdCopyVec3( tri[1], tri[2] ); sgdSetVec3( tri[2], leaf->getVertex( short(n+2) ) );
sgdCopyVec3( tri[2], tri[1] );
} else { } else {
sgdCopyVec3( tri[0], tri[1] ); sgdCopyVec3( tri[2], tri[1] );
sgdCopyVec3( tri[1], tri[2] );
sgdSetVec3( tri[2], leaf->getVertex( short(n+2) ) ); sgdSetVec3( tri[2], leaf->getVertex( short(n+2) ) );
} }
} }
break; break;
case GL_QUADS : case GL_QUADS :
SG_LOG( SG_TERRAIN, SG_ALERT,
"WARNING: dubiously handled GL_QUADS" );
sgdSetVec3( tri[0], leaf->getVertex( short(n*2) ) ); sgdSetVec3( tri[0], leaf->getVertex( short(n*2) ) );
sgdSetVec3( tri[1], leaf->getVertex( short(n*2+1) ) ); sgdSetVec3( tri[1], leaf->getVertex( short(n*2+1) ) );
sgdSetVec3( tri[2], leaf->getVertex( short(n*2 + 2 - (n&1)*4) ) ); sgdSetVec3( tri[2], leaf->getVertex( short(n*2 + 2 - (n&1)*4) ) );
break; break;
default: default:
SG_LOG( SG_TERRAIN, SG_ALERT,
"WARNING: not-handled structure: " << primType );
return IntersectLeaf( leaf, m, orig, dir); return IntersectLeaf( leaf, m, orig, dir);
} }
@ -519,14 +530,15 @@ bool fgCurrentElev( sgdVec3 abs_view_pos, sgdVec3 scenery_center,
double result = -9999; double result = -9999;
Point3D sc(scenery_center[0], scenery_center[1], scenery_center[2]) ; Point3D sc(scenery_center[0], scenery_center[1], scenery_center[2]) ;
// cout << "hits = ";
int hitcount = hit_list->num_hits(); int hitcount = hit_list->num_hits();
// cout << "hits = " << hitcount << endl;
for ( int i = 0; i < hitcount; ++i ) { for ( int i = 0; i < hitcount; ++i ) {
geoc = sgCartToPolar3d( sc + hit_list->get_point(i) ); geoc = sgCartToPolar3d( sc + hit_list->get_point(i) );
double lat_geod, alt, sea_level_r; double lat_geod, alt, sea_level_r;
sgGeocToGeod(geoc.lat(), geoc.radius(), &lat_geod, sgGeocToGeod(geoc.lat(), geoc.radius(), &lat_geod,
&alt, &sea_level_r); &alt, &sea_level_r);
// cout << alt << " "; // cout << "hit " << i << " lon = " << geoc.lon() << " lat = "
// << lat_geod << " alt = " << alt << endl;
if ( alt > result && alt < 10000 ) { if ( alt > result && alt < 10000 ) {
result = alt; result = alt;
this_hit = i; this_hit = i;