Got mesh smoothing working.
Cleaning up code. Various changes made without internet access.
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of a voxel plugin for OGRE
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
@ -16,18 +17,25 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <cstring>
|
||||
#pragma region Headers
|
||||
#include <cassert>
|
||||
#include <cstring> //For memcpy
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
|
||||
#pragma region Constructors/Destructors
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>::Block(boost::uint8_t uSideLengthPower)
|
||||
:m_tData(0)
|
||||
{
|
||||
//Check the block size is sensible. This corresponds to a side length of 256 voxels
|
||||
assert(uSideLengthPower <= 8);
|
||||
if(uSideLengthPower > 8)
|
||||
{
|
||||
throw std::invalid_argument("Block side length must be less than or equal to eight");
|
||||
}
|
||||
|
||||
//Compute the side length
|
||||
m_uSideLengthPower = uSideLengthPower;
|
||||
@ -35,7 +43,7 @@ namespace PolyVox
|
||||
|
||||
//If this fails an exception will be thrown. Memory is not
|
||||
//allocated and there is nothing else in this class to clean up
|
||||
m_tData = new VoxelType[getNoOfVoxels()];
|
||||
m_tData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
@ -50,7 +58,9 @@ namespace PolyVox
|
||||
delete[] m_tData;
|
||||
m_tData = 0;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Operators
|
||||
template <typename VoxelType>
|
||||
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& rhs)
|
||||
{
|
||||
@ -58,43 +68,48 @@ namespace PolyVox
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
memcpy(m_tData,rhs.m_tData,getNoOfVoxels());
|
||||
|
||||
memcpy(m_tData, rhs.m_tData, m_uSideLength * m_uSideLength * m_uSideLength);
|
||||
return *this;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Getters
|
||||
template <typename VoxelType>
|
||||
VoxelType Block<VoxelType>::getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const
|
||||
{
|
||||
return m_tData
|
||||
[
|
||||
xPosition +
|
||||
yPosition * m_uSideLength +
|
||||
zPosition * m_uSideLength * m_uSideLength
|
||||
];
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value)
|
||||
{
|
||||
m_tData
|
||||
[
|
||||
xPosition +
|
||||
yPosition * m_uSideLength +
|
||||
zPosition * m_uSideLength * m_uSideLength
|
||||
] = value;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
boost::uint16_t Block<VoxelType>::getSideLength(void)
|
||||
boost::uint16_t Block<VoxelType>::getSideLength(void) const
|
||||
{
|
||||
return m_uSideLength;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
boost::uint32_t Block<VoxelType>::getNoOfVoxels(void)
|
||||
VoxelType Block<VoxelType>::getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const
|
||||
{
|
||||
return m_uSideLength * m_uSideLength * m_uSideLength;
|
||||
assert(uXPos < m_uSideLength);
|
||||
assert(uYPos < m_uSideLength);
|
||||
assert(uZPos < m_uSideLength);
|
||||
|
||||
return m_tData
|
||||
[
|
||||
uXPos +
|
||||
uYPos * m_uSideLength +
|
||||
uZPos * m_uSideLength * m_uSideLength
|
||||
];
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Setters
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::setVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos, VoxelType tValue)
|
||||
{
|
||||
assert(uXPos < m_uSideLength);
|
||||
assert(uYPos < m_uSideLength);
|
||||
assert(uZPos < m_uSideLength);
|
||||
|
||||
m_tData
|
||||
[
|
||||
uXPos +
|
||||
uYPos * m_uSideLength +
|
||||
uZPos * m_uSideLength * m_uSideLength
|
||||
] = tValue;
|
||||
}
|
||||
#pragma endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user