From afd06502307d92667133975e9c59c688adbf2059 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 31 Mar 2015 16:33:56 +0200 Subject: [PATCH] Implemented peeking in positive x and negative x directions using Matt's delta lookup table. --- include/PolyVox/PagedVolumeSampler.inl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/PolyVox/PagedVolumeSampler.inl b/include/PolyVox/PagedVolumeSampler.inl index d937bfe3..e6df0331 100644 --- a/include/PolyVox/PagedVolumeSampler.inl +++ b/include/PolyVox/PagedVolumeSampler.inl @@ -21,6 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include + #define CAN_GO_NEG_X(val) ((val % this->mVolume->m_uChunkSideLength != 0)) #define CAN_GO_POS_X(val) (((val + 1) % this->mVolume->m_uChunkSideLength != 0)) #define CAN_GO_NEG_Y(val) ((val % this->mVolume->m_uChunkSideLength != 0)) @@ -30,6 +32,8 @@ freely, subject to the following restrictions: namespace PolyVox { + static const std::array dp = { 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 3511, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 28087, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 3511, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 224695, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 3511, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 28087, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 3511, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 1797559, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 3511, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 28087, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 3511, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 224695, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 3511, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 28087, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1, 3511, 1, 7, 1, 55, 1, 7, 1, 439, 1, 7, 1, 55, 1, 7, 1 }; + template PagedVolume::Sampler::Sampler(PagedVolume* volume) :BaseVolume::template Sampler< PagedVolume >(volume) @@ -284,10 +288,10 @@ namespace PolyVox template VoxelType PagedVolume::Sampler::peekVoxel1nx0py0pz(void) const { - /*if(CAN_GO_NEG_X(this->mXPosInVolume) ) + if(CAN_GO_NEG_X(this->mXPosInVolume) ) { - return *(mCurrentVoxel - 1); - }*/ + return *(mCurrentVoxel - dp[this->m_uXPosInChunk - 1]); + } return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume); } @@ -464,10 +468,10 @@ namespace PolyVox template VoxelType PagedVolume::Sampler::peekVoxel1px0py0pz(void) const { - /*if(CAN_GO_POS_X(this->mXPosInVolume) ) + if(CAN_GO_POS_X(this->mXPosInVolume) ) { - return *(mCurrentVoxel + 1); - }*/ + return *(mCurrentVoxel + dp[this->m_uXPosInChunk]); + } return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume); }