Skip to content

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 ​

cpp
using HeightFunction = std::function<double(double, double)>

Terrain height at world (x, y).

Constructors & destructor ​

TerrainPatch ​

cpp
TerrainPatch(
    WorldCellBounds bounds,
    unsigned int intervals,
    const HeightFunction &height,
    double skirtDepth=1,
    double textureRepeatMeters=4)

Sample and decimate the terrain over bounds.

Parameters

ParameterDescription
boundsWorld rectangle of the patch.
intervalsFull-resolution grid intervals per side; a power of two in [2, 256].
heightHeight function.
skirtDepthMinimum depth of the edge skirt that hides LOD cracks.
textureRepeatMetersWorld distance per texture-coordinate unit.

Exceptions

ExceptionDescription
std::invalid_argumenton invalid arguments.
std::runtime_errorif heights, normals or texture coordinates overflow float.

Public member functions ​

levels ​

cpp
const std::vector<TerrainPatchLevel> &levels() const

Returns Levels from full resolution (index 0) down to 2 intervals per side.

bounds ​

cpp
WorldCellBounds bounds() const

Returns World rectangle given at construction.

selectLevel ​

cpp
size_t selectLevel(
    double distanceToBounds,
    double focalPixels,
    double pixelError=1) const

Select by measured vertical approximation error in screen pixels. distanceToBounds must conservatively include the patch's height range.

Parameters

ParameterDescription
distanceToBoundsObserver distance to the patch (>= 0).
focalPixelsProjection focal length in pixels.
pixelErrorAllowed screen-space height error in pixels.

Returns Index of the coarsest level whose projected error is within pixelError.

RaiSim — physics for robotics and AI.