diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 2d5f4301..d33d6b4c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -109,6 +109,8 @@ namespace PolyVox inline VoxelType peekVoxel1px1py1pz(void) const; protected: + bool isCurrentPositionValid(void) const; + DerivedVolumeType* mVolume; //The current position in the volume @@ -118,6 +120,12 @@ namespace PolyVox WrapMode m_eWrapMode; VoxelType m_tBorder; + + //Whether the current position is inside the volume + //FIXME - Replace these with flags + bool m_bIsCurrentPositionValidInX; + bool m_bIsCurrentPositionValidInY; + bool m_bIsCurrentPositionValidInZ; }; #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index 27275507..f4590196 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -32,6 +32,9 @@ namespace PolyVox ,mZPosInVolume(0) ,m_eWrapMode(WrapModes::Border) ,m_tBorder(0) + ,m_bIsCurrentPositionValidInX(false) + ,m_bIsCurrentPositionValidInY(false) + ,m_bIsCurrentPositionValidInZ(false) { } @@ -59,9 +62,7 @@ namespace PolyVox template void BaseVolume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) { - mXPosInVolume = v3dNewPos.getX(); - mYPosInVolume = v3dNewPos.getY(); - mZPosInVolume = v3dNewPos.getZ(); + setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ()); } template @@ -71,6 +72,10 @@ namespace PolyVox mXPosInVolume = xPos; mYPosInVolume = yPos; mZPosInVolume = zPos; + + m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos); + m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos); + m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos); } template @@ -93,6 +98,7 @@ namespace PolyVox void BaseVolume::Sampler::movePositiveX(void) { mXPosInVolume++; + m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume); } template @@ -100,6 +106,7 @@ namespace PolyVox void BaseVolume::Sampler::movePositiveY(void) { mYPosInVolume++; + m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume); } template @@ -107,6 +114,7 @@ namespace PolyVox void BaseVolume::Sampler::movePositiveZ(void) { mZPosInVolume++; + m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume); } template @@ -114,6 +122,7 @@ namespace PolyVox void BaseVolume::Sampler::moveNegativeX(void) { mXPosInVolume--; + m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume); } template @@ -121,6 +130,7 @@ namespace PolyVox void BaseVolume::Sampler::moveNegativeY(void) { mYPosInVolume--; + m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume); } template @@ -128,6 +138,7 @@ namespace PolyVox void BaseVolume::Sampler::moveNegativeZ(void) { mZPosInVolume--; + m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume); } template @@ -322,4 +333,11 @@ namespace PolyVox { return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1); } + + template + template + bool inline BaseVolume::Sampler::isCurrentPositionValid(void) const + { + return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ; + } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index c740a384..a3660e7c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -105,17 +105,9 @@ namespace PolyVox private: VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; - bool isCurrentPositionValid(void) const; - //Other current position information VoxelType* mCurrentVoxel; - - //Whether the current position is inside the volume - //FIXME - Replace these with flags - bool m_bIsCurrentPositionValidInX; - bool m_bIsCurrentPositionValidInY; - bool m_bIsCurrentPositionValidInZ; }; #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index a6b5d95e..290346a7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -36,9 +36,6 @@ namespace PolyVox RawVolume::Sampler::Sampler(RawVolume* volume) :BaseVolume::template Sampler< RawVolume >(volume) ,mCurrentVoxel(0) - ,m_bIsCurrentPositionValidInX(false) - ,m_bIsCurrentPositionValidInY(false) - ,m_bIsCurrentPositionValidInZ(false) { } @@ -69,10 +66,10 @@ namespace PolyVox template void RawVolume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) { - this->mXPosInVolume = xPos; - this->mYPosInVolume = yPos; - this->mZPosInVolume = zPos; + // Base version updates position and validity flags. + BaseVolume::Sampler< RawVolume >::setPosition(xPos, yPos, zPos); + // Then we update the voxel pointer const Vector3DInt32& v3dLowerCorner = this->mVolume->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = xPos - v3dLowerCorner.getX(); int32_t iLocalYPos = yPos - v3dLowerCorner.getY(); @@ -83,10 +80,6 @@ namespace PolyVox iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight(); mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex; - - m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(xPos); - m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(yPos); - m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(zPos); } template @@ -107,49 +100,61 @@ namespace PolyVox template void RawVolume::Sampler::movePositiveX(void) { - this->mXPosInVolume++; + // Base version updates position and validity flags. + BaseVolume::Sampler< RawVolume >::movePositiveX(); + + // Then we update the voxel pointer ++mCurrentVoxel; - m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume); } template void RawVolume::Sampler::movePositiveY(void) { - this->mYPosInVolume++; + // Base version updates position and validity flags. + BaseVolume::Sampler< RawVolume >::movePositiveY(); + + // Then we update the voxel pointer mCurrentVoxel += this->mVolume->getWidth(); - m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume); } template void RawVolume::Sampler::movePositiveZ(void) { - this->mZPosInVolume++; + // Base version updates position and validity flags. + BaseVolume::Sampler< RawVolume >::movePositiveZ(); + + // Then we update the voxel pointer mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight(); - m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume); } template void RawVolume::Sampler::moveNegativeX(void) { - this->mXPosInVolume--; + // Base version updates position and validity flags. + BaseVolume::Sampler< RawVolume >::moveNegativeX(); + + // Then we update the voxel pointer --mCurrentVoxel; - m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume); } template void RawVolume::Sampler::moveNegativeY(void) { - this->mYPosInVolume--; + // Base version updates position and validity flags. + BaseVolume::Sampler< RawVolume >::moveNegativeY(); + + // Then we update the voxel pointer mCurrentVoxel -= this->mVolume->getWidth(); - m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume); } template void RawVolume::Sampler::moveNegativeZ(void) { - this->mZPosInVolume--; + // Base version updates position and validity flags. + BaseVolume::Sampler< RawVolume >::moveNegativeZ(); + + // Then we update the voxel pointer mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight(); - m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume); } template @@ -463,12 +468,6 @@ namespace PolyVox } } } - - template - bool RawVolume::Sampler::isCurrentPositionValid(void) const - { - return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ; - } } #undef CAN_GO_NEG_X