Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HeightMipmap.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 /*
20  * Describes ground using heightmap mipmaps
21  * Used for camera movement
22  */
23 
24 #ifndef INCLUDED_HEIGHTMIPMAP
25 #define INCLUDED_HEIGHTMIPMAP
26 
27 #include "lib/file/vfs/vfs_path.h"
28 
29 struct SMipmap
30 {
31  SMipmap() : m_MapSize(0), m_Heightmap(0) { }
32  SMipmap(size_t MapSize, u16* Heightmap) : m_MapSize(MapSize), m_Heightmap(Heightmap) { }
33 
34  size_t m_MapSize;
36 };
37 
39 {
41 public:
42 
43  CHeightMipmap();
45 
46  void Initialize(size_t mapSize, const u16* ptr);
47  void ReleaseData();
48 
49  // update the heightmap mipmaps
50  void Update(const u16* ptr);
51 
52  // update a section of the heightmap mipmaps
53  // (coordinates are heightmap cells, inclusive of lower bounds,
54  // exclusive of upper bounds)
55  void Update(const u16* ptr, size_t left, size_t bottom, size_t right, size_t top);
56 
57  float GetTrilinearGroundLevel(float x, float z, float radius) const;
58 
59  void DumpToDisk(const VfsPath& path) const;
60 
61 private:
62 
63  // get bilinear filtered height from mipmap
64  float BilinearFilter(const SMipmap &mipmap, float x, float z) const;
65 
66  // update rectangle of the output mipmap by bilinear interpolating an input mipmap of exactly twice its size
67  void HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const u16* ptr, size_t left, size_t bottom, size_t right, size_t top);
68 
69  // update rectangle of the output mipmap by bilinear interpolating the input mipmap
70  void BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u16* ptr, size_t left, size_t bottom, size_t right, size_t top);
71 
72  // size of this map in each direction
73  size_t m_MapSize;
74 
75  // mipmap list
76  std::vector<SMipmap> m_Mipmap;
77 };
78 
79 #endif
void DumpToDisk(const VfsPath &path) const
void ReleaseData()
float BilinearFilter(const SMipmap &mipmap, float x, float z) const
size_t m_MapSize
Definition: HeightMipmap.h:73
float GetTrilinearGroundLevel(float x, float z, float radius) const
void BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u16 *ptr, size_t left, size_t bottom, size_t right, size_t top)
NONCOPYABLE(CHeightMipmap)
u16 * m_Heightmap
Definition: HeightMipmap.h:35
void HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const u16 *ptr, size_t left, size_t bottom, size_t right, size_t top)
void Initialize(size_t mapSize, const u16 *ptr)
Definition: path.h:75
void Update(const u16 *ptr)
size_t m_MapSize
Definition: HeightMipmap.h:34
std::vector< SMipmap > m_Mipmap
Definition: HeightMipmap.h:76
#define u16
Definition: types.h:40
SMipmap(size_t MapSize, u16 *Heightmap)
Definition: HeightMipmap.h:32