프로그래밍 2014. 4. 21. 11:08

 

bsp 트리 ( bsp tree ) - 소스 코드

 

 

#define qDelete(p)        { if(p) { delete p;     p=NULL; } }
#define qDeleteA(p)      { if(p) { delete [] p;  p=NULL; } }

 

 

//2. bsp 트리 제거

//재귀호출

void Delete_BSP( BSPTree* T )
{
 if( T == NULL )
  return;

 

 if( T->pFront )
  Delete_BSP( T->pFront );

 

 if( T->pBack )
  Delete_BSP( T->pBack );

 

 if( T->pLeaf )
  Delete_BSP( T->pLeaf );

 

 qDelete( T );
}

 

//두 벡터의 거리 구하기

inline float VDistance_NoW( const Vector4& v1, const Vector4& v2 )
{
 float x = v1.x - v2.x;
 float y = v1.y - v2.y;
 float z = v1.z - v2.z;

 return sqrtf( x * x + y * y + z * z );
}

 

 

//3. 트리 검색

//재귀호출

void Collect_BSP( BSPTree* _pT, Vector4 _v, float _fCollectRad )
{
 if( !_pT )
  return;

 

 iLoopCount++;

 

 if( _pT->pVal )
 {
  if( VDistance_NoW( *_pT->pVal, _v ) > _pT->fRad ) //정점들간의 거리와,

                                                                           //트리노드 값의 반지름값을 비교
  {
   return;
  }
 }

 

 if( _pT->pFront )
  Collect_BSP( _pT->pFront, _v, _fCollectRad );
 
 if( _pT->pBack )
  Collect_BSP( _pT->pBack, _v, _fCollectRad );

 

 if( _pT->pLeaf )
  Collect_BSP( _pT->pLeaf, _v, _fCollectRad );  

 

 //
 if( !_pT->pVal )
  return;

 

 if( VDistance_NoW( *_pT->pVal, _v ) > _fCollectRad )
 {
  return;
 }

 

 //point
 pList[iListCount] = _pT->pVal;

 iListCount++;

}

 

 

 

 

posted by BK dddDang
: