summaryrefslogtreecommitdiff
path: root/src/collision/Collision.cpp
diff options
context:
space:
mode:
authorerorcun <erorcunerorcun@hotmail.com.tr>2021-01-28 00:51:43 +0300
committererorcun <erorcunerorcun@hotmail.com.tr>2021-01-28 02:18:04 +0300
commit2b269ff1c0b834d9a89c3b6acbec4c73c98cd35a (patch)
treeb6c42b3c3ce8b1122e90ad871b3c06bd3e21c7b0 /src/collision/Collision.cpp
parente9054f298036a73af7491cb6bb0b73e43428d7ca (diff)
Fix some Collision NaN/inf's
Diffstat (limited to 'src/collision/Collision.cpp')
-rw-r--r--src/collision/Collision.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/collision/Collision.cpp b/src/collision/Collision.cpp
index 396e3b85..9d656581 100644
--- a/src/collision/Collision.cpp
+++ b/src/collision/Collision.cpp
@@ -477,8 +477,16 @@ CCollision::TestLineTriangle(const CColLine &line, const CompressedVector *verts
if(plane.CalcPoint(line.p0) * plane.CalcPoint(line.p1) > 0.0f)
return false;
+ float p0dist = DotProduct(line.p1 - line.p0, normal);
+
+#ifdef FIX_BUGS
+ // line lines in the plane, assume no collision
+ if (p0dist == 0.0f)
+ return false;
+#endif
+
// intersection parameter on line
- t = -plane.CalcPoint(line.p0) / DotProduct(line.p1 - line.p0, normal);
+ t = -plane.CalcPoint(line.p0) / p0dist;
// find point of intersection
CVector p = line.p0 + (line.p1-line.p0)*t;
@@ -1286,8 +1294,17 @@ CCollision::ProcessLineTriangle(const CColLine &line,
if(plane.CalcPoint(line.p0) * plane.CalcPoint(line.p1) > 0.0f)
return false;
+ float p0dist = DotProduct(line.p1 - line.p0, normal);
+
+#ifdef FIX_BUGS
+ // line lines in the plane, assume no collision
+ if (p0dist == 0.0f)
+ return false;
+#endif
+
// intersection parameter on line
- t = -plane.CalcPoint(line.p0) / DotProduct(line.p1 - line.p0, normal);
+ t = -plane.CalcPoint(line.p0) / p0dist;
+
// early out if we're beyond the mindist
if(t >= mindist)
return false;