diff --git a/include/IntegralVector3.h b/include/IntegralVector3.h index d38d92ae..3b41a348 100644 --- a/include/IntegralVector3.h +++ b/include/IntegralVector3.h @@ -26,11 +26,18 @@ namespace Ogre template class IntegralVector3 { public: - IntegralVector3(Type xToSet, Type yToSet, Type zToSet) + IntegralVector3() + :x(0) + ,y(0) + ,z(0) { - x = xToSet; - y = yToSet; - z = zToSet; + } + + IntegralVector3(Type xToSet, Type yToSet, Type zToSet) + :x(xToSet) + ,y(yToSet) + ,z(zToSet) + { } bool operator==(const IntegralVector3& rhs) const throw() @@ -48,13 +55,25 @@ namespace Ogre return (z < rhs.z); else return false; //They are equal - } + } Type x; Type y; Type z; }; + template + IntegralVector3 operator-(const IntegralVector3& lhs, const IntegralVector3& rhs) + { + IntegralVector3 result; + + result.x = lhs.x - rhs.x; + result.y = lhs.y - rhs.y; + result.z = lhs.z - rhs.z; + + return result; + } + typedef IntegralVector3 CharVector3; typedef IntegralVector3 ShortVector3; typedef IntegralVector3 IntVector3; diff --git a/include/SurfaceVertex.h b/include/SurfaceVertex.h index 83698bb3..0f3c599c 100644 --- a/include/SurfaceVertex.h +++ b/include/SurfaceVertex.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "OgrePrerequisites.h" #include "OgreVector3.h" +#include "IntegralVector3.h" namespace Ogre { @@ -31,7 +32,7 @@ namespace Ogre class SurfaceVertex { public: - Vector3 position; + UIntVector3 position; Vector3 normal; float alpha; @@ -39,9 +40,9 @@ namespace Ogre SurfaceVertex(); - SurfaceVertex(Vector3 positionToSet); + SurfaceVertex(UIntVector3 positionToSet); - SurfaceVertex(Vector3 positionToSet, Vector3 normalToSet); + SurfaceVertex(UIntVector3 positionToSet, Vector3 normalToSet); bool operator==(const SurfaceVertex& rhs) const; diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index c5168493..2c48065b 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -593,9 +593,9 @@ namespace Ogre const uint lastZ = (std::min)(firstZ + OGRE_REGION_SIDE_LENGTH-1,static_cast(OGRE_VOLUME_SIDE_LENGTH-2)); //Offset from lower block corner - const Vector3 offset(firstX,firstY,firstZ); + const UIntVector3 offset(firstX*2,firstY*2,firstZ*2); - Vector3 vertlist[12]; + UIntVector3 vertlist[12]; uchar vertMaterials[12]; VolumeIterator volIter(*volumeData); volIter.setValidRegion(firstX,firstY,firstZ,lastX,lastY,lastZ); @@ -645,95 +645,95 @@ namespace Ogre /* Find the vertices where the surface intersects the cube */ if (edgeTable[iCubeIndex] & 1) { - vertlist[0].x = (static_cast(x) + 0.5); - vertlist[0].y = (static_cast(y)); - vertlist[0].z = (static_cast(z)); + vertlist[0].x = 2*x + 1; + vertlist[0].y = 2*y; + vertlist[0].z = 2*z; vertMaterials[0] = (std::max)(v000,v100); //FIXME - faster way? } if (edgeTable[iCubeIndex] & 2) { - vertlist[1].x = (static_cast(x + 1)); - vertlist[1].y = (static_cast(y) + 0.5); - vertlist[1].z = (static_cast(z)); + vertlist[1].x = 2*x + 2; + vertlist[1].y = 2*y + 1; + vertlist[1].z = 2*z; vertMaterials[1] = (std::max)(v100,v110); } if (edgeTable[iCubeIndex] & 4) { - vertlist[2].x = (static_cast(x) + 0.5); - vertlist[2].y = (static_cast(y + 1)); - vertlist[2].z = (static_cast(z)); + vertlist[2].x = 2*x + 1; + vertlist[2].y = 2*y + 2; + vertlist[2].z = 2*z; vertMaterials[2] = (std::max)(v010,v110); } if (edgeTable[iCubeIndex] & 8) { - vertlist[3].x = (static_cast(x)); - vertlist[3].y = (static_cast(y) + 0.5); - vertlist[3].z = (static_cast(z)); + vertlist[3].x = 2*x; + vertlist[3].y = 2*y + 1; + vertlist[3].z = 2*z; vertMaterials[3] = (std::max)(v000,v010); } if (edgeTable[iCubeIndex] & 16) { - vertlist[4].x = (static_cast(x) + 0.5); - vertlist[4].y = (static_cast(y)); - vertlist[4].z = (static_cast(z + 1)); + vertlist[4].x = 2*x + 1; + vertlist[4].y = 2*y; + vertlist[4].z = 2*z + 2; vertMaterials[4] = (std::max)(v001,v101); } if (edgeTable[iCubeIndex] & 32) { - vertlist[5].x = (static_cast(x + 1)); - vertlist[5].y = (static_cast(y) + 0.5); - vertlist[5].z = (static_cast(z + 1)); + vertlist[5].x = 2*x + 2; + vertlist[5].y = 2*y + 1; + vertlist[5].z = 2*z + 2; vertMaterials[5] = (std::max)(v101,v111); } if (edgeTable[iCubeIndex] & 64) { - vertlist[6].x = (static_cast(x) + 0.5); - vertlist[6].y = (static_cast(y + 1)); - vertlist[6].z = (static_cast(z + 1)); + vertlist[6].x = 2*x + 1; + vertlist[6].y = 2*y + 2; + vertlist[6].z = 2*z + 2; vertMaterials[6] = (std::max)(v011,v111); } if (edgeTable[iCubeIndex] & 128) { - vertlist[7].x = (static_cast(x)); - vertlist[7].y = (static_cast(y) + 0.5); - vertlist[7].z = (static_cast(z + 1)); + vertlist[7].x = 2*x; + vertlist[7].y = 2*y + 1; + vertlist[7].z = 2*z + 2; vertMaterials[7] = (std::max)(v001,v011); } if (edgeTable[iCubeIndex] & 256) { - vertlist[8].x = (static_cast(x)); - vertlist[8].y = (static_cast(y)); - vertlist[8].z = (static_cast(z) + 0.5); + vertlist[8].x = 2*x; + vertlist[8].y = 2*y; + vertlist[8].z = 2*z + 1; vertMaterials[8] = (std::max)(v000,v001); } if (edgeTable[iCubeIndex] & 512) { - vertlist[9].x = (static_cast(x + 1)); - vertlist[9].y = (static_cast(y)); - vertlist[9].z = (static_cast(z) + 0.5); + vertlist[9].x = 2*x + 2; + vertlist[9].y = 2*y; + vertlist[9].z = 2*z + 1; vertMaterials[9] = (std::max)(v100,v101); } if (edgeTable[iCubeIndex] & 1024) { - vertlist[10].x = (static_cast(x + 1)); - vertlist[10].y = (static_cast(y + 1)); - vertlist[10].z = (static_cast(z) + 0.5); + vertlist[10].x = 2*x + 2; + vertlist[10].y = 2*y + 2; + vertlist[10].z = 2*z + 1; vertMaterials[10] = (std::max)(v110,v111); } if (edgeTable[iCubeIndex] & 2048) { - vertlist[11].x = (static_cast(x)); - vertlist[11].y = (static_cast(y + 1)); - vertlist[11].z = (static_cast(z) + 0.5); + vertlist[11].x = 2*x; + vertlist[11].y = 2*y + 2; + vertlist[11].z = 2*z + 1; vertMaterials[11] = (std::max)(v010,v011); } for (int i=0;triTable[iCubeIndex][i]!=-1;i+=3) { //The three vertices forming a triangle - const Vector3 vertex0 = vertlist[triTable[iCubeIndex][i ]] - offset; - const Vector3 vertex1 = vertlist[triTable[iCubeIndex][i+1]] - offset; - const Vector3 vertex2 = vertlist[triTable[iCubeIndex][i+2]] - offset; + const UIntVector3 vertex0 = vertlist[triTable[iCubeIndex][i ]] - offset; + const UIntVector3 vertex1 = vertlist[triTable[iCubeIndex][i+1]] - offset; + const UIntVector3 vertex2 = vertlist[triTable[iCubeIndex][i+2]] - offset; const uchar material0 = vertMaterials[triTable[iCubeIndex][i ]]; const uchar material1 = vertMaterials[triTable[iCubeIndex][i+1]]; diff --git a/source/SurfacePatchRenderable.cpp b/source/SurfacePatchRenderable.cpp index 860c7406..858d3e38 100644 --- a/source/SurfacePatchRenderable.cpp +++ b/source/SurfacePatchRenderable.cpp @@ -64,8 +64,14 @@ namespace Ogre // Drawing stuff int size = verticesToSet.size(); - Vector3 vaabMin = verticesToSet[0].position; - Vector3 vaabMax = verticesToSet[0].position; + Vector3 vaabMin; + Vector3 vaabMax; + vaabMin.x = verticesToSet[0].position.x/2.0f; + vaabMin.y = verticesToSet[0].position.y/2.0f; + vaabMin.z = verticesToSet[0].position.z/2.0f; + vaabMax.x = verticesToSet[0].position.x/2.0f; + vaabMax.y = verticesToSet[0].position.y/2.0f; + vaabMax.z = verticesToSet[0].position.z/2.0f; //LogManager::getSingleton().logMessage("Setting Vertex Data of size " + StringConverter::toString(size)); @@ -73,9 +79,9 @@ namespace Ogre for(int i = 0; i < size; i++) { - *prPos++ = verticesToSet[i].position.x; - *prPos++ = verticesToSet[i].position.y; - *prPos++ = verticesToSet[i].position.z; + *prPos++ = verticesToSet[i].position.x/2.0f; + *prPos++ = verticesToSet[i].position.y/2.0f; + *prPos++ = verticesToSet[i].position.z/2.0f; *prPos++ = verticesToSet[i].normal.x; *prPos++ = verticesToSet[i].normal.y; @@ -100,6 +106,9 @@ namespace Ogre vbuf->unlock(); + vaabMin /= 2.0f; + vaabMax /= 2.0f; + mBox.setExtents(vaabMin, vaabMax); unsigned short* pIdx = static_cast(ibuf->lock(HardwareBuffer::HBL_DISCARD)); diff --git a/source/SurfaceVertex.cpp b/source/SurfaceVertex.cpp index 4a13421c..43b370d2 100644 --- a/source/SurfaceVertex.cpp +++ b/source/SurfaceVertex.cpp @@ -6,12 +6,12 @@ namespace Ogre { } - SurfaceVertex::SurfaceVertex(Vector3 positionToSet) + SurfaceVertex::SurfaceVertex(UIntVector3 positionToSet) :position(positionToSet) { } - SurfaceVertex::SurfaceVertex(Vector3 positionToSet, Vector3 normalToSet) + SurfaceVertex::SurfaceVertex(UIntVector3 positionToSet, Vector3 normalToSet) :position(positionToSet) ,normal(normalToSet) { @@ -20,21 +20,21 @@ namespace Ogre bool SurfaceVertex::operator==(const SurfaceVertex& rhs) const { //We dont't check the normal here as it may not have been set. But if two vertices have the same position they should have the same normal too. - return + /*return ( (abs(position.x - rhs.position.x) <= 0.01) && (abs(position.y - rhs.position.y) <= 0.01) && (abs(position.z - rhs.position.z) <= 0.01) && (abs(alpha - rhs.alpha) <= 0.01) - ); + );*/ - /*return + return ( (position.x == rhs.position.x) && (position.x == rhs.position.y) && (position.x == rhs.position.z) && - (alpha == rhs.alpha) - );*/ + (abs(alpha - rhs.alpha) <= 0.01) + ); } bool SurfaceVertex::operator < (const SurfaceVertex& rhs) const