Merged in RLE branch.

This commit is contained in:
David Williams
2011-04-05 20:55:20 +00:00
54 changed files with 29210 additions and 730 deletions

View File

@ -29,41 +29,41 @@ using namespace PolyVox;
namespace PolyVox
{
const Vector3DInt16 arrayPathfinderFaces[6] =
const Vector3DInt32 arrayPathfinderFaces[6] =
{
Vector3DInt16(0, 0, -1),
Vector3DInt16(0, 0, +1),
Vector3DInt16(0, -1, 0),
Vector3DInt16(0, +1, 0),
Vector3DInt16(-1, 0, 0),
Vector3DInt16(+1, 0, 0)
Vector3DInt32(0, 0, -1),
Vector3DInt32(0, 0, +1),
Vector3DInt32(0, -1, 0),
Vector3DInt32(0, +1, 0),
Vector3DInt32(-1, 0, 0),
Vector3DInt32(+1, 0, 0)
};
const Vector3DInt16 arrayPathfinderEdges[12] =
const Vector3DInt32 arrayPathfinderEdges[12] =
{
Vector3DInt16(0, -1, -1),
Vector3DInt16(0, -1, +1),
Vector3DInt16(0, +1, -1),
Vector3DInt16(0, +1, +1),
Vector3DInt16(-1, 0, -1),
Vector3DInt16(-1, 0, +1),
Vector3DInt16(+1, 0, -1),
Vector3DInt16(+1, 0, +1),
Vector3DInt16(-1, -1, 0),
Vector3DInt16(-1, +1, 0),
Vector3DInt16(+1, -1, 0),
Vector3DInt16(+1, +1, 0)
Vector3DInt32(0, -1, -1),
Vector3DInt32(0, -1, +1),
Vector3DInt32(0, +1, -1),
Vector3DInt32(0, +1, +1),
Vector3DInt32(-1, 0, -1),
Vector3DInt32(-1, 0, +1),
Vector3DInt32(+1, 0, -1),
Vector3DInt32(+1, 0, +1),
Vector3DInt32(-1, -1, 0),
Vector3DInt32(-1, +1, 0),
Vector3DInt32(+1, -1, 0),
Vector3DInt32(+1, +1, 0)
};
const Vector3DInt16 arrayPathfinderCorners[8] =
const Vector3DInt32 arrayPathfinderCorners[8] =
{
Vector3DInt16(-1, -1, -1),
Vector3DInt16(-1, -1, +1),
Vector3DInt16(-1, +1, -1),
Vector3DInt16(-1, +1, +1),
Vector3DInt16(+1, -1, -1),
Vector3DInt16(+1, -1, +1),
Vector3DInt16(+1, +1, -1),
Vector3DInt16(+1, +1, +1)
Vector3DInt32(-1, -1, -1),
Vector3DInt32(-1, -1, +1),
Vector3DInt32(-1, +1, -1),
Vector3DInt32(-1, +1, +1),
Vector3DInt32(+1, -1, -1),
Vector3DInt32(+1, -1, +1),
Vector3DInt32(+1, +1, -1),
Vector3DInt32(+1, +1, +1)
};
}

View File

