home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / idlib / containers / PlaneSet.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  1KB  |  55 lines

  1.  
  2. #ifndef __PLANESET_H__
  3. #define __PLANESET_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.     Plane Set
  9.  
  10. ===============================================================================
  11. */
  12.  
  13. class idPlaneSet : public idList<idPlane> {
  14. public:
  15.  
  16.     void                    Clear( void ) { idList<idPlane>::Clear(); hash.Free(); }
  17.  
  18.     int                        FindPlane( const idPlane &plane, const float normalEps, const float distEps );
  19.  
  20. private:
  21.     idHashIndex                hash;
  22. };
  23.  
  24. ID_INLINE int idPlaneSet::FindPlane( const idPlane &plane, const float normalEps, const float distEps ) {
  25.     int i, border, hashKey;
  26.  
  27.     assert( distEps <= 0.125f );
  28.  
  29.     hashKey = (int)( idMath::Fabs( plane.Dist() ) * 0.125f );
  30.     for ( border = -1; border <= 1; border++ ) {
  31.         for ( i = hash.First( hashKey + border ); i >= 0; i = hash.Next( i ) ) {
  32.             if ( (*this)[i].Compare( plane, normalEps, distEps ) ) {
  33.                 return i;
  34.             }
  35.         }
  36.     }
  37.  
  38.     if ( plane.Type() >= PLANETYPE_NEGX && plane.Type() < PLANETYPE_TRUEAXIAL ) {
  39.         Append( -plane );
  40.         hash.Add( hashKey, Num()-1 );
  41.         Append( plane );
  42.         hash.Add( hashKey, Num()-1 );
  43.         return ( Num() - 1 );
  44.     }
  45.     else {
  46.         Append( plane );
  47.         hash.Add( hashKey, Num()-1 );
  48.         Append( -plane );
  49.         hash.Add( hashKey, Num()-1 );
  50.         return ( Num() - 2 );
  51.     }
  52. }
  53.  
  54. #endif /* !__PLANESET_H__ */
  55.