本文整理汇总了C++中TerrainTile::addBufferUpdateRange方法的典型用法代码示例。如果您正苦于以下问题:C++ TerrainTile::addBufferUpdateRange方法的具体用法?C++ TerrainTile::addBufferUpdateRange怎么用?C++ TerrainTile::addBufferUpdateRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TerrainTile
的用法示例。
在下文中一共展示了TerrainTile::addBufferUpdateRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setValue
float TerrainInteraction::setValue(TerrainTile & tile, unsigned row, unsigned column, float value, bool setToInteractionElement)
{
float stddev = tile.interactStdDeviation;
assert(stddev > 0);
/** clamp value */
if (value < tile.minValidValue) value = tile.minValidValue;
if (value > tile.maxValidValue) value = tile.maxValidValue;
// define the size of the affected interaction area, in grid coords
const float effectRadiusWorld = stddev * 3;
const uint32_t effectRadius = static_cast<uint32_t>(std::ceil(effectRadiusWorld * tile.samplesPerWorldCoord)); // = 0 means to change only the value at (row,column)
bool moveUp = (value - tile.valueAt(row, column)) > 0;
int invert = moveUp ? 1 : -1; // invert the curve if moving downwards
float norm0Inv = 1.0f / normalDist(0, 0, stddev);
float valueRange = std::abs(tile.maxValidValue - tile.minValidValue);
std::function<float(float)> interactHeight = [stddev, norm0Inv, value, valueRange, invert](float x) {
return normalDist(x, 0, stddev) // - normalize normDist to
* norm0Inv // normDist value at interaction center
* (valueRange + 10) // - scale to value range + offset to omit norm values near 0
* invert // - mirror the curve along the y axis if moving downward
+ value // - move along y so that value==0 => y==0
- (valueRange + 10) * invert;
};
unsigned int minRow, maxRow, minColumn, maxColumn;
{
// unchecked signed min/max values, possibly < 0 or > numRows/Column
int iMinRow = row - effectRadius, iMaxRow = row + effectRadius, iMinColumn = column - effectRadius, iMaxColumn = column + effectRadius;
// work on rows and column that are in range of the terrain tile settings and larger than 0
minRow = iMinRow < 0 ? 0 : (iMinRow >= static_cast<signed>(tile.samplesPerAxis) ? tile.samplesPerAxis - 1 : static_cast<unsigned int>(iMinRow));
maxRow = iMaxRow < 0 ? 0 : (iMaxRow >= static_cast<signed>(tile.samplesPerAxis) ? tile.samplesPerAxis - 1 : static_cast<unsigned int>(iMaxRow));
minColumn = iMinColumn < 0 ? 0 : (iMinColumn >= static_cast<signed>(tile.samplesPerAxis) ? tile.samplesPerAxis - 1 : static_cast<unsigned int>(iMinColumn));
maxColumn = iMaxColumn < 0 ? 0 : (iMaxColumn >= static_cast<signed>(tile.samplesPerAxis) ? tile.samplesPerAxis - 1 : static_cast<unsigned int>(iMaxColumn));
}
// also change element id's if requested and the tile supports it
PhysicalTile * physicalTile = dynamic_cast<PhysicalTile*>(&tile);
if (setToInteractionElement) {
assert(physicalTile);
}
uint8_t elementIndex = 0;
if (physicalTile)
elementIndex = physicalTile->elementIndex(m_interactElement);
for (unsigned int r = minRow; r <= maxRow; ++r) {
float relWorldX = (signed(r) - signed(row)) * tile.sampleInterval;
for (unsigned int c = minColumn; c <= maxColumn; ++c) {
float relWorldZ = (signed(c) - signed(column)) * tile.sampleInterval;
float localRadius = std::sqrt(relWorldX*relWorldX + relWorldZ*relWorldZ);
if (localRadius > effectRadiusWorld) // interaction in a circle, not square
continue;
float newLocalHeight = interactHeight(localRadius);
bool localMoveUp = newLocalHeight > tile.valueAt(r, c);
// don't do anything if we pull up the terrain but the local height point is already higher than its calculated height. (vice versa)
if (localMoveUp != moveUp)
continue;
tile.setValue(r, c, newLocalHeight);
if (setToInteractionElement)
physicalTile->setElement(r, c, elementIndex);
}
tile.addBufferUpdateRange(minColumn + r * tile.samplesPerAxis, 1u + effectRadius * 2u);
}
if (physicalTile)
physicalTile->addToPxUpdateBox(minRow, maxRow, minColumn, maxColumn);
return value;
}