From 3f87fc780f6b60f6bf574833921bfca69c96f98e Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 5 Dec 2012 23:49:39 +0100 Subject: [PATCH] Fixed bug with SimpleVolume and negative positions. --- .../include/PolyVoxCore/SimpleVolume.inl | 14 ++++++++------ tests/testvolume.cpp | 9 ++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 6602bac7..4fd15d8e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -174,17 +174,19 @@ namespace PolyVox throw std::invalid_argument("Block side length must be a power of two."); } - m_uBlockSideLength = uBlockSideLength; - m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; - this->m_regValidRegion = regValidRegion; - m_regValidRegionInBlocks.setLowerCorner(this->m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); - m_regValidRegionInBlocks.setUpperCorner(this->m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); - //Compute the block side length m_uBlockSideLength = uBlockSideLength; m_uBlockSideLengthPower = logBase2(m_uBlockSideLength); + m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; + + m_regValidRegionInBlocks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setLowerY(this->m_regValidRegion.getLowerY() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setLowerZ(this->m_regValidRegion.getLowerZ() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setUpperX(this->m_regValidRegion.getUpperX() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uBlockSideLengthPower); + m_regValidRegionInBlocks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uBlockSideLengthPower); //Compute the size of the volume in blocks (and note +1 at the end) m_uWidthInBlocks = m_regValidRegionInBlocks.getUpperCorner().getX() - m_regValidRegionInBlocks.getLowerCorner().getX() + 1; diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index f51925bf..d40c55fe 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -34,8 +34,7 @@ using namespace PolyVox; template int32_t complexVolumeTest(void) { - //VolumeType testVolume(Region(-57, -31, 12, 64, 96, 131)); // Deliberatly awkward size - VolumeType testVolume(Region(0, 0, 0, 63, 63, 63)); + VolumeType testVolume(Region(-57, -31, 12, 64, 96, 131)); // Deliberatly awkward size for(int z = testVolume.getEnclosingRegion().getLowerZ(); z <= testVolume.getEnclosingRegion().getUpperZ(); z++) { for(int y = testVolume.getEnclosingRegion().getLowerY(); y <= testVolume.getEnclosingRegion().getUpperY(); y++) @@ -66,19 +65,19 @@ int32_t complexVolumeTest(void) void TestVolume::testLargeVolume() { int32_t result = complexVolumeTest< LargeVolume >(); - QCOMPARE(result, static_cast(24772608)); + QCOMPARE(result, static_cast(201446400)); } void TestVolume::testRawVolume() { int32_t result = complexVolumeTest< RawVolume >(); - QCOMPARE(result, static_cast(24772608)); + QCOMPARE(result, static_cast(201446400)); } void TestVolume::testSimpleVolume() { int32_t result = complexVolumeTest< SimpleVolume >(); - QCOMPARE(result, static_cast(24772608)); + QCOMPARE(result, static_cast(201446400)); } QTEST_MAIN(TestVolume)