Ticket #887: catch-patch-vertex-height.patch
File catch-patch-vertex-height.patch, 4.4 KB (added by , 13 years ago) |
---|
-
source/graphics/Patch.h
61 61 // is already in the DrawList 62 62 bool m_bWillBeDrawn; 63 63 64 bool TileHasVertexBelowHeight(ssize_t x, ssize_t z, float height) const 65 { 66 return m_VertexHeight[x+1][z] < height 67 || m_VertexHeight[x+1][z+1] < height 68 || m_VertexHeight[x][z+1] < height 69 || m_VertexHeight[x][z] < height; 70 } 71 72 void RefreshVertexHeight(); 73 void RecalculateMinimumHeight(); 74 bool HasAnyVertexBelowHeight(float height) const { return m_MinVertexHeight < height; } 75 76 float GetVertexHeight( ssize_t x, ssize_t z) const { return m_VertexHeight[x][z]; } 77 64 78 public: 65 79 // minipatches (tiles) making up the patch 66 80 CMiniPatch m_MiniPatches[PATCH_SIZE][PATCH_SIZE]; … … 68 82 int m_X,m_Z; 69 83 // parent terrain 70 84 CTerrain* m_Parent; 85 // height of each vertex of the minipatches 86 float m_VertexHeight[PATCH_SIZE+1][PATCH_SIZE+1]; 87 // lower vertex height in this patch 88 float m_MinVertexHeight; 71 89 72 90 // draw state... 73 91 void setDrawState(bool value) { m_bWillBeDrawn = value; }; -
source/graphics/Patch.cpp
50 50 m_X=x; 51 51 m_Z=z; 52 52 53 RefreshVertexHeight(); 54 53 55 InvalidateBounds(); 54 56 } 55 57 58 void CPatch::RefreshVertexHeight() 59 { 60 ssize_t init_x = m_X * PATCH_SIZE; 61 ssize_t init_z = m_Z * PATCH_SIZE; 62 63 ssize_t patch_x, patch_z; 64 ssize_t map_x, map_z; 65 66 map_x = init_x; 67 for ( patch_x = 0; patch_x < PATCH_SIZE+1; ++patch_x ) 68 { 69 map_z = init_z; 70 for ( patch_z = 0; patch_z < PATCH_SIZE+1; ++patch_z ) 71 { 72 m_VertexHeight[patch_x][patch_z] = m_Parent->GetVertexGroundLevel(map_x, map_z); 73 ++map_z; 74 } 75 ++map_x; 76 } 77 } 78 79 void CPatch::RecalculateMinimumHeight() 80 { 81 float min_h = m_VertexHeight[0][0]; 82 ssize_t x,z; 83 for ( x=0; x < PATCH_SIZE+1; ++x ) 84 { 85 for ( z=0; z < PATCH_SIZE+1; ++z ) 86 { 87 min_h = std::min(min_h, m_VertexHeight[x][z]); 88 } 89 } 90 m_MinVertexHeight = min_h; 91 } 92 56 93 /////////////////////////////////////////////////////////////////////////////// 57 94 // CalcBounds: calculating the bounds of this patch 58 95 void CPatch::CalcBounds() -
source/renderer/TerrainRenderer.cpp
528 528 m->fancyWaterShader = h; 529 529 } 530 530 } 531 CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); // TODO: stop using g_Game532 531 533 532 CLOSTexture& losTexture = g_Renderer.GetScene().GetLOSTexture(); 534 533 … … 662 661 663 662 float repeatPeriod = (fancy ? WaterMgr->m_RepeatPeriod : 16.0f); 664 663 664 // Some offsets used to go around counterclockwise while keeping code concise 665 const int DX[] = {1,1,0,0}; 666 const int DZ[] = {0,1,1,0}; 667 665 668 glBegin(GL_QUADS); 666 669 667 670 for(size_t i=0; i<m->visiblePatches.size(); i++) 668 671 { 669 672 CPatch* patch = m->visiblePatches[i]->GetPatch(); 673 if ( ! patch->HasAnyVertexBelowHeight(WaterMgr->m_WaterHeight) ) 674 { 675 continue; 676 } 670 677 671 678 for(ssize_t dx=0; dx<PATCH_SIZE; dx++) 672 679 { 673 680 for(ssize_t dz=0; dz<PATCH_SIZE; dz++) 674 681 { 675 ssize_t x = (patch->m_X*PATCH_SIZE + dx); 676 ssize_t z = (patch->m_Z*PATCH_SIZE + dz); 677 678 // Some offsets used to go around counterclockwise while keeping code concise 679 const int DX[] = {1,1,0,0}; 680 const int DZ[] = {0,1,1,0}; 681 682 // is any corner of the tile below the water height? if not, no point rendering it 683 bool shouldRender = false; 684 for (int j = 0; j < 4; j++) 682 if ( ! patch->TileHasVertexBelowHeight(dx, dz, WaterMgr->m_WaterHeight) ) 685 683 { 686 float terrainHeight = terrain->GetVertexGroundLevel(x + DX[j], z + DZ[j]);687 if (terrainHeight < WaterMgr->m_WaterHeight)688 {689 shouldRender = true;690 break;691 }692 }693 if (!shouldRender)694 684 continue; 685 } 695 686 687 ssize_t x = (patch->m_X*PATCH_SIZE + dx); 688 ssize_t z = (patch->m_Z*PATCH_SIZE + dz); 689 696 690 for (int j=0; j<4; j++) 697 691 { 698 692 ssize_t ix = x + DX[j]; … … 701 695 float vertX = ix * CELL_SIZE; 702 696 float vertZ = iz * CELL_SIZE; 703 697 704 float terrainHeight = terrain->GetVertexGroundLevel(ix, iz);698 float terrainHeight = patch->GetVertexHeight(dx+DX[j], dz+DZ[j]); 705 699 706 700 if (fancy) 707 701 {