30inline float vertexHeight(
const QList<float>& heights,
int gridSize,
const LodDeltas& lodDeltas,
int row,
int col)
32 const int verticesPerEdge = gridSize + 1;
33 if (heights.count() != (qsizetype(verticesPerEdge) * verticesPerEdge)) {
36 const int r = std::clamp(row, 0, gridSize);
37 const int c = std::clamp(col, 0, gridSize);
38 const auto raw = [&](
int rr,
int cc) {
return heights.at((qsizetype(rr) * verticesPerEdge) + cc); };
41 if ((r == 0) && (lodDeltas[0] > 0)) {
43 }
else if ((r == gridSize) && (lodDeltas[1] > 0)) {
45 }
else if ((c == 0) && (lodDeltas[2] > 0)) {
47 }
else if ((c == gridSize) && (lodDeltas[3] > 0)) {
53 const bool alongCol = (edge <= 1);
54 const int step = 1 << lodDeltas[edge];
55 const int idx = alongCol ? c : r;
56 const int base = (idx / step) * step;
60 const float t = float(idx - base) / step;
61 const float a = alongCol ? raw(r, base) : raw(base, c);
62 const float b = alongCol ? raw(r, base + step) : raw(base + step, c);
63 return a + ((b - a) * t);
72 const double r = std::clamp(row, 0.0,
double(gridSize));
73 const double c = std::clamp(col, 0.0,
double(gridSize));
74 const int row0 = std::min(
int(r), gridSize - 1);
75 const int col0 = std::min(
int(c), gridSize - 1);
76 const double fr = r - row0;
77 const double fc = c - col0;
78 const auto h = [&](
int dr,
int dc) {
79 return double(
vertexHeight(heights, gridSize, lodDeltas, row0 + dr, col0 + dc));
81 if ((fr + fc) <= 1.0) {
82 return h(0, 0) + ((h(1, 0) - h(0, 0)) * fr) + ((h(0, 1) - h(0, 0)) * fc);
84 return h(1, 1) + ((h(0, 1) - h(1, 1)) * (1.0 - fr)) + ((h(1, 0) - h(1, 1)) * (1.0 - fc));