Removed setVoxel() function from BlockVolumeIterator and added setVoxelAt() function to BlockVolume.h
Improved OpenGL example.
This commit is contained in:
@ -50,6 +50,9 @@ namespace PolyVox
|
||||
VoxelType getVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos) const;
|
||||
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
|
||||
|
||||
void setVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos, VoxelType tValue);
|
||||
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
|
||||
|
||||
bool containsPoint(const Vector3DFloat& pos, float boundary) const;
|
||||
bool containsPoint(const Vector3DInt32& pos, uint16 boundary) const;
|
||||
BlockVolumeIterator<VoxelType> firstVoxel(void);
|
||||
|
@ -169,6 +169,50 @@ namespace PolyVox
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Setters
|
||||
template <typename VoxelType>
|
||||
void BlockVolume<VoxelType>::setVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos, VoxelType tValue)
|
||||
{
|
||||
const uint16 blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const uint16 blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
const uint16 blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||
|
||||
const uint16 xOffset = uXPos - (blockX << m_uBlockSideLengthPower);
|
||||
const uint16 yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
|
||||
const uint16 zOffset = uZPos - (blockZ << m_uBlockSideLengthPower);
|
||||
|
||||
const uint32 uBlockIndex =
|
||||
blockX +
|
||||
blockY * m_uSideLengthInBlocks +
|
||||
blockZ * m_uSideLengthInBlocks * m_uSideLengthInBlocks;
|
||||
|
||||
const bool bIsShared = m_pIsShared[uBlockIndex];
|
||||
const VoxelType tHomogenousValue = m_pHomogenousValue[uBlockIndex];
|
||||
if(bIsShared)
|
||||
{
|
||||
if(tHomogenousValue != tValue)
|
||||
{
|
||||
m_pBlocks[uBlockIndex] = new Block<VoxelType>(m_uBlockSideLengthPower);
|
||||
m_pIsShared[uBlockIndex] = false;
|
||||
m_pBlocks[uBlockIndex]->fill(tHomogenousValue);
|
||||
m_pBlocks[uBlockIndex]->setVoxelAt(xOffset,yOffset,zOffset, tValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//There is a chance that setting this voxel makes the block homogenous and therefore shareable.
|
||||
m_pIsPotentiallySharable[uBlockIndex] = true;
|
||||
m_pBlocks[uBlockIndex]->setVoxelAt(xOffset,yOffset,zOffset, tValue);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void BlockVolume<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
|
||||
{
|
||||
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Other
|
||||
template <typename VoxelType>
|
||||
bool BlockVolume<VoxelType>::containsPoint(const Vector3DFloat& pos, float boundary) const
|
||||
|
@ -53,8 +53,7 @@ namespace PolyVox
|
||||
void setPosition(const Vector3DInt16& v3dNewPos);
|
||||
void setPosition(uint16 xPos, uint16 yPos, uint16 zPos);
|
||||
void setValidRegion(const Region& region);
|
||||
void setValidRegion(uint16 xFirst, uint16 yFirst, uint16 zFirst, uint16 xLast, uint16 yLast, uint16 zLast);
|
||||
void setVoxel(VoxelType tValue);
|
||||
void setValidRegion(uint16 xFirst, uint16 yFirst, uint16 zFirst, uint16 xLast, uint16 yLast, uint16 zLast);
|
||||
|
||||
bool isValidForRegion(void) const;
|
||||
void moveForwardInRegionFast(void);
|
||||
|
@ -235,35 +235,6 @@ namespace PolyVox
|
||||
mYRegionLastBlock = mYRegionLast >> mVolume.m_uBlockSideLengthPower;
|
||||
mZRegionLastBlock = mZRegionLast >> mVolume.m_uBlockSideLengthPower;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void BlockVolumeIterator<VoxelType>::setVoxel(VoxelType tValue)
|
||||
{
|
||||
const uint32 uBlockIndex =
|
||||
mXBlock +
|
||||
mYBlock * mVolume.m_uSideLengthInBlocks +
|
||||
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
|
||||
|
||||
const bool bIsShared = mVolume.m_pIsShared[uBlockIndex];
|
||||
const VoxelType tHomogenousValue = mVolume.m_pHomogenousValue[uBlockIndex];
|
||||
if(bIsShared)
|
||||
{
|
||||
if(tHomogenousValue != tValue)
|
||||
{
|
||||
mVolume.m_pBlocks[uBlockIndex] = new Block<VoxelType>(mVolume.m_uBlockSideLengthPower);
|
||||
mVolume.m_pIsShared[uBlockIndex] = false;
|
||||
mVolume.m_pBlocks[uBlockIndex]->fill(tHomogenousValue);
|
||||
mCurrentVoxel = mVolume.m_pBlocks[uBlockIndex]->m_tData + mVoxelIndexInBlock;
|
||||
*mCurrentVoxel = tValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//There is a chance that setting this voxel makes the block homogenous and therefore shareable.
|
||||
mVolume.m_pIsPotentiallySharable[uBlockIndex] = true;
|
||||
*mCurrentVoxel = tValue;
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Other
|
||||
|
Reference in New Issue
Block a user