From cc1aa8a514b69525ba97af97d43d7cc29ed6d8d4 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 12 Sep 2010 21:10:15 +0000 Subject: [PATCH] Fix for broken moveNegative...() sampler functions. Fixed bug in surface extractor causing divide by zero and/or infinite vertices. --- library/PolyVoxCore/include/SurfaceExtractor.inl | 6 ++++++ library/PolyVoxCore/include/VolumeSampler.inl | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/library/PolyVoxCore/include/SurfaceExtractor.inl b/library/PolyVoxCore/include/SurfaceExtractor.inl index 983cf0bf..606a45aa 100644 --- a/library/PolyVoxCore/include/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/SurfaceExtractor.inl @@ -467,6 +467,8 @@ namespace PolyVox surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesX[uXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][uYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex; + + m_sampVolume.moveNegativeX(); } if (edgeTable[iCubeIndex] & 8) { @@ -495,6 +497,8 @@ namespace PolyVox surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesY[uXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][uYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex; + + m_sampVolume.moveNegativeY(); } if (edgeTable[iCubeIndex] & 256) { @@ -523,6 +527,8 @@ namespace PolyVox surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesZ[uXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][uYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex; + + m_sampVolume.moveNegativeZ(); } }//For each cell } diff --git a/library/PolyVoxCore/include/VolumeSampler.inl b/library/PolyVoxCore/include/VolumeSampler.inl index dafe2a20..1f5b817c 100644 --- a/library/PolyVoxCore/include/VolumeSampler.inl +++ b/library/PolyVoxCore/include/VolumeSampler.inl @@ -228,11 +228,11 @@ namespace PolyVox template void VolumeSampler::moveNegativeX(void) { - //Note the *post* increament here + //Note the *post* decreament here if((mXPosInVolume--) % mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - ++mCurrentVoxel; + --mCurrentVoxel; } else { @@ -244,11 +244,11 @@ namespace PolyVox template void VolumeSampler::moveNegativeY(void) { - //Note the *post* increament here + //Note the *post* decreament here if((mYPosInVolume--) % mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel += mVolume->m_uBlockSideLength; + mCurrentVoxel -= mVolume->m_uBlockSideLength; } else { @@ -260,11 +260,11 @@ namespace PolyVox template void VolumeSampler::moveNegativeZ(void) { - //Note the *post* increament here + //Note the *post* decreament here if((mZPosInVolume--) % mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel += mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; + mCurrentVoxel -= mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; } else {