raisin::TerrainPatch
class · #include <rayrai/TerrainPatch.hpp>
CPU terrain geometry, sampled once at full resolution and decimated per patch. Mesh positions are relative to bounds.min; place the visual there. The shared height function must be finite, deterministic, and support normal samples one finest-grid spacing outside the patch.
Public types
HeightFunction
using HeightFunction = std::function<double(double, double)>Terrain height at world (x, y).
Constructors & destructor
TerrainPatch
TerrainPatch(
WorldCellBounds bounds,
unsigned int intervals,
const HeightFunction &height,
double skirtDepth=1,
double textureRepeatMeters=4)Sample and decimate the terrain over bounds.
Parameters
| Parameter | Description |
|---|---|
bounds | World rectangle of the patch. |
intervals | Full-resolution grid intervals per side; a power of two in [2, 256]. |
height | Height function. |
skirtDepth | Minimum depth of the edge skirt that hides LOD cracks. |
textureRepeatMeters | World distance per texture-coordinate unit. |
Exceptions
| Exception | Description |
|---|---|
std::invalid_argument | on invalid arguments. |
std::runtime_error | if heights, normals or texture coordinates overflow float. |
Public member functions
levels
const std::vector<TerrainPatchLevel> &levels() constReturns Levels from full resolution (index 0) down to 2 intervals per side.
bounds
WorldCellBounds bounds() constReturns World rectangle given at construction.
selectLevel
size_t selectLevel(
double distanceToBounds,
double focalPixels,
double pixelError=1) constSelect by measured vertical approximation error in screen pixels. distanceToBounds must conservatively include the patch's height range.
Parameters
| Parameter | Description |
|---|---|
distanceToBounds | Observer distance to the patch (>= 0). |
focalPixels | Projection focal length in pixels. |
pixelError | Allowed screen-space height error in pixels. |
Returns Index of the coarsest level whose projected error is within pixelError.