Subtract the centroid
This commit is contained in:
@@ -89,8 +89,12 @@ void SpatialSort::Fill(const aiVector3D *pPositions, unsigned int pNumPositions,
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SpatialSort::Finalize() {
|
||||
const ai_real scale = 1.0f / mPositions.size();
|
||||
for (unsigned int i = 0; i < mPositions.size(); i++) {
|
||||
mPositions[i].mDistance = mPositions[i].mPosition * mPlaneNormal;
|
||||
mCentroid += scale * mPositions[i].mPosition;
|
||||
}
|
||||
for (unsigned int i = 0; i < mPositions.size(); i++) {
|
||||
mPositions[i].mDistance = (mPositions[i].mPosition - mCentroid) * mPlaneNormal;
|
||||
}
|
||||
std::sort(mPositions.begin(), mPositions.end());
|
||||
mFinalized = true;
|
||||
@@ -121,7 +125,7 @@ void SpatialSort::Append(const aiVector3D *pPositions, unsigned int pNumPosition
|
||||
void SpatialSort::FindPositions(const aiVector3D &pPosition,
|
||||
ai_real pRadius, std::vector<unsigned int> &poResults) const {
|
||||
ai_assert(mFinalized && "The SpatialSort object must be finalized before FindPositions can be called.");
|
||||
const ai_real dist = pPosition * mPlaneNormal;
|
||||
const ai_real dist = (pPosition - mCentroid) * mPlaneNormal;
|
||||
const ai_real minDist = dist - pRadius, maxDist = dist + pRadius;
|
||||
|
||||
// clear the array
|
||||
@@ -262,7 +266,7 @@ void SpatialSort::FindIdenticalPositions(const aiVector3D &pPosition, std::vecto
|
||||
|
||||
// Convert the plane distance to its signed integer representation so the ULPs tolerance can be
|
||||
// applied. For some reason, VC won't optimize two calls of the bit pattern conversion.
|
||||
const BinFloat minDistBinary = ToBinary(pPosition * mPlaneNormal) - distanceToleranceInULPs;
|
||||
const BinFloat minDistBinary = ToBinary((pPosition - mCentroid) * mPlaneNormal) - distanceToleranceInULPs;
|
||||
const BinFloat maxDistBinary = minDistBinary + 2 * distanceToleranceInULPs;
|
||||
|
||||
// clear the array in this strange fashion because a simple clear() would also deallocate
|
||||
@@ -312,7 +316,7 @@ unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int> &fill,
|
||||
unsigned int t = 0;
|
||||
const ai_real pSquared = pRadius * pRadius;
|
||||
for (size_t i = 0; i < mPositions.size();) {
|
||||
dist = mPositions[i].mPosition * mPlaneNormal;
|
||||
dist = (mPositions[i].mPosition - mCentroid) * mPlaneNormal;
|
||||
maxDist = dist + pRadius;
|
||||
|
||||
fill[mPositions[i].mIndex] = t;
|
||||
|
||||
Reference in New Issue
Block a user