2013-11-27 08:26:28 -05:00
|
|
|
|
|
|
|
// VoronoiMap.h
|
|
|
|
|
|
|
|
// Declares the cVoronoiMap class that implements a Voronoi algorithm over a noise to produce a map
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-11-18 06:07:08 -05:00
|
|
|
#include "Noise/Noise.h"
|
2013-11-27 08:26:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cVoronoiMap
|
|
|
|
{
|
|
|
|
public:
|
2014-09-15 16:34:33 -04:00
|
|
|
cVoronoiMap(int a_Seed, int a_CellSize = 128, int a_JitterSize = 128);
|
2013-11-27 08:26:28 -05:00
|
|
|
|
2014-09-15 16:34:33 -04:00
|
|
|
/** Sets both the cell size and jitter size used for generating the Voronoi seeds. */
|
2013-11-27 08:26:28 -05:00
|
|
|
void SetCellSize(int a_CellSize);
|
2014-09-15 16:34:33 -04:00
|
|
|
|
|
|
|
/** Sets the jitter size. Clamps it to current cell size. */
|
|
|
|
void SetJitterSize(int a_JitterSize);
|
|
|
|
|
|
|
|
/** Sets the offset that is added to each odd row of cells.
|
|
|
|
This offset makes the voronoi cells align to a non-grid.
|
|
|
|
Clamps the value to [-m_CellSize, +m_CellSize]. */
|
|
|
|
void SetOddRowOffset(int a_OddRowOffset);
|
2013-11-27 08:26:28 -05:00
|
|
|
|
2014-09-15 16:34:33 -04:00
|
|
|
/** Returns the value in the cell into which the specified point lies. */
|
2013-11-27 08:26:28 -05:00
|
|
|
int GetValueAt(int a_X, int a_Y);
|
|
|
|
|
2014-09-15 16:34:33 -04:00
|
|
|
/** Returns the value in the cell into which the specified point lies,
|
|
|
|
and the distance to the nearest Voronoi seed. */
|
2013-11-27 08:26:28 -05:00
|
|
|
int GetValueAt(int a_X, int a_Y, int & a_MinDistance);
|
|
|
|
|
2014-09-15 16:34:33 -04:00
|
|
|
/** Returns the value in the cell into which the specified point lies,
|
|
|
|
and the distances to the 2 nearest Voronoi seeds. Uses a cache. */
|
2014-09-17 17:24:22 -04:00
|
|
|
int GetValueAt(
|
|
|
|
int a_X, int a_Y, // Coords to query
|
|
|
|
int & a_NearestSeedX, int & a_NearestSeedY, // Coords of the closest cell's seed
|
|
|
|
int & a_MinDist2 // Distance to the second closest cell's seed
|
|
|
|
);
|
|
|
|
|
|
|
|
/** Finds the nearest and second nearest seeds, returns their coords. */
|
|
|
|
void FindNearestSeeds(
|
|
|
|
int a_X, int a_Y,
|
|
|
|
int & a_NearestSeedX, int & a_NearestSeedY,
|
|
|
|
int & a_SecondNearestSeedX, int & a_SecondNearestSeedY
|
|
|
|
);
|
2014-06-20 11:10:18 -04:00
|
|
|
|
2013-11-27 08:26:28 -05:00
|
|
|
protected:
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The noise used for generating Voronoi seeds */
|
2014-06-20 11:10:18 -04:00
|
|
|
cNoise m_Noise1;
|
|
|
|
cNoise m_Noise2;
|
|
|
|
cNoise m_Noise3;
|
2013-11-27 08:26:28 -05:00
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
/** Size of the Voronoi cells (avg X / Y distance between the seeds). Expected to be at least 2. */
|
2013-11-27 08:26:28 -05:00
|
|
|
int m_CellSize;
|
2014-09-15 16:34:33 -04:00
|
|
|
|
|
|
|
/** The amount that the cell seeds may be offset from the grid.
|
|
|
|
Expected to be at least 1 and less than m_CellSize. */
|
|
|
|
int m_JitterSize;
|
|
|
|
|
|
|
|
/** The constant amount that the cell seeds of every odd row will be offset from the grid.
|
|
|
|
This allows us to have non-rectangular grids.
|
|
|
|
Expected to be between -m_CellSize and +m_CellSize. */
|
|
|
|
int m_OddRowOffset;
|
2014-06-20 11:10:18 -04:00
|
|
|
|
|
|
|
/** The X coordinate of the currently cached cell neighborhood */
|
|
|
|
int m_CurrentCellX;
|
|
|
|
|
|
|
|
/** The Z coordinate of the currently cached cell neighborhood */
|
|
|
|
int m_CurrentCellZ;
|
|
|
|
|
|
|
|
/** The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords */
|
|
|
|
int m_SeedX[5][5];
|
|
|
|
|
|
|
|
/** The seeds of cells around m_CurrentCellX, m_CurrentCellZ, X-coords */
|
|
|
|
int m_SeedZ[5][5];
|
|
|
|
|
|
|
|
|
|
|
|
/** Updates the cached cell seeds to match the specified cell. Noop if cell pos already matches.
|
|
|
|
Updates m_SeedX and m_SeedZ. */
|
|
|
|
void UpdateCell(int a_CellX, int a_CellZ);
|
2013-11-27 08:26:28 -05:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|