// 출력할 폴리곤의 인덱스를 생성한다. int ZQuadTree::_GenTriIndex( int nTris, LPVOID pIndex, TERRAINVERTEX* pHeightMap, ZFrustum* pFrustum, float fLODRatio ) { // 컬링된 노드라면 그냥 리턴 if( m_bCulled ) { m_bCulled = FALSE; return nTris; } // 현재 노드가 출력되어야 하는가? if( _IsVisible( pHeightMap, pFrustum->GetPos(), fLODRatio ) ) { #ifdef _USE_INDEX16 LPWORD p = ((LPWORD)pIndex) + nTris * 3; #else LPDWORD p = ((LPDWORD)pIndex) + nTris * 3; #endif *p++ = m_nCorner[0]; *p++ = m_nCorner[1]; *p++ = m_nCorner[2]; nTris++; *p++ = m_nCorner[2]; *p++ = m_nCorner[1]; *p++ = m_nCorner[3]; nTris++; return nTris; } // 자식 노드들 검색 if( m_pChild[CORNER_TL] ) nTris = m_pChild[CORNER_TL]->_GenTriIndex( nTris, pIndex, pHeightMap, pFrustum, fLODRatio ); if( m_pChild[CORNER_TR] ) nTris = m_pChild[CORNER_TR]->_GenTriIndex( nTris, pIndex, pHeightMap, pFrustum, fLODRatio ); if( m_pChild[CORNER_BL] ) nTris = m_pChild[CORNER_BL]->_GenTriIndex( nTris, pIndex, pHeightMap, pFrustum, fLODRatio ); if( m_pChild[CORNER_BR] ) nTris = m_pChild[CORNER_BR]->_GenTriIndex( nTris, pIndex, pHeightMap, pFrustum, fLODRatio ); return nTris; }
// 출력할 폴리곤의 인덱스를 생성한다. int ZQuadTree::_GenTriIndex( int nTris, LPVOID pIndex ) { // 컬링된 노드라면 그냥 리턴 if( m_bCulled ) { m_bCulled = FALSE; return nTris; } // 현재 노드가 출력되어야 하는가? if( _IsVisible() ) { #ifdef _USE_INDEX16 LPWORD p = ((LPWORD)pIndex) + nTris * 3; #else LPDWORD p = ((LPDWORD)pIndex) + nTris * 3; #endif *p++ = m_nCorner[0]; *p++ = m_nCorner[1]; *p++ = m_nCorner[2]; nTris++; *p++ = m_nCorner[2]; *p++ = m_nCorner[1]; *p++ = m_nCorner[3]; nTris++; return nTris; } // 자식 노드들 검색 if( m_pChild[CORNER_TL] ) nTris = m_pChild[CORNER_TL]->_GenTriIndex( nTris, pIndex ); if( m_pChild[CORNER_TR] ) nTris = m_pChild[CORNER_TR]->_GenTriIndex( nTris, pIndex ); if( m_pChild[CORNER_BL] ) nTris = m_pChild[CORNER_BL]->_GenTriIndex( nTris, pIndex ); if( m_pChild[CORNER_BR] ) nTris = m_pChild[CORNER_BR]->_GenTriIndex( nTris, pIndex ); return nTris; }
int ZQuadTree::_GenTriIndex(int nTris, std::vector<Point> &vArray, CGeoMapData &pHeightMap, Point &bottomLeft, CFrustum &pFrustum, float fLODRatio) { if(m_bCulled) { //printf("%d %d bCulled\n", m_nCenter.x, m_nCenter.y); m_bCulled = false; return nTris; } if(_IsVisible(pHeightMap, bottomLeft, pFrustum.GetCamera(), fLODRatio)) { if(m_nCorner[CORNER_TR].x - m_nCorner[CORNER_TL].x <= MIN_SIZE) { //좌측 상단 삼각형; nTris++; vArray.push_back(m_nCorner[CORNER_TL]); vArray.push_back(m_nCorner[CORNER_TR]); vArray.push_back(m_nCorner[CORNER_BL]); //우측 하단 삼각형 nTris++; vArray.push_back(bottomLeft + m_nCorner[CORNER_BL]); vArray.push_back(bottomLeft + m_nCorner[CORNER_TR]); vArray.push_back(bottomLeft + m_nCorner[CORNER_BR]); return nTris; } bool b[4] = {true, true, true, true}; if(m_pNeighbor[EDGE_UP]) b[EDGE_UP] = m_pNeighbor[EDGE_UP] ->_IsVisible(pHeightMap, bottomLeft, pFrustum.GetCamera(), fLODRatio); if(m_pNeighbor[EDGE_DN]) b[EDGE_DN] = m_pNeighbor[EDGE_DN] ->_IsVisible(pHeightMap, bottomLeft, pFrustum.GetCamera(), fLODRatio); if(m_pNeighbor[EDGE_LT]) b[EDGE_LT] = m_pNeighbor[EDGE_LT] ->_IsVisible(pHeightMap, bottomLeft, pFrustum.GetCamera(), fLODRatio); if(m_pNeighbor[EDGE_RT]) b[EDGE_RT] = m_pNeighbor[EDGE_RT] ->_IsVisible(pHeightMap, bottomLeft, pFrustum.GetCamera(), fLODRatio); if(b[EDGE_UP] && b[EDGE_DN] && b[EDGE_LT] && b[EDGE_RT]) { //좌측 상단 삼각형; nTris++; vArray.push_back(m_nCorner[CORNER_TL]); vArray.push_back(m_nCorner[CORNER_TR]); vArray.push_back(m_nCorner[CORNER_BL]); //우측 하단 삼각형 nTris++; vArray.push_back(m_nCorner[CORNER_BL]); vArray.push_back(m_nCorner[CORNER_TR]); vArray.push_back(m_nCorner[CORNER_BR]); return nTris; } Point p; if(!b[EDGE_UP]) { p.x = (m_nCorner[CORNER_TL].x + m_nCorner[CORNER_TR].x) / 2; p.y = m_nCorner[CORNER_TL].y; nTris++; vArray.push_back(m_nCenter); vArray.push_back(m_nCorner[CORNER_TL]); vArray.push_back( p); nTris++; vArray.push_back(m_nCenter); vArray.push_back(p); vArray.push_back(m_nCorner[CORNER_TR]); } else { vArray.push_back(m_nCenter); vArray.push_back(m_nCorner[CORNER_TL]); vArray.push_back(m_nCorner[CORNER_TR]); } if(!b[EDGE_DN]) { p.x = (m_nCorner[CORNER_BL].x + m_nCorner[CORNER_BR].x) / 2; p.y = m_nCorner[CORNER_BL].y; nTris++; vArray.push_back(m_nCenter); vArray.push_back(m_nCorner[CORNER_BR]); vArray.push_back(p); nTris++; vArray.push_back(bottomLeft + m_nCenter); vArray.push_back(p); vArray.push_back(m_nCorner[CORNER_BL]); } else { vArray.push_back(m_nCenter); vArray.push_back(m_nCorner[CORNER_BR]); vArray.push_back(m_nCorner[CORNER_BL]); } if(!b[EDGE_LT]) { p.x = m_nCorner[CORNER_TL].x; p.y = (m_nCorner[CORNER_TL].y + m_nCorner[CORNER_BL].y) / 2; nTris++; vArray.push_back(m_nCenter); vArray.push_back(m_nCorner[CORNER_BL]); vArray.push_back(p); nTris++; vArray.push_back(m_nCenter); vArray.push_back(p); vArray.push_back(m_nCorner[CORNER_TL]); } else { vArray.push_back(m_nCenter); vArray.push_back(m_nCorner[CORNER_BL]); vArray.push_back(m_nCorner[CORNER_TL]); } if(!b[EDGE_RT]) { p.x = m_nCorner[CORNER_TR].x; p.y = (m_nCorner[CORNER_TR].y + m_nCorner[CORNER_BR].y) / 2; nTris++; vArray.push_back(m_nCenter); vArray.push_back(m_nCorner[CORNER_TR]); vArray.push_back(p); nTris++; vArray.push_back(m_nCenter); vArray.push_back(p); vArray.push_back(m_nCorner[CORNER_BR]); } else { vArray.push_back(m_nCenter); vArray.push_back(m_nCorner[CORNER_TR]); vArray.push_back(m_nCorner[CORNER_BR]); } return nTris; } if(m_pChild[CORNER_TL]) nTris = m_pChild[CORNER_TL] -> _GenTriIndex(nTris, vArray, pHeightMap, bottomLeft, pFrustum, fLODRatio); if(m_pChild[CORNER_TR]) nTris = m_pChild[CORNER_TR] -> _GenTriIndex(nTris, vArray, pHeightMap, bottomLeft, pFrustum, fLODRatio); if(m_pChild[CORNER_BL]) nTris = m_pChild[CORNER_BL] -> _GenTriIndex(nTris, vArray, pHeightMap, bottomLeft, pFrustum, fLODRatio); if(m_pChild[CORNER_BR]) nTris = m_pChild[CORNER_BR] -> _GenTriIndex(nTris, vArray, pHeightMap, bottomLeft, pFrustum, fLODRatio); return nTris; }