17 m_CellSize(
std::max(a_CellSize, 2)),
18 m_JitterSize(
Clamp(a_JitterSize, 1, a_CellSize)),
20 m_CurrentCellX(9999999),
21 m_CurrentCellZ(9999999)
31 a_CellSize = std::max(a_CellSize, 2);
62 int SeedX, SeedY, MinDist2;
63 return GetValueAt(a_X, a_Y, SeedX, SeedY, MinDist2);
72 int SeedX, SeedY, MinDist2;
73 int res =
GetValueAt(a_X, a_Y, SeedX, SeedY, MinDist2);
74 a_MinDist = (a_X - SeedX) * (a_X - SeedX) + (a_Y - SeedY) * (a_Y - SeedY);
84 int & a_NearestSeedX,
int & a_NearestSeedY,
94 int NearestSeedX = 0, NearestSeedY = 0;
96 int MinDist2 = MinDist;
98 for (
int x = 0; x < 5; x++)
100 for (
int y = 0; y < 5; y++)
105 int Dist = (SeedX - a_X) * (SeedX - a_X) + (SeedY - a_Y) * (SeedY - a_Y);
108 NearestSeedX = SeedX;
109 NearestSeedY = SeedY;
114 else if (Dist < MinDist2)
121 a_NearestSeedX = NearestSeedX;
122 a_NearestSeedY = NearestSeedY;
123 a_MinDist2 = MinDist2;
133 int & a_NearestSeedX,
int & a_NearestSeedY,
134 int & a_SecondNearestSeedX,
int & a_SecondNearestSeedY
143 int NearestSeedX = 0, NearestSeedY = 0;
144 int SecondNearestSeedX = 0, SecondNearestSeedY = 0;
146 int MinDist2 = MinDist;
147 for (
int x = 0; x < 5; x++)
149 for (
int y = 0; y < 5; y++)
154 int Dist = (SeedX - a_X) * (SeedX - a_X) + (SeedY - a_Y) * (SeedY - a_Y);
157 SecondNearestSeedX = NearestSeedX;
158 SecondNearestSeedY = NearestSeedY;
160 NearestSeedX = SeedX;
161 NearestSeedY = SeedY;
164 else if (Dist < MinDist2)
166 SecondNearestSeedX = SeedX;
167 SecondNearestSeedY = SeedY;
173 a_NearestSeedX = NearestSeedX;
174 a_NearestSeedY = NearestSeedY;
175 a_SecondNearestSeedX = SecondNearestSeedX;
176 a_SecondNearestSeedY = SecondNearestSeedY;
192 int NoiseBaseX = a_CellX - 2;
193 int NoiseBaseZ = a_CellZ - 2;
194 for (
int x = 0; x < 5; x++)
198 for (
int z = 0; z < 5; z++)
202 m_SeedX[x][z] = BaseX + OffsetX;
T Clamp(T a_Value, T a_Min, T a_Max)
Clamp X to the specified range.
int IntNoise2DInt(int a_X, int a_Y) const
int m_CurrentCellZ
The Z coordinate of the currently cached cell neighborhood.
int m_SeedX[5][5]
The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords.
void SetCellSize(int a_CellSize)
Sets both the cell size and jitter size used for generating the Voronoi seeds.
int m_CellSize
Size of the Voronoi cells (avg X / Y distance between the seeds).
int m_JitterSize
The amount that the cell seeds may be offset from the grid.
void FindNearestSeeds(int a_X, int a_Y, int &a_NearestSeedX, int &a_NearestSeedY, int &a_SecondNearestSeedX, int &a_SecondNearestSeedY)
Finds the nearest and second nearest seeds, returns their coords.
cVoronoiMap(int a_Seed, int a_CellSize=128, int a_JitterSize=128)
void SetJitterSize(int a_JitterSize)
Sets the jitter size.
int m_CurrentCellX
The X coordinate of the currently cached cell neighborhood.
int m_SeedZ[5][5]
The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords.
void UpdateCell(int a_CellX, int a_CellZ)
Updates the cached cell seeds to match the specified cell.
void SetOddRowOffset(int a_OddRowOffset)
Sets the offset that is added to each odd row of cells.
int m_OddRowOffset
The constant amount that the cell seeds of every odd row will be offset from the grid.
cNoise m_Noise1
The noise used for generating Voronoi seeds.
int GetValueAt(int a_X, int a_Y)
Returns the value in the cell into which the specified point lies.