1
0
Fork 0

Remove cached intersection code so that we can support intersecting with

dynamic objects.
This commit is contained in:
curt 2001-07-31 19:54:29 +00:00
parent 57b4283383
commit 17c781a870
2 changed files with 42 additions and 36 deletions

View file

@ -222,7 +222,7 @@ void FGHitList::IntersectBranch( ssgBranch *branch, sgdMat4 m,
kid = branch->getNextKid() ) kid = branch->getNextKid() )
{ {
if ( kid->getTraversalMask() & SSGTRAV_HOT ) { if ( kid->getTraversalMask() & SSGTRAV_HOT ) {
bsphere = kid->getBSphere(); bsphere = kid->getBSphere();
sgVec3 fcenter; sgVec3 fcenter;
sgCopyVec3( fcenter, bsphere->getCenter() ); sgCopyVec3( fcenter, bsphere->getCenter() );
sgdVec3 center; sgdVec3 center;
@ -230,20 +230,20 @@ void FGHitList::IntersectBranch( ssgBranch *branch, sgdMat4 m,
center[1] = fcenter[1]; center[1] = fcenter[1];
center[2] = fcenter[2]; center[2] = fcenter[2];
sgdXformPnt3( center, m ) ; sgdXformPnt3( center, m ) ;
double radius_sqd = bsphere->getRadius() * bsphere->getRadius(); // watch out for overflow
if ( sgdClosestPointToLineDistSquared( center, orig, dir ) < if ( sgdClosestPointToLineDistSquared( center, orig, dir ) <
radius_sqd ) double(bsphere->getRadius() * bsphere->getRadius()) )
{ {
// possible intersections // possible intersections
if ( kid->isAKindOf ( ssgTypeBranch() ) ) { if ( kid->isAKindOf ( ssgTypeBranch() ) ) {
sgdMat4 m_new; sgdMat4 m_new;
sgdCopyMat4(m_new, m); sgdCopyMat4(m_new, m);
if ( kid->isA( ssgTypeTransform() ) ) { if ( kid->isA( ssgTypeTransform() ) ) {
sgMat4 fxform; sgMat4 fxform;
((ssgTransform *)kid)->getTransform( fxform ); ((ssgTransform *)kid)->getTransform( fxform );
sgdMat4 xform; sgdMat4 xform;
sgdSetMat4( xform, fxform ); sgdSetMat4( xform, fxform );
sgdPreMultMat4( m_new, xform ); sgdPreMultMat4( m_new, xform );
} }
IntersectBranch( (ssgBranch *)kid, m_new, orig, dir ); IntersectBranch( (ssgBranch *)kid, m_new, orig, dir );
} else if ( kid->isAKindOf ( ssgTypeLeaf() ) ) { } else if ( kid->isAKindOf ( ssgTypeLeaf() ) ) {
@ -307,8 +307,8 @@ void FGHitList::IntersectCachedLeaf( sgdMat4 m,
sgdXformPnt3( center, m ); sgdXformPnt3( center, m );
if ( sgdClosestPointToLineDistSquared( center, orig, dir ) < if ( sgdClosestPointToLineDistSquared( center, orig, dir ) <
radius*radius ) double(radius*radius) )
{ {
IntersectLeaf( (ssgLeaf *)last_hit(), m, orig, dir ); IntersectLeaf( (ssgLeaf *)last_hit(), m, orig, dir );
} }
} }
@ -357,34 +357,34 @@ bool fgCurrentElev( sgdVec3 abs_view_pos, sgdVec3 scenery_center,
int hitcount = hit_list->num_hits(); int hitcount = hit_list->num_hits();
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);
if ( alt > result && alt < 10000 ) { if ( alt > result && alt < 10000 ) {
result = alt; result = alt;
this_hit = i; this_hit = i;
} }
} }
if ( result > -9000 ) { if ( result > -9000 ) {
*terrain_elev = result; *terrain_elev = result;
*radius = geoc.radius(); *radius = geoc.radius();
sgVec3 tmp; sgVec3 tmp;
sgSetVec3(tmp, hit_list->get_normal(this_hit)); sgSetVec3(tmp, hit_list->get_normal(this_hit));
// cout << "cur_normal: " << tmp[0] << " " << tmp[1] << " " // cout << "cur_normal: " << tmp[0] << " " << tmp[1] << " "
// << tmp[2] << endl; // << tmp[2] << endl;
/* ssgState *IntersectedLeafState = /* ssgState *IntersectedLeafState =
((ssgLeaf*)hit_list->get_entity(this_hit))->getState(); */ ((ssgLeaf*)hit_list->get_entity(this_hit))->getState(); */
CurrentNormalInLocalPlane(tmp, tmp); CurrentNormalInLocalPlane(tmp, tmp);
sgdSetVec3( normal, tmp ); sgdSetVec3( normal, tmp );
// cout << "NED: " << tmp[0] << " " << tmp[1] << " " << tmp[2] << endl; // cout << "NED: " << tmp[0] << " " << tmp[1] << " " << tmp[2] << endl;
return true; return true;
} else { } else {
SG_LOG( SG_TERRAIN, SG_INFO, "no terrain intersection" ); SG_LOG( SG_TERRAIN, SG_INFO, "no terrain intersection" );
*terrain_elev = 0.0; *terrain_elev = 0.0;
float *up = globals->get_current_view()->get_world_up(); float *up = globals->get_current_view()->get_world_up();
sgdSetVec3(normal, up[0], up[1], up[2]); sgdSetVec3(normal, up[0], up[1], up[2]);
return false; return false;
} }
} }

View file

@ -80,17 +80,23 @@ inline void FGHitList::Intersect( ssgBranch *scene,
{ {
sgdMat4 m; sgdMat4 m;
#ifdef USE_CACHED_HIT
// This optimization gives a slight speedup
// but it precludes using the hitlist for dynamic
// objects NHV
init(); init();
if( last_hit() ) { if( last_hit() ) {
sgdMakeIdentMat4 ( m ) ; sgdMakeIdentMat4 ( m ) ;
IntersectCachedLeaf(m, orig, dir); IntersectCachedLeaf(m, orig, dir);
} }
if( ! num_hits() ) { if( ! num_hits() ) {
#endif
clear(); clear();
sgdMakeIdentMat4 ( m ) ; sgdMakeIdentMat4 ( m ) ;
IntersectBranch( scene, m, orig, dir); IntersectBranch( scene, m, orig, dir);
#ifdef USE_CACHED_HIT
} }
#endif
} }