From 38b266d261fd284f99e8f5dc58f4ea8d5d3d1a40 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 9 Feb 2008 17:49:34 +0000 Subject: [PATCH] Started removing OgreVector3 from main library. --- include/IntegralVector3.h | 6 ++-- include/PolyVoxSceneManager.h | 8 +++-- include/SurfaceVertex.h | 8 ++--- include/Volume.h | 2 +- include/VolumeIterator.h | 6 ++-- source/PolyVoxSceneManager.cpp | 66 +++++++++++++++++----------------- source/SurfaceVertex.cpp | 8 ++--- source/Volume.cpp | 14 ++++---- source/VolumeIterator.cpp | 20 +++++------ 9 files changed, 70 insertions(+), 68 deletions(-) diff --git a/include/IntegralVector3.h b/include/IntegralVector3.h index 5460ed0a..c83e7034 100644 --- a/include/IntegralVector3.h +++ b/include/IntegralVector3.h @@ -23,6 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include +#include "Vector.hpp" + namespace Ogre { template class IntegralVector3 @@ -66,9 +68,9 @@ namespace Ogre return false; //They are equal } - Vector3 toOgreVector3(void) const + Vector3DFloat toVector3DFloat(void) const { - return Vector3(Real(x), Real(y), Real(z)); + return Vector3DFloat(x, y, z); } Type x; diff --git a/include/PolyVoxSceneManager.h b/include/PolyVoxSceneManager.h index 3178d698..eadab41b 100644 --- a/include/PolyVoxSceneManager.h +++ b/include/PolyVoxSceneManager.h @@ -32,6 +32,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "SurfaceVertex.h" #include "RegionGeometry.h" +#include "Vector.hpp" + #include namespace Ogre @@ -64,13 +66,13 @@ namespace Ogre std::list getChangedRegionGeometry(void); void setAllUpToDateFlagsTo(bool newUpToDateValue); - void createSphereAt(Vector3 centre, Real radius, boost::uint8_t value, bool painting); + void createSphereAt(Vector3DFloat centre, Real radius, boost::uint8_t value, bool painting); void generateLevelVolume(void); void generateMeshDataForRegion(boost::uint16_t regionX,boost:: uint16_t regionY, boost::uint16_t regionZ, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch) const; - bool containsPoint(Vector3 pos, float boundary); + bool containsPoint(Vector3DFloat pos, float boundary); bool containsPoint(IntVector3 pos, boost::uint16_t boundary); @@ -81,7 +83,7 @@ namespace Ogre //SurfacePatchRenderable* m_singleMaterialSurfaces[OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS]; //SurfacePatchRenderable* m_multiMaterialSurfaces[OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS][OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS]; - Vector3 computeNormal(const Vector3& position, NormalGenerationMethod normalGenerationMethod) const; + Vector3DFloat computeNormal(const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod) const; public: void markVoxelChanged(boost::uint16_t x, boost::uint16_t y, boost::uint16_t z); diff --git a/include/SurfaceVertex.h b/include/SurfaceVertex.h index bb0f2a65..0debe5bf 100644 --- a/include/SurfaceVertex.h +++ b/include/SurfaceVertex.h @@ -34,7 +34,7 @@ namespace Ogre public: SurfaceVertex(); SurfaceVertex(UIntVector3 positionToSet, float materialToSet, float alphaToSet); - SurfaceVertex(UIntVector3 positionToSet, Vector3 normalToSet); + SurfaceVertex(UIntVector3 positionToSet, Vector3DFloat normalToSet); friend bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs); friend bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs); @@ -42,19 +42,19 @@ namespace Ogre float getAlpha(void) const; const SurfaceEdgeIterator& getEdge(void) const; float getMaterial(void) const; - const Vector3& getNormal(void) const; + const Vector3DFloat& getNormal(void) const; const UIntVector3& getPosition(void) const; void setAlpha(float alphaToSet); void setEdge(const SurfaceEdgeIterator& edgeToSet); void setMaterial(float materialToSet); - void setNormal(const Vector3& normalToSet); + void setNormal(const Vector3DFloat& normalToSet); std::string toString(void) const; private: UIntVector3 position; - Vector3 normal; + Vector3DFloat normal; float material; float alpha; diff --git a/include/Volume.h b/include/Volume.h index 0d4a6672..1a2c7509 100644 --- a/include/Volume.h +++ b/include/Volume.h @@ -44,7 +44,7 @@ namespace Ogre Block* getBlock(boost::uint16_t index); - bool containsPoint(Vector3 pos, float boundary); + bool containsPoint(Vector3DFloat pos, float boundary); bool containsPoint(IntVector3 pos, boost::uint16_t boundary); bool loadFromFile(const std::string& sFilename); diff --git a/include/VolumeIterator.h b/include/VolumeIterator.h index 63147ecd..ad7989c0 100644 --- a/include/VolumeIterator.h +++ b/include/VolumeIterator.h @@ -42,9 +42,9 @@ namespace Ogre float getAveragedVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, boost::uint16_t size) const; //FIXME - this shouldn't return float vector - Vector3 getCentralDifferenceGradient(void) const; - Vector3 getAveragedCentralDifferenceGradient(void) const; - Vector3 getSobelGradient(void) const; + Vector3DFloat getCentralDifferenceGradient(void) const; + Vector3DFloat getAveragedCentralDifferenceGradient(void) const; + Vector3DFloat getSobelGradient(void) const; boost::uint16_t getPosX(void); boost::uint16_t getPosY(void); diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index 4db14a74..8838c621 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -96,15 +96,15 @@ namespace Ogre } } - void PolyVoxSceneManager::createSphereAt(Vector3 centre, Real radius, uint8_t value, bool painting) + void PolyVoxSceneManager::createSphereAt(Vector3DFloat centre, Real radius, uint8_t value, bool painting) { - int firstX = static_cast(std::floor(centre.x - radius)); - int firstY = static_cast(std::floor(centre.y - radius)); - int firstZ = static_cast(std::floor(centre.z - radius)); + int firstX = static_cast(std::floor(centre.x() - radius)); + int firstY = static_cast(std::floor(centre.y() - radius)); + int firstZ = static_cast(std::floor(centre.z() - radius)); - int lastX = static_cast(std::ceil(centre.x + radius)); - int lastY = static_cast(std::ceil(centre.y + radius)); - int lastZ = static_cast(std::ceil(centre.z + radius)); + int lastX = static_cast(std::ceil(centre.x() + radius)); + int lastY = static_cast(std::ceil(centre.y() + radius)); + int lastZ = static_cast(std::ceil(centre.z() + radius)); Real radiusSquared = radius * radius; @@ -123,7 +123,7 @@ namespace Ogre while(volIter.isValidForRegion()) { //if((volIter.getPosX()*volIter.getPosX()+volIter.getPosY()*volIter.getPosY()+volIter.getPosZ()*volIter.getPosZ()) < radiusSquared) - if((centre - Vector3(volIter.getPosX(),volIter.getPosY(),volIter.getPosZ())).squaredLength() <= radiusSquared) + if((centre - Vector3DFloat(volIter.getPosX(),volIter.getPosY(),volIter.getPosZ())).lengthSquared() <= radiusSquared) { if(painting) { @@ -186,18 +186,18 @@ namespace Ogre } //Rooms - Vector3 centre(128,128,128); - Vector3 v3dSize(192,96,128); + Vector3DFloat centre(128,128,128); + Vector3DFloat v3dSize(192,96,128); - uint16_t uHalfX = static_cast(v3dSize.x / 2); - uint16_t uHalfY = static_cast(v3dSize.y / 2); - uint16_t uHalfZ = static_cast(v3dSize.z / 2); + uint16_t uHalfX = static_cast(v3dSize.x() / 2); + uint16_t uHalfY = static_cast(v3dSize.y() / 2); + uint16_t uHalfZ = static_cast(v3dSize.z() / 2); - for(uint16_t z = static_cast(centre.z) - uHalfZ; z < static_cast(centre.z) + uHalfZ; z++) + for(uint16_t z = static_cast(centre.z()) - uHalfZ; z < static_cast(centre.z()) + uHalfZ; z++) { - for(uint16_t y = static_cast(centre.y) - uHalfY; y < static_cast(centre.y) + uHalfY; y++) + for(uint16_t y = static_cast(centre.y()) - uHalfY; y < static_cast(centre.y()) + uHalfY; y++) { - for(uint16_t x = static_cast(centre.x) - uHalfX; x < static_cast(centre.x) + uHalfX; x++) + for(uint16_t x = static_cast(centre.x()) - uHalfX; x < static_cast(centre.x()) + uHalfX; x++) { volIter.setVoxelAt(x,y,z,0); } @@ -507,7 +507,7 @@ namespace Ogre std::vector::iterator iterSurfaceVertex = singleMaterialPatch->m_vecVertices.begin(); while(iterSurfaceVertex != singleMaterialPatch->m_vecVertices.end()) { - Vector3 tempNormal = computeNormal((iterSurfaceVertex->getPosition() + offset).toOgreVector3()/2.0f, CENTRAL_DIFFERENCE); + Vector3DFloat tempNormal = computeNormal((iterSurfaceVertex->getPosition() + offset).toVector3DFloat()/2.0f, CENTRAL_DIFFERENCE); const_cast(*iterSurfaceVertex).setNormal(tempNormal); ++iterSurfaceVertex; } @@ -515,7 +515,7 @@ namespace Ogre iterSurfaceVertex = multiMaterialPatch->m_vecVertices.begin(); while(iterSurfaceVertex != multiMaterialPatch->m_vecVertices.end()) { - Vector3 tempNormal = computeNormal((iterSurfaceVertex->getPosition() + offset).toOgreVector3()/2.0f, CENTRAL_DIFFERENCE); + Vector3DFloat tempNormal = computeNormal((iterSurfaceVertex->getPosition() + offset).toVector3DFloat()/2.0f, CENTRAL_DIFFERENCE); const_cast(*iterSurfaceVertex).setNormal(tempNormal); ++iterSurfaceVertex; } @@ -531,25 +531,25 @@ namespace Ogre //return singleMaterialPatch; } - Vector3 PolyVoxSceneManager::computeNormal(const Vector3& position, NormalGenerationMethod normalGenerationMethod) const + Vector3DFloat PolyVoxSceneManager::computeNormal(const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod) const { VolumeIterator volIter(*volumeData); //FIXME - save this somewhere - could be expensive to create? - const float posX = position.x; - const float posY = position.y; - const float posZ = position.z; + const float posX = position.x(); + const float posY = position.y(); + const float posZ = position.z(); const uint16_t floorX = static_cast(posX); const uint16_t floorY = static_cast(posY); const uint16_t floorZ = static_cast(posZ); - Vector3 result; + Vector3DFloat result; if(normalGenerationMethod == SOBEL) { volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ)); - const Vector3 gradFloor = volIter.getSobelGradient(); + const Vector3DFloat gradFloor = volIter.getSobelGradient(); if((posX - floorX) > 0.25) //The result should be 0.0 or 0.5 { volIter.setPosition(static_cast(posX+1.0),static_cast(posY),static_cast(posZ)); @@ -562,9 +562,9 @@ namespace Ogre { volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ+1.0)); } - const Vector3 gradCeil = volIter.getSobelGradient(); + const Vector3DFloat gradCeil = volIter.getSobelGradient(); result = ((gradFloor + gradCeil) * -1.0); - if(result.squaredLength() < 0.0001) + if(result.lengthSquared() < 0.0001) { //Operation failed - fall back on simple gradient estimation normalGenerationMethod = SIMPLE; @@ -573,7 +573,7 @@ namespace Ogre if(normalGenerationMethod == CENTRAL_DIFFERENCE) { volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ)); - const Vector3 gradFloor = volIter.getCentralDifferenceGradient(); + const Vector3DFloat gradFloor = volIter.getCentralDifferenceGradient(); if((posX - floorX) > 0.25) //The result should be 0.0 or 0.5 { volIter.setPosition(static_cast(posX+1.0),static_cast(posY),static_cast(posZ)); @@ -586,9 +586,9 @@ namespace Ogre { volIter.setPosition(static_cast(posX),static_cast(posY),static_cast(posZ+1.0)); } - const Vector3 gradCeil = volIter.getCentralDifferenceGradient(); + const Vector3DFloat gradCeil = volIter.getCentralDifferenceGradient(); result = ((gradFloor + gradCeil) * -1.0); - if(result.squaredLength() < 0.0001) + if(result.lengthSquared() < 0.0001) { //Operation failed - fall back on simple gradient estimation normalGenerationMethod = SIMPLE; @@ -601,17 +601,17 @@ namespace Ogre if((posX - floorX) > 0.25) //The result should be 0.0 or 0.5 { uint8_t uCeil = volIter.peekVoxel1px0py0pz() > 0 ? 1 : 0; - result = Vector3(uFloor - uCeil,0.0,0.0); + result = Vector3DFloat(uFloor - uCeil,0.0,0.0); } else if((posY - floorY) > 0.25) //The result should be 0.0 or 0.5 { uint8_t uCeil = volIter.peekVoxel0px1py0pz() > 0 ? 1 : 0; - result = Vector3(0.0,uFloor - uCeil,0.0); + result = Vector3DFloat(0.0,uFloor - uCeil,0.0); } else if((posZ - floorZ) > 0.25) //The result should be 0.0 or 0.5 { uint8_t uCeil = volIter.peekVoxel0px0py1pz() > 0 ? 1 : 0; - result = Vector3(0.0, 0.0,uFloor - uCeil); + result = Vector3DFloat(0.0, 0.0,uFloor - uCeil); } } return result; @@ -701,7 +701,7 @@ namespace Ogre m_normalGenerationMethod = method; } - bool PolyVoxSceneManager::containsPoint(Vector3 pos, float boundary) + bool PolyVoxSceneManager::containsPoint(Vector3DFloat pos, float boundary) { return volumeData->containsPoint(pos, boundary); } diff --git a/source/SurfaceVertex.cpp b/source/SurfaceVertex.cpp index 352bce94..80000974 100644 --- a/source/SurfaceVertex.cpp +++ b/source/SurfaceVertex.cpp @@ -20,7 +20,7 @@ namespace Ogre } - SurfaceVertex::SurfaceVertex(UIntVector3 positionToSet, Vector3 normalToSet) + SurfaceVertex::SurfaceVertex(UIntVector3 positionToSet, Vector3DFloat normalToSet) :position(positionToSet) ,normal(normalToSet) { @@ -42,7 +42,7 @@ namespace Ogre return edge; } - const Vector3& SurfaceVertex::getNormal(void) const + const Vector3DFloat& SurfaceVertex::getNormal(void) const { return normal; } @@ -67,7 +67,7 @@ namespace Ogre edge = edgeToSet; } - void SurfaceVertex::setNormal(const Vector3& normalToSet) + void SurfaceVertex::setNormal(const Vector3DFloat& normalToSet) { normal = normalToSet; normal.normalise(); @@ -76,7 +76,7 @@ namespace Ogre std::string SurfaceVertex::toString(void) const { std::stringstream ss; - ss << "SurfaceVertex: Position = (" << position.x << "," << position.y << "," << position.z << "), Normal = " << StringConverter::toString(normal); + ss << "SurfaceVertex: Position = (" << position.x << "," << position.y << "," << position.z << "), Normal = " << normal; return ss.str(); } diff --git a/source/Volume.cpp b/source/Volume.cpp index 05adef99..f986fbbd 100644 --- a/source/Volume.cpp +++ b/source/Volume.cpp @@ -138,14 +138,14 @@ namespace Ogre return mBlocks[index]; } - bool Volume::containsPoint(Vector3 pos, float boundary) + bool Volume::containsPoint(Vector3DFloat pos, float boundary) { - return (pos.x < OGRE_VOLUME_SIDE_LENGTH - 1 - boundary) - && (pos.y < OGRE_VOLUME_SIDE_LENGTH - 1 - boundary) - && (pos.z < OGRE_VOLUME_SIDE_LENGTH - 1 - boundary) - && (pos.x > boundary) - && (pos.y > boundary) - && (pos.z > boundary); + return (pos.x() < OGRE_VOLUME_SIDE_LENGTH - 1 - boundary) + && (pos.y() < OGRE_VOLUME_SIDE_LENGTH - 1 - boundary) + && (pos.z() < OGRE_VOLUME_SIDE_LENGTH - 1 - boundary) + && (pos.x() > boundary) + && (pos.y() > boundary) + && (pos.z() > boundary); } bool Volume::containsPoint(IntVector3 pos, uint16_t boundary) diff --git a/source/VolumeIterator.cpp b/source/VolumeIterator.cpp index e2e6b77a..f978ba8f 100644 --- a/source/VolumeIterator.cpp +++ b/source/VolumeIterator.cpp @@ -20,8 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "Volume.h" #include "VolumeIterator.h" -#include "OgreVector3.h" - using namespace boost; namespace Ogre @@ -154,7 +152,7 @@ namespace Ogre block->setVoxelAt(xOffset,yOffset,zOffset, value); } - Vector3 VolumeIterator::getCentralDifferenceGradient(void) const + Vector3DFloat VolumeIterator::getCentralDifferenceGradient(void) const { //FIXME - should this test be here? if((mXPosInVolume < 1) || (mXPosInVolume > OGRE_VOLUME_SIDE_LENGTH-2) || @@ -162,7 +160,7 @@ namespace Ogre (mZPosInVolume < 1) || (mZPosInVolume > OGRE_VOLUME_SIDE_LENGTH-2)) { //LogManager::getSingleton().logMessage("Out of range"); - return Vector3(0.0,0.0,0.0); + return Vector3DFloat(0.0,0.0,0.0); } //FIXME - bitwise way of doing this? @@ -175,10 +173,10 @@ namespace Ogre uint8_t voxel1nz = peekVoxel0px0py1nz() > 0 ? 1: 0; uint8_t voxel1pz = peekVoxel0px0py1pz() > 0 ? 1: 0; - return Vector3(int(voxel1px) - int(voxel1nx),int(voxel1py) - int(voxel1ny),int(voxel1pz) - int(voxel1nz)); + return Vector3DFloat(int(voxel1px) - int(voxel1nx),int(voxel1py) - int(voxel1ny),int(voxel1pz) - int(voxel1nz)); } - Vector3 VolumeIterator::getAveragedCentralDifferenceGradient(void) const + Vector3DFloat VolumeIterator::getAveragedCentralDifferenceGradient(void) const { //FIXME - should this test be here? if((mXPosInVolume < 2) || (mXPosInVolume > OGRE_VOLUME_SIDE_LENGTH-3) || @@ -186,7 +184,7 @@ namespace Ogre (mZPosInVolume < 2) || (mZPosInVolume > OGRE_VOLUME_SIDE_LENGTH-3)) { //LogManager::getSingleton().logMessage("Out of range"); - return Vector3(0.0,0.0,0.0); + return Vector3DFloat(0.0,0.0,0.0); } //FIXME - bitwise way of doing this? @@ -199,10 +197,10 @@ namespace Ogre float voxel1nz = getAveragedVoxelAt(mXPosInVolume ,mYPosInVolume ,mZPosInVolume-1,2); float voxel1pz = getAveragedVoxelAt(mXPosInVolume ,mYPosInVolume ,mZPosInVolume+1,2); - return Vector3(voxel1px - voxel1nx,voxel1py - voxel1ny,voxel1pz - voxel1nz); + return Vector3DFloat(voxel1px - voxel1nx,voxel1py - voxel1ny,voxel1pz - voxel1nz); } - Vector3 VolumeIterator::getSobelGradient(void) const + Vector3DFloat VolumeIterator::getSobelGradient(void) const { //FIXME - should this test be here? if((mXPosInVolume < 1) || (mXPosInVolume > OGRE_VOLUME_SIDE_LENGTH-2) || @@ -210,7 +208,7 @@ namespace Ogre (mZPosInVolume < 1) || (mZPosInVolume > OGRE_VOLUME_SIDE_LENGTH-2)) { //LogManager::getSingleton().logMessage("Out of range"); - return Vector3(0.0,0.0,0.0); + return Vector3DFloat(0.0,0.0,0.0); } static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, { @@ -290,7 +288,7 @@ namespace Ogre weights[0][2][2] * ( pVoxel1px1py1nz) + weights[2][2][2] * ( pVoxel1px1py1pz)); - return Vector3(xGrad,yGrad,zGrad); + return Vector3DFloat(xGrad,yGrad,zGrad); } uint16_t VolumeIterator::getPosX(void)