@ -37,13 +37,13 @@ namespace PolyVox
while(iterSurfaceVertex != vecVertices.end())
{
const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
const Vector3DInt16 v3dFloor = static_cast<Vector3DInt16>(v3dPos);
const Vector3DInt32 v3dFloor = static_cast<Vector3DInt32>(v3dPos);
VolumeSampler<uint8_t> volIter(volumeData);
//Check all corners are within the volume, allowing a boundary for gradient estimation
bool lowerCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor,2);
bool upperCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor+Vector3DInt16(1,1,1),2);
bool upperCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor+Vector3DInt32(1,1,1),2);
if(lowerCornerInside && upperCornerInside) //If this test fails the vertex will be left as it was
{
@ -69,7 +69,7 @@ namespace PolyVox
const Vector3DInt32 v3dFloor = static_cast<Vector3DInt32>(v3dPos);
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor));
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor));
Vector3DFloat gradFloor;
switch(normalGenerationMethod)
{
@ -89,15 +89,15 @@ namespace PolyVox
if((v3dPos.getX() - v3dFloor.getX()) > 0.25) //The result should be 0.0 or 0.5
{
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor+Vector3DInt32(1,0,0)));
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor+Vector3DInt32(1,0,0)));
}
if((v3dPos.getY() - v3dFloor.getY()) > 0.25) //The result should be 0.0 or 0.5
{
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor+Vector3DInt32(0,1,0)));
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor+Vector3DInt32(0,1,0)));
}
if((v3dPos.getZ() - v3dFloor.getZ()) > 0.25) //The result should be 0.0 or 0.5
{
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor+Vector3DInt32(0,0,1)));
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor+Vector3DInt32(0,0,1)));
}
Vector3DFloat gradCeil;
@ -126,7 +126,7 @@ namespace PolyVox
if(normalGenerationMethod == SIMPLE)
{
volIter.setPosition(static_cast<Vector3DInt16>(v3dFloor));
volIter.setPosition(static_cast<Vector3DInt32>(v3dFloor));
const uint8_t uFloor = volIter.getVoxel() > 0 ? 1 : 0;
if((v3dPos.getX() - v3dFloor.getX()) > 0.25) //The result should be 0.0 or 0.5
{

View File

@ -62,7 +62,7 @@ namespace PolyVox
for(int ct = 0; ct < vecVertexMetadata.size(); ct++)
{
Region regTransformed = m_pOutputMesh->m_Region;
regTransformed.shift(regTransformed.getLowerCorner() * static_cast<int16_t>(-1));
regTransformed.shift(regTransformed.getLowerCorner() * static_cast<int32_t>(-1));
//Plus and minus X
vecVertexMetadata[ct].isOnRegionFace.set(RFF_ON_REGION_FACE_NEG_X, m_pOutputMesh->m_vecVertices[ct].getPosition().getX() < regTransformed.getLowerCorner().getX() + 0.001f);
@ -94,7 +94,7 @@ namespace PolyVox
for(int ct = 0; ct < vecVertexMetadata.size(); ct++)
{
Region regTransformed = m_pOutputMesh->m_Region;
regTransformed.shift(regTransformed.getLowerCorner() * static_cast<int16_t>(-1));
regTransformed.shift(regTransformed.getLowerCorner() * static_cast<int32_t>(-1));
//Plus and minus X
vecVertexMetadata[ct].isOnRegionFace.set(RFF_ON_REGION_FACE_NEG_X, m_pOutputMesh->m_vecVertices[ct].getPosition().getX() < regTransformed.getLowerCorner().getX() + 0.001f);

View File

@ -23,36 +23,49 @@ freely, subject to the following restrictions:
#include "Region.h"
#include <limits>
namespace PolyVox
{
const Region Region::MaxRegion
(
Vector3DInt32((std::numeric_limits<int32_t>::min)(), (std::numeric_limits<int32_t>::min)(), (std::numeric_limits<int32_t>::min)()),
Vector3DInt32((std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)())
);
Region::Region()
:m_v3dLowerCorner(0,0,0)
,m_v3dUpperCorner(0,0,0)
{
}
Region::Region(const Vector3DInt16& v3dLowerCorner, const Vector3DInt16& v3dUpperCorner)
Region::Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner)
:m_v3dLowerCorner(v3dLowerCorner)
,m_v3dUpperCorner(v3dUpperCorner)
{
//Check the region is valid.
assert(m_v3dUpperCorner.getX() >= m_v3dLowerCorner.getX());
assert(m_v3dUpperCorner.getY() >= m_v3dLowerCorner.getY());
assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
}
const Vector3DInt16& Region::getLowerCorner(void) const
const Vector3DInt32& Region::getLowerCorner(void) const
{
return m_v3dLowerCorner;
}
const Vector3DInt16& Region::getUpperCorner(void) const
const Vector3DInt32& Region::getUpperCorner(void) const
{
return m_v3dUpperCorner;
}
void Region::setLowerCorner(const Vector3DInt16& v3dLowerCorner)
void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
{
m_v3dLowerCorner = v3dLowerCorner;
}
void Region::setUpperCorner(const Vector3DInt16& v3dUpperCorner)
void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner)
{
m_v3dUpperCorner = v3dUpperCorner;
}
@ -67,7 +80,7 @@ namespace PolyVox
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
}
bool Region::containsPoint(const Vector3DInt16& pos, uint8_t boundary) const
bool Region::containsPoint(const Vector3DInt32& pos, uint8_t boundary) const
{
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
@ -87,39 +100,47 @@ namespace PolyVox
m_v3dUpperCorner.setZ((std::min)(m_v3dUpperCorner.getZ(), other.m_v3dUpperCorner.getZ()));
}
int16_t Region::depth(void) const
int32_t Region::depth(void) const
{
//This function is deprecated and wrong.
assert(false);
return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ();
}
int16_t Region::height(void) const
int32_t Region::height(void) const
{
//This function is deprecated and wrong.
assert(false);
return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY();
}
void Region::shift(const Vector3DInt16& amount)
void Region::shift(const Vector3DInt32& amount)
{
m_v3dLowerCorner += amount;
m_v3dUpperCorner += amount;
}
void Region::shiftLowerCorner(const Vector3DInt16& amount)
void Region::shiftLowerCorner(const Vector3DInt32& amount)
{
m_v3dLowerCorner += amount;
}
void Region::shiftUpperCorner(const Vector3DInt16& amount)
void Region::shiftUpperCorner(const Vector3DInt32& amount)
{
m_v3dUpperCorner += amount;
}
Vector3DInt16 Region::dimensions(void)
Vector3DInt32 Region::dimensions(void)
{
//This function is deprecated and wrong.
assert(false);
return m_v3dUpperCorner - m_v3dLowerCorner;
}
int16_t Region::width(void) const
int32_t Region::width(void) const
{
//This function is deprecated and wrong.
assert(false);
return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX();
}
}