Commits

Anonymous committed 67c40a4

Fix a rounding bug: when CalculateNormalsSeamless() is comparing GLvectors for equality, it needs to allow some difference between the matching components of the vectors. Otherwise if anything is ever rounded, the equality comparisons will return false instead of true. Also fix glRgba and glVector2, whose operator== overloads had the same issue. Use an epsilon of several decimal places (enough to represent in a float, and catch rounding issues, but not enough to cause significant issues for resolution).

Comments (0)

Files changed (4)

+#define EPSILON 0.000001f
+
 float MathAngle (float angle);
 float MathAngle (float x1, float y1, float x2, float y2);
 float MathAngleDifference (float a1, float a2);

Terrain/glRgba.cpp

 
 bool GLrgba::operator==  (const GLrgba& c)
 {
-  return (red == c.red && green == c.green && blue == c.blue);
+  return (std::fabs(red - c.red) < EPSILON && std::fabs(green - c.green) < EPSILON &&
+          std::fabs(blue - c.blue) < EPSILON);
 }
 
 

Terrain/glVector2.cpp

 
 bool GLvector2::operator== (const GLvector2& c)
 {
-  if (x == c.x && y == c.y)
+  if (std::fabs(x - c.x) < EPSILON && std::fabs(y - c.y) < EPSILON)
     return true;
   return false;
 }

Terrain/glVector3.cpp

 
 bool GLvector::operator== (const GLvector& c)
 {
-  if (x == c.x && y == c.y && z == c.z)
+  if (std::fabs(x - c.x) < EPSILON && std::fabs(y - c.y) < EPSILON &&
+      std::fabs(z == c.z) < EPSILON)
     return true;
   return false;
 }