- short i1, i2, i3;
- leaf->getTriangle( i, &i1, &i2, &i3 );
-
- sgdVec3 tri[3];
- sgdSetVec3( tri[0], leaf->getVertex( i1 ) );
- sgdSetVec3( tri[1], leaf->getVertex( i2 ) );
- sgdSetVec3( tri[2], leaf->getVertex( i3 ) );
-
- // avoid division by zero when two points are the same
- if( isZeroAreaTri( tri ) )
- continue;
-
- sgdVec4 plane;
- sgdMakePlane( plane, tri[0], tri[1], tri[2] );
-
- sgdVec3 point;
- if( sgdIsectInfLinePlane( point, orig, dir, plane ) ) {
- if( sgdPointInTriangle( point, tri ) ) {
- // transform point into passed into desired coordinate frame
- sgdXformPnt3( point, point, m );
- add(leaf,i,point,plane);
- num_hits++;
- }
- }
- }
- return num_hits;
-}
-
-
-//=================
-int FGHitList::IntersectPolyOrFanLeaf( ssgLeaf *leaf, sgdMat4 m,
- sgdVec3 orig, sgdVec3 dir )
-{
- double tmp_dist;
-
- // number of hits but there could be more that
- // were not found because of short circut switch !
- // so you may want to use the unspecialized IntersectLeaf()
- int num_hits = 0;
-
- int ntri = leaf->getNumTriangles();
- for ( int n = 0; n < ntri; ++n ) {
- sgdVec3 tri[3];
-
- if ( !n ) {
- sgdSetVec3( tri[0], leaf->getVertex( short(0) ) );
- sgdSetVec3( tri[1], leaf->getVertex( short(1) ) );
- sgdSetVec3( tri[2], leaf->getVertex( short(2) ) );
- } else {
- sgdCopyVec3( tri[1], tri[2] );
- sgdSetVec3( tri[2], leaf->getVertex( short(n+2) ) );
- }
-
- if( isZeroAreaTri( tri ) )
- continue;
-
- sgdVec4 plane;
- sgdMakePlane( plane, tri[0], tri[1], tri[2] );
-
- sgdVec3 point;
-
- //inlined IsectInfLinePlane( point dst, orig, dir, plane )
- {
- SGDfloat tmp = sgdScalarProductVec3 ( dir, plane ) ;
-
- /* Is line parallel to plane? */
- if ( sgdAbs ( tmp ) < FLT_EPSILON /*DBL_EPSILON*/ )
- continue ;
-
- sgdScaleVec3 ( point, dir,
- -( sgdScalarProductVec3 ( orig, plane ) + plane[3] )
- / tmp ) ;
-
- sgdAddVec3 ( point, orig ) ;
- } // end of inlined intersection routine
-
- // short circut if this point is further away then a previous hit
- tmp_dist = sgdScalarProductVec3(point,point);
- if( tmp_dist > test_dist )
- continue;
-
- if( sgdPointInTriangle( point, tri ) ) {
- // transform point into passed coordinate frame
- sgdXformPnt3( point, point, m );
- add(leaf,n,point,plane);
- test_dist = tmp_dist;
- num_hits++;
- }
- }
- return num_hits;
-}
-
-
-//===============
-
-int FGHitList::IntersectTriLeaf( ssgLeaf *leaf, sgdMat4 m,
- sgdVec3 orig, sgdVec3 dir )
-{
- double tmp_dist;
-
- // number of hits but there could be more that
- // were not found because of short circut switch !
- // so you may want to use the unspecialized IntersectLeaf()
- int num_hits = 0;
-
- int ntri = leaf->getNumTriangles();
- for ( int n = 0; n < ntri; ++n ) {
- sgdVec3 tri[3];
- sgdSetVec3( tri[0], leaf->getVertex( short(n*3) ) );
- sgdSetVec3( tri[1], leaf->getVertex( short(n*3+1) ) );
- sgdSetVec3( tri[2], leaf->getVertex( short(n*3+2) ) );
-
- // avoid division by zero when two points are the same
- if( isZeroAreaTri( tri ) )
- continue;
-
- sgdVec4 plane;
- sgdMakePlane( plane, tri[0], tri[1], tri[2] );
-
- sgdVec3 point;
- //inlined IsectInfLinePlane( point dst, orig, dir, plane )
- {
- SGDfloat tmp = sgdScalarProductVec3 ( dir, plane ) ;
-
- /* Is line parallel to plane? */
- if ( sgdAbs ( tmp ) < FLT_EPSILON /*DBL_EPSILON*/ )
- continue ;
-
- sgdScaleVec3 ( point, dir,
- -( sgdScalarProductVec3 ( orig, plane ) + plane[3] )
- / tmp ) ;
-
- sgdAddVec3 ( point, orig ) ;
- } // end of inlined intersection routine
-
- // short circut if this point is further away then a previous hit
- tmp_dist = sgdScalarProductVec3(point,point);
- if( tmp_dist > test_dist )
- continue;
-
- if( sgdPointInTriangle( point, tri ) ) {
- // transform point into passed coordinate frame
- sgdXformPnt3( point, point, m );
- add(leaf,n,point,plane);
- test_dist = tmp_dist;
- num_hits++;
- }
- }
- return num_hits;
-}
-
-//============================
-
-int FGHitList::IntersectStripLeaf( ssgLeaf *leaf, sgdMat4 m,
- sgdVec3 orig, sgdVec3 dir )
-{
- double tmp_dist;
-
- // number of hits but there could be more that
- // were not found because of short circut switch !
- // so you may want to use the unspecialized IntersectLeaf()
- int num_hits = 0;
-
- int ntri = leaf->getNumTriangles();
- for ( int n = 0; n < ntri; ++n ) {
- sgdVec3 tri[3];
-
- if ( !n ) {
- sgdSetVec3( tri[0], leaf->getVertex( short(0) ) );
- sgdSetVec3( tri[1], leaf->getVertex( short(1) ) );
- sgdSetVec3( tri[2], leaf->getVertex( short(2) ) );
- } else {
- if ( n & 1 ) {
- sgdSetVec3( tri[0], leaf->getVertex( short(n+2) ) );
- sgdCopyVec3( tri[1], tri[2] );
- sgdCopyVec3( tri[2], tri[1] );
-
- } else {
- sgdCopyVec3( tri[0], tri[1] );
- sgdCopyVec3( tri[1], tri[2] );
- sgdSetVec3( tri[2], leaf->getVertex( short(n+2) ) );
- }
- }
-
- if( isZeroAreaTri( tri ) )
- continue;
-
- sgdVec4 plane;
- sgdMakePlane( plane, tri[0], tri[1], tri[2] );
-
- sgdVec3 point;
-
- //inlined IsectInfLinePlane( point dst, orig, dir, plane )
- {
- SGDfloat tmp = sgdScalarProductVec3 ( dir, plane ) ;
-
- /* Is line parallel to plane? */
- if ( sgdAbs ( tmp ) < FLT_EPSILON /*DBL_EPSILON*/ )
- continue ;
-
- sgdScaleVec3 ( point, dir,
- -( sgdScalarProductVec3 ( orig, plane ) + plane[3] )
- / tmp ) ;
-
- sgdAddVec3 ( point, orig ) ;
- } // end of inlined intersection routine
-
- // short circut if this point is further away then a previous hit
- tmp_dist = sgdScalarProductVec3(point,point);
- if( tmp_dist > test_dist )
- continue;
-
- if( sgdPointInTriangle( point, tri ) ) {
- // transform point into passed coordinate frame
- sgdXformPnt3( point, point, m );
- add(leaf,n,point,plane);
- test_dist = tmp_dist;
- num_hits++;
- }