Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -136,7 +136,6 @@ RayHeightfieldIntersectionVisitor::RayHeightfieldIntersectionVisitor(const glm:: · 135 unmodified lines | ||
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | static const float EIGHT_BIT_MAXIMUM_RECIPROCAL = 1.0f / 255.0f; |
| 139 | −static const int HEIGHT_BORDER = 1; | |
| 140 | 139 | |
| 141 | 140 | int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance) { |
| 142 | 141 | if (!info.isLeaf) { |
| @@ -151,12 +150,13 @@ int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance · 8 unmodified lines | ||
| 151 | 150 | const uchar* src = (const uchar*)contents.constData(); |
| 152 | 151 | int size = glm::sqrt((float)contents.size()); |
| 153 | 152 | int unextendedSize = size - HeightfieldBuffer::HEIGHT_EXTENSION; |
| 154 | − int highest = HEIGHT_BORDER + unextendedSize; | |
| 153 | + int highest = HeightfieldBuffer::HEIGHT_BORDER + unextendedSize; | |
| 155 | 154 | float heightScale = unextendedSize * EIGHT_BIT_MAXIMUM_RECIPROCAL; |
| 156 | 155 | |
| 157 | 156 | // find the initial location in heightfield coordinates |
| 158 | − glm::vec3 entry = (_origin + distance * _direction - info.minimum + glm::vec3(HEIGHT_BORDER, 0.0f, HEIGHT_BORDER)) * | |
| 159 | − (float)unextendedSize / info.size; | |
| 157 | + glm::vec3 entry = (_origin + distance * _direction - info.minimum) * (float)unextendedSize / info.size; | |
| 158 | + entry.x += HeightfieldBuffer::HEIGHT_BORDER; | |
| 159 | + entry.z += HeightfieldBuffer::HEIGHT_BORDER; | |
| 160 | 160 | glm::vec3 floors = glm::floor(entry); |
| 161 | 161 | glm::vec3 ceils = glm::ceil(entry); |
| 162 | 162 | if (floors.x == ceils.x) { |
| @@ -178,10 +178,10 @@ int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance · 15 unmodified lines | ||
| 178 | 178 | float accumulatedDistance = 0.0f; |
| 179 | 179 | while (withinBounds) { |
| 180 | 180 | // find the heights at the corners of the current cell |
| 181 | − int floorX = qMin(qMax((int)floors.x, HEIGHT_BORDER), highest); | |
| 182 | − int floorZ = qMin(qMax((int)floors.z, HEIGHT_BORDER), highest); | |
| 183 | − int ceilX = qMin(qMax((int)ceils.x, HEIGHT_BORDER), highest); | |
| 184 | − int ceilZ = qMin(qMax((int)ceils.z, HEIGHT_BORDER), highest); | |
| 181 | + int floorX = qMin(qMax((int)floors.x, HeightfieldBuffer::HEIGHT_BORDER), highest); | |
| 182 | + int floorZ = qMin(qMax((int)floors.z, HeightfieldBuffer::HEIGHT_BORDER), highest); | |
| 183 | + int ceilX = qMin(qMax((int)ceils.x, HeightfieldBuffer::HEIGHT_BORDER), highest); | |
| 184 | + int ceilZ = qMin(qMax((int)ceils.z, HeightfieldBuffer::HEIGHT_BORDER), highest); | |
| 185 | 185 | float upperLeft = src[floorZ * size + floorX] * heightScale; |
| 186 | 186 | float upperRight = src[floorZ * size + ceilX] * heightScale; |
| 187 | 187 | float lowerLeft = src[ceilZ * size + floorX] * heightScale; |
| @@ -215,13 +215,13 @@ int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance · 27 unmodified lines | ||
| 215 | 215 | } else { |
| 216 | 216 | // find the exit point and the next cell, and determine whether it's still within the bounds |
| 217 | 217 | exit = entry + exitDistance * _direction; |
| 218 | − withinBounds = (exit.y >= HEIGHT_BORDER && exit.y <= highest); | |
| 218 | + withinBounds = (exit.y >= HeightfieldBuffer::HEIGHT_BORDER && exit.y <= highest); | |
| 219 | 219 | if (exitDistance == xDistance) { |
| 220 | 220 | if (_direction.x > 0.0f) { |
| 221 | 221 | nextFloors.x += 1.0f; |
| 222 | 222 | withinBounds &= (nextCeils.x += 1.0f) <= highest; |
| 223 | 223 | } else { |
| 224 | − withinBounds &= (nextFloors.x -= 1.0f) >= HEIGHT_BORDER; | |
| 224 | + withinBounds &= (nextFloors.x -= 1.0f) >= HeightfieldBuffer::HEIGHT_BORDER; | |
| 225 | 225 | nextCeils.x -= 1.0f; |
| 226 | 226 | } |
| 227 | 227 | } |
| @@ -230,7 +230,7 @@ int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance · 2 unmodified lines | ||
| 230 | 230 | nextFloors.z += 1.0f; |
| 231 | 231 | withinBounds &= (nextCeils.z += 1.0f) <= highest; |
| 232 | 232 | } else { |
| 233 | − withinBounds &= (nextFloors.z -= 1.0f) >= HEIGHT_BORDER; | |
| 233 | + withinBounds &= (nextFloors.z -= 1.0f) >= HeightfieldBuffer::HEIGHT_BORDER; | |
| 234 | 234 | nextCeils.z -= 1.0f; |
| 235 | 235 | } |
| 236 | 236 | } |
| @@ -337,19 +337,19 @@ int HeightfieldHeightVisitor::visit(MetavoxelInfo& info) { · 100 unmodified lines | ||
| 337 | 337 | const uchar* src = (const uchar*)contents.constData(); |
| 338 | 338 | int size = glm::sqrt((float)contents.size()); |
| 339 | 339 | int unextendedSize = size - HeightfieldBuffer::HEIGHT_EXTENSION; |
| 340 | − int highest = HEIGHT_BORDER + unextendedSize; | |
| 340 | + int highest = HeightfieldBuffer::HEIGHT_BORDER + unextendedSize; | |
| 341 | 341 | relative *= unextendedSize / info.size; |
| 342 | − relative.x += HEIGHT_BORDER; | |
| 343 | − relative.z += HEIGHT_BORDER; | |
| 342 | + relative.x += HeightfieldBuffer::HEIGHT_BORDER; | |
| 343 | + relative.z += HeightfieldBuffer::HEIGHT_BORDER; | |
| 344 | 344 | |
| 345 | 345 | // find the bounds of the cell containing the point and the shared vertex heights |
| 346 | 346 | glm::vec3 floors = glm::floor(relative); |
| 347 | 347 | glm::vec3 ceils = glm::ceil(relative); |
| 348 | 348 | glm::vec3 fracts = glm::fract(relative); |
| 349 | − int floorX = qMin(qMax((int)floors.x, HEIGHT_BORDER), highest); | |
| 350 | − int floorZ = qMin(qMax((int)floors.z, HEIGHT_BORDER), highest); | |
| 351 | − int ceilX = qMin(qMax((int)ceils.x, HEIGHT_BORDER), highest); | |
| 352 | − int ceilZ = qMin(qMax((int)ceils.z, HEIGHT_BORDER), highest); | |
| 349 | + int floorX = qMin(qMax((int)floors.x, HeightfieldBuffer::HEIGHT_BORDER), highest); | |
| 350 | + int floorZ = qMin(qMax((int)floors.z, HeightfieldBuffer::HEIGHT_BORDER), highest); | |
| 351 | + int ceilX = qMin(qMax((int)ceils.x, HeightfieldBuffer::HEIGHT_BORDER), highest); | |
| 352 | + int ceilZ = qMin(qMax((int)ceils.z, HeightfieldBuffer::HEIGHT_BORDER), highest); | |
| 353 | 353 | float upperLeft = src[floorZ * size + floorX]; |
| 354 | 354 | float lowerRight = src[ceilZ * size + ceilX]; |
| 355 | 355 | float interpolatedHeight = glm::mix(upperLeft, lowerRight, fracts.z); |
| @@ -593,6 +593,10 @@ void PointBuffer::render(bool cursor) { · 237 unmodified lines | ||
| 593 | 593 | _buffer.release(); |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | +const int HeightfieldBuffer::HEIGHT_BORDER = 1; | |
| 597 | +const int HeightfieldBuffer::SHARED_EDGE = 1; | |
| 598 | +const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE; | |
| 599 | + | |
| 596 | 600 | HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, |
| 597 | 601 | const QByteArray& height, const QByteArray& color) : |
| 598 | 602 | _translation(translation), |