diff --git a/bsp.h b/bsp.h index e9392ae..8a2aa6e 100644 --- a/bsp.h +++ b/bsp.h @@ -335,7 +335,7 @@ typedef struct World const plane_t* plane = &planes[face->plane_id]; // Check if the point lies on the face's plane (it's not strictly necessary to do this, but this check makes the whole function a lot faster) - if (fabs(plane->pointDistance(point)) > 0.001) + if (fabs(plane->pointDistance(point)) > 0.01) continue; // Check if the point is contained within the face's polygon @@ -363,7 +363,7 @@ typedef struct World double m0 = p0.magnitude(); double m1 = p1.magnitude(); - if ((m0 * m1) <= 0.001) + if ((m0 * m1) <= 0.01) { // Point is on one of the vertices outFaces.push_back(face); @@ -375,7 +375,7 @@ typedef struct World } // If the point is inside the polygon, then the sum of all the above angles will be exactly 360 degrees - if (fabs(2 * M_PI - angleSum) <= 0.001) + if (fabs(2 * M_PI - angleSum) <= 0.01) outFaces.push_back(face); } diff --git a/common.h b/common.h index 9aa824f..894a893 100644 --- a/common.h +++ b/common.h @@ -69,6 +69,14 @@ typedef struct Vec3 // Vector or Position return (double)x * x + (double)y * y + (double)z * z; } + double longestElement() const + { + double longest = fabs(x); + if (fabs(y) > longest) longest = fabs(y); + if (fabs(z) > longest) longest = fabs(z); + return longest; + } + Vec3 normalized() const { double invMag = 1.0 / magnitude(); @@ -138,15 +146,15 @@ template<> struct std::hash static bool operator==(const Vec3& lhs, const Vec3& rhs) { return - fabs(rhs.x - lhs.x) < 0.001 && - fabs(rhs.y - lhs.y) < 0.001 && - fabs(rhs.z - lhs.z) < 0.001; + fabs(rhs.x - lhs.x) < 0.01 && + fabs(rhs.y - lhs.y) < 0.01 && + fabs(rhs.z - lhs.z) < 0.01; } static bool operator<(const Vec3& lhs, const Vec3& rhs) { - if (fabs(rhs.x - lhs.x) < 0.001) - if (fabs(rhs.y - lhs.y) < 0.001) + if (fabs(rhs.x - lhs.x) < 0.01) + if (fabs(rhs.y - lhs.y) < 0.01) return lhs.z < rhs.z; else return lhs.y < rhs.y;