From 120b8e84cc021d6a52819bd3e2f56ec889f225e1 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 30 Mar 2015 23:33:51 +0200 Subject: [PATCH] Added position in chunk and pointer to current chunk data to sampler. --- include/PolyVox/PagedVolume.h | 5 +++++ include/PolyVox/PagedVolumeSampler.inl | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/PolyVox/PagedVolume.h b/include/PolyVox/PagedVolume.h index 0eb87a30..f7b59a58 100644 --- a/include/PolyVox/PagedVolume.h +++ b/include/PolyVox/PagedVolume.h @@ -243,6 +243,11 @@ namespace PolyVox private: //Other current position information VoxelType* mCurrentVoxel; + VoxelType* m_CurrentChunkData; + + uint16_t m_uXPosInChunk; + uint16_t m_uYPosInChunk; + uint16_t m_uZPosInChunk; }; #endif diff --git a/include/PolyVox/PagedVolumeSampler.inl b/include/PolyVox/PagedVolumeSampler.inl index e2184625..d937bfe3 100644 --- a/include/PolyVox/PagedVolumeSampler.inl +++ b/include/PolyVox/PagedVolumeSampler.inl @@ -102,18 +102,21 @@ namespace PolyVox const int32_t uYChunk = this->mYPosInVolume >> this->mVolume->m_uChunkSideLengthPower; const int32_t uZChunk = this->mZPosInVolume >> this->mVolume->m_uChunkSideLengthPower; - const uint16_t uXPosInChunk = static_cast(this->mXPosInVolume - (uXChunk << this->mVolume->m_uChunkSideLengthPower)); - const uint16_t uYPosInChunk = static_cast(this->mYPosInVolume - (uYChunk << this->mVolume->m_uChunkSideLengthPower)); - const uint16_t uZPosInChunk = static_cast(this->mZPosInVolume - (uZChunk << this->mVolume->m_uChunkSideLengthPower)); + m_uXPosInChunk = static_cast(this->mXPosInVolume - (uXChunk << this->mVolume->m_uChunkSideLengthPower)); + m_uYPosInChunk = static_cast(this->mYPosInVolume - (uYChunk << this->mVolume->m_uChunkSideLengthPower)); + m_uZPosInChunk = static_cast(this->mZPosInVolume - (uZChunk << this->mVolume->m_uChunkSideLengthPower)); - const uint32_t uVoxelIndexInChunk = uXPosInChunk + - uYPosInChunk * this->mVolume->m_uChunkSideLength + - uZPosInChunk * this->mVolume->m_uChunkSideLength * this->mVolume->m_uChunkSideLength; + /*const uint32_t uVoxelIndexInChunk = m_uXPosInChunk + + m_uYPosInChunk * this->mVolume->m_uChunkSideLength + + m_uZPosInChunk * this->mVolume->m_uChunkSideLength * this->mVolume->m_uChunkSideLength;*/ + + uint32_t uVoxelIndexInChunk = morton256_x[m_uXPosInChunk] | morton256_y[m_uYPosInChunk] | morton256_z[m_uZPosInChunk]; auto pCurrentChunk = this->mVolume->canReuseLastAccessedChunk(uXChunk, uYChunk, uZChunk) ? this->mVolume->m_pLastAccessedChunk : this->mVolume->getChunk(uXChunk, uYChunk, uZChunk); - mCurrentVoxel = pCurrentChunk->m_tData + uVoxelIndexInChunk; + m_CurrentChunkData = pCurrentChunk->m_tData; + mCurrentVoxel = m_CurrentChunkData + uVoxelIndexInChunk; } template @@ -373,8 +376,7 @@ namespace PolyVox template VoxelType PagedVolume::Sampler::peekVoxel0px0py0pz(void) const { - //return *mCurrentVoxel; - return this->mVolume->getVoxel(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + return *mCurrentVoxel; } template