History

Ray query fix.

Andrzej Kapolka committed 12 years ago

Commit 8c42a3a1 parent 56c6c3c3 files · +26 −31Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 3 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+22−18
@@ -136,7 +136,6 @@ RayHeightfieldIntersectionVisitor::RayHeightfieldIntersectionVisitor(const glm:: · 135 unmodified lines
136136 }
137137
138138 static const float EIGHT_BIT_MAXIMUM_RECIPROCAL = 1.0f / 255.0f;
139−static const int HEIGHT_BORDER = 1;
140139
141140 int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance) {
142141 if (!info.isLeaf) {
@@ -151,12 +150,13 @@ int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance · 8 unmodified lines
151150 const uchar* src = (const uchar*)contents.constData();
152151 int size = glm::sqrt((float)contents.size());
153152 int unextendedSize = size - HeightfieldBuffer::HEIGHT_EXTENSION;
154− int highest = HEIGHT_BORDER + unextendedSize;
153+ int highest = HeightfieldBuffer::HEIGHT_BORDER + unextendedSize;
155154 float heightScale = unextendedSize * EIGHT_BIT_MAXIMUM_RECIPROCAL;
156155
157156 // 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;
160160 glm::vec3 floors = glm::floor(entry);
161161 glm::vec3 ceils = glm::ceil(entry);
162162 if (floors.x == ceils.x) {
@@ -178,10 +178,10 @@ int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance · 15 unmodified lines
178178 float accumulatedDistance = 0.0f;
179179 while (withinBounds) {
180180 // 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);
185185 float upperLeft = src[floorZ * size + floorX] * heightScale;
186186 float upperRight = src[floorZ * size + ceilX] * heightScale;
187187 float lowerLeft = src[ceilZ * size + floorX] * heightScale;
@@ -215,13 +215,13 @@ int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance · 27 unmodified lines
215215 } else {
216216 // find the exit point and the next cell, and determine whether it's still within the bounds
217217 exit = entry + exitDistance * _direction;
218− withinBounds = (exit.y >= HEIGHT_BORDER && exit.y <= highest);
218+ withinBounds = (exit.y >= HeightfieldBuffer::HEIGHT_BORDER && exit.y <= highest);
219219 if (exitDistance == xDistance) {
220220 if (_direction.x > 0.0f) {
221221 nextFloors.x += 1.0f;
222222 withinBounds &= (nextCeils.x += 1.0f) <= highest;
223223 } else {
224− withinBounds &= (nextFloors.x -= 1.0f) >= HEIGHT_BORDER;
224+ withinBounds &= (nextFloors.x -= 1.0f) >= HeightfieldBuffer::HEIGHT_BORDER;
225225 nextCeils.x -= 1.0f;
226226 }
227227 }
@@ -230,7 +230,7 @@ int RayHeightfieldIntersectionVisitor::visit(MetavoxelInfo& info, float distance · 2 unmodified lines
230230 nextFloors.z += 1.0f;
231231 withinBounds &= (nextCeils.z += 1.0f) <= highest;
232232 } else {
233− withinBounds &= (nextFloors.z -= 1.0f) >= HEIGHT_BORDER;
233+ withinBounds &= (nextFloors.z -= 1.0f) >= HeightfieldBuffer::HEIGHT_BORDER;
234234 nextCeils.z -= 1.0f;
235235 }
236236 }
@@ -337,19 +337,19 @@ int HeightfieldHeightVisitor::visit(MetavoxelInfo& info) { · 100 unmodified lines
337337 const uchar* src = (const uchar*)contents.constData();
338338 int size = glm::sqrt((float)contents.size());
339339 int unextendedSize = size - HeightfieldBuffer::HEIGHT_EXTENSION;
340− int highest = HEIGHT_BORDER + unextendedSize;
340+ int highest = HeightfieldBuffer::HEIGHT_BORDER + unextendedSize;
341341 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;
344344
345345 // find the bounds of the cell containing the point and the shared vertex heights
346346 glm::vec3 floors = glm::floor(relative);
347347 glm::vec3 ceils = glm::ceil(relative);
348348 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);
353353 float upperLeft = src[floorZ * size + floorX];
354354 float lowerRight = src[ceilZ * size + ceilX];
355355 float interpolatedHeight = glm::mix(upperLeft, lowerRight, fracts.z);
@@ -593,6 +593,10 @@ void PointBuffer::render(bool cursor) { · 237 unmodified lines
593593 _buffer.release();
594594 }
595595
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+
596600 HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale,
597601 const QByteArray& height, const QByteArray& color) :
598602 _translation(translation),