Exemplo n.º 1
0
void AVQuadTree::Build(TERRAIN_VERTEX *pHeightMap, int cell, int tile)
{
	int tiles  = tile + 1;
	int vertex = cell * tile + 1;
		
	int tl = ((m_nCorner[DIR_TL]/tiles) * cell * vertex) 
		+ ((m_nCorner[DIR_TL]%tiles) * cell);
	int br = ((m_nCorner[DIR_BR]/tiles) * cell * vertex)
		+ ((m_nCorner[DIR_BR]%tiles) * cell);

	//좌상단, 우하단을 뺌
	D3DXVECTOR3 v = pHeightMap[tl].p - pHeightMap[br].p;

	//경계구의 반지름
	m_fRadius = D3DXVec3Length(&v) / 2.f;
	m_vCenter = (pHeightMap[tl].p + pHeightMap[br].p) / 2.f;

	//최 하단 노드의 반지름, 중심점 셋팅이 전혀 되질 않아.
	//뭐.. 안되면 미리 계산 없애버리고 만들어버리는게 낫기야 하겠다

	//여기서는 타일별이 아닌, 각각 한칸을 기준으로 잡고 나눈다.

	if(_SubDivide() == false)
		return;

	for(int i=0; i<4; i++)
		m_pChild[i]->Build(pHeightMap, cell, tile);
}
void ZBspTree::_SubDivide( ZBspNode* p )
{
	ZBspNode * front_node = NULL;
	ZBspNode * back_node = NULL;

	ZBspFace* bestface = _FindBestSplitter( p->GetFaces() );
	
	if ( bestface == NULL )
	{
		_MakeLeaf( p );
		return;
	}

	*(p->GetPlane()) = *(bestface->GetPlane());

	ZBspFace * fr = NULL;
	ZBspFace * bk = NULL;
	
	_GetSortedFaceList ( bestface->GetPlane() , p->GetFaces(), &fr , &bk );
	p->SetFaces( NULL );	// Face정보는 Leaf노드에서만 갖고있어야 한다.

	if ( bk )
	{
		back_node = new ZBspNode();
		back_node->SetFaces( bk );
		p->SetBackNode( back_node );
		_SubDivide( p->GetBackNode() );
	}
	else
	{
		back_node = new ZBspNode();
		back_node->SetFaces( NULL );
		back_node->SetNodeType( ZBspNode::NODETYPE_SOLIDLEAF );
		p->SetBackNode( back_node );
	}

	if ( fr )
	{
		front_node = new ZBspNode();
		front_node->SetFaces( fr );
		p->SetFrontNode( front_node );
		_SubDivide( p->GetFrontNode() );
	}
}
Exemplo n.º 3
0
void AVQuadTree::Build( TERRAIN_VERTEX *pHeightMap )
{
	//좌상단, 우하단을 뺌
	D3DXVECTOR3 v = pHeightMap[m_nCorner[DIR_TL]].p - pHeightMap[m_nCorner[DIR_BR]].p;

	//경계구의 반지름
	m_fRadius = D3DXVec3Length(&v) / 2.f;
	m_vCenter = (pHeightMap[m_nCorner[DIR_TL]].p + pHeightMap[m_nCorner[DIR_BR]].p) / 2.f;

	if(_SubDivide() == false)
		return;

	for(int i=0; i<4; i++)
		m_pChild[i]->Build(pHeightMap);
}
// 쿼드트리를 만든다.
BOOL	ZQuadTree::Build( TERRAINVERTEX* pHeightMap )
{
	if( _SubDivide() )
	{
		// 좌측상단과, 우측 하단의 거리를 구한다.
		D3DXVECTOR3 v = *((D3DXVECTOR3*)(pHeightMap+m_nCorner[CORNER_TL])) - 
					    *((D3DXVECTOR3*)(pHeightMap+m_nCorner[CORNER_BR]));
		// v의 거리값이 이 노드를 감싸는 경계구의 지름이므로, 
		// 2로 나누어 반지름을 구한다.
		m_fRadius	  = D3DXVec3Length( &v ) / 2.0f;
		m_pChild[CORNER_TL]->Build( pHeightMap );
		m_pChild[CORNER_TR]->Build( pHeightMap );
		m_pChild[CORNER_BL]->Build( pHeightMap );
		m_pChild[CORNER_BR]->Build( pHeightMap );
	}
	return TRUE;
}
Exemplo n.º 5
0
bool ZQuadTree::_BuildQuadTree(CGeoMapData &pHeightMap, Point &bottomLeft)
{
	const unsigned char *buffer = pHeightMap.GetGeoBuffer();
	int nXSize = pHeightMap.GetXSize();
	int nBands = pHeightMap.GetNBands();

	m_fRadius = _GetDistance(Vertex (bottomLeft.x + m_nCorner[CORNER_TL].x, bottomLeft.y + m_nCorner[CORNER_TL].y, 0),
		Vertex(bottomLeft.x + m_nCorner[CORNER_BR].x, bottomLeft.y + m_nCorner[CORNER_BR].y, 0)) / 2.0f;

	if(_SubDivide())
	{
		m_pChild[CORNER_TL] -> _BuildQuadTree(pHeightMap, bottomLeft);
		m_pChild[CORNER_TR] -> _BuildQuadTree(pHeightMap, bottomLeft);
		m_pChild[CORNER_BL] -> _BuildQuadTree(pHeightMap, bottomLeft);
		m_pChild[CORNER_BR] -> _BuildQuadTree(pHeightMap, bottomLeft);
	}

	return true;
}
BOOL ZBspTree::Build( LPSTR szFileName )
{
	BSPMAPDATA		data;
	ZSimpleParser*	parser;
	parser = new ZSimpleParser;
	if( !parser->Parse( szFileName, &data ) ) return FALSE;
	DEL( parser );

	m_nFaceCount = data.nFaceCount;
	m_nVertCount = data.nVertCount;
	m_pVerts = data.pVerts;
	m_pIndices = data.pIndices;

	_CreateFaceList();

	m_pRootNode = new ZBspNode();
	m_pRootNode->SetFaces( m_pRootFace );
	_SubDivide( m_pRootNode );

	return TRUE;
}