From 683306797ddd6a2252abc5d1851b941e00452f88 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 17 Nov 2014 11:43:16 -0800 Subject: [PATCH] Working on adjusting the range limits when we raise/lower past the original bounds. --- libraries/metavoxels/src/Spanner.cpp | 36 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/libraries/metavoxels/src/Spanner.cpp b/libraries/metavoxels/src/Spanner.cpp index 325bd80d04..ee397a1475 100644 --- a/libraries/metavoxels/src/Spanner.cpp +++ b/libraries/metavoxels/src/Spanner.cpp @@ -1741,7 +1741,7 @@ Spanner* Heightfield::paintHeight(const glm::vec3& position, float radius, float glm::vec3 start = glm::floor(center - extents); glm::vec3 end = glm::ceil(center + extents); - // paint all points within the radius + // first see if we're going to exceed the range limits float z = qMax(start.z, 0.0f); float startX = qMax(start.x, 0.0f), endX = qMin(end.x, (float)highestX); quint16* lineDest = contents.data() + (int)z * heightWidth + (int)startX; @@ -1749,6 +1749,34 @@ Spanner* Heightfield::paintHeight(const glm::vec3& position, float radius, float float squaredRadiusReciprocal = 1.0f / squaredRadius; float scaledHeight = height * numeric_limits::max() / (getScale() * _aspectY); float multiplierZ = inverseScale.x / inverseScale.z; + int minimumValue = 1, maximumValue = numeric_limits::max(); + for (float endZ = qMin(end.z, (float)highestZ); z <= endZ; z += 1.0f) { + quint16* dest = lineDest; + for (float x = startX; x <= endX; x += 1.0f, dest++) { + float dx = x - center.x, dz = (z - center.z) * multiplierZ; + float distanceSquared = dx * dx + dz * dz; + if (distanceSquared <= squaredRadius) { + // height falls off towards edges + int value = *dest; + if (value != 0) { + value += scaledHeight * (squaredRadius - distanceSquared) * squaredRadiusReciprocal; + minimumValue = qMin(minimumValue, value); + maximumValue = qMax(maximumValue, value); + } + } + } + lineDest += heightWidth; + } + + // renormalize if necessary + if (minimumValue < 1 || maximumValue > numeric_limits::max()) { + + } + + // now apply the actual change + z = qMax(start.z, 0.0f); + lineDest = contents.data() + (int)z * heightWidth + (int)startX; + scaledHeight = height * numeric_limits::max() / (getScale() * newHeightfield->getAspectY()); bool changed = false; for (float endZ = qMin(end.z, (float)highestZ); z <= endZ; z += 1.0f) { quint16* dest = lineDest; @@ -1757,9 +1785,9 @@ Spanner* Heightfield::paintHeight(const glm::vec3& position, float radius, float float distanceSquared = dx * dx + dz * dz; if (distanceSquared <= squaredRadius) { // height falls off towards edges - int value = *dest + scaledHeight * (squaredRadius - distanceSquared) * squaredRadiusReciprocal; - if (value != *dest) { - *dest = qMin(qMax(value, 0), (int)numeric_limits::max()); + int value = *dest; + if (value != 0) { + *dest = value + scaledHeight * (squaredRadius - distanceSquared) * squaredRadiusReciprocal; changed = true; } }