summaryrefslogtreecommitdiff
path: root/core/math/plane.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/math/plane.cpp')
-rw-r--r--core/math/plane.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index ee59a0e171..b01853c4ac 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -110,19 +110,20 @@ bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3
real_t den = normal.dot(segment);
//printf("den is %i\n",den);
- if (Math::abs(den) <= CMP_EPSILON) {
+ if (Math::is_zero_approx(den)) {
return false;
}
- real_t dist = (-normal.dot(p_from) - d) / den;
+ real_t dist = (normal.dot(p_from) - d) / den;
//printf("dist is %i\n",dist);
- if (dist < -CMP_EPSILON) { //this is a ray, before the emitting pos (p_from) doesn't exist
+ if (dist > CMP_EPSILON) { //this is a ray, before the emitting pos (p_from) doesn't exist
return false;
}
+ dist = -dist;
*p_intersection = p_from + segment * dist;
return true;
@@ -134,12 +135,12 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec
real_t den = normal.dot(segment);
//printf("den is %i\n",den);
- if (Math::abs(den) <= CMP_EPSILON) {
+ if (Math::is_zero_approx(den)) {
return false;
}
- real_t dist = (-normal.dot(p_begin) - d) / den;
+ real_t dist = (normal.dot(p_begin) - d) / den;
//printf("dist is %i\n",dist);
if (dist < -CMP_EPSILON || dist > (1.0 + CMP_EPSILON)) {
@@ -147,6 +148,7 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec
return false;
}
+ dist = -dist;
*p_intersection = p_begin + segment * dist;
return true;