Use NearZero in plane intersection calculations

Also clean up the "point on surface" logic and remove the normal flipping (doesn't make sense without a ray origin anyway).
This commit is contained in:
Eryn Wells 2014-08-02 14:12:01 -07:00
parent 82c7e75e11
commit 1a5a46c468

View file

@ -92,7 +92,7 @@ Plane::DoesIntersect(const Ray &ray,
/* The denominator for the t equation above. */
Double vd = mNormal.dot(ray.direction);
if (vd == 0.0) {
if (NearZero(vd)) {
/* The ray is parallel to the plane. */
return false;
}
@ -106,6 +106,10 @@ Plane::DoesIntersect(const Ray &ray,
return false;
}
if (TooFar(t0)) {
return false;
}
t.push_back(t0);
return true;
}
@ -126,10 +130,7 @@ Plane::point_is_on_surface(const Vector3 &p)
* where (A, B, C) are the coordinates of the normal vector, and D is the
* distance along that vector from the origin.
*/
Double x = mNormal.x * p.x;
Double y = mNormal.y * p.y;
Double z = mNormal.z * p.z;
return (x + y + z + mDistance) == 0.0;
return NearZero(mNormal.dot(p) + mDistance);
}
@ -143,11 +144,7 @@ Plane::compute_normal(const Vector3 &p)
if (!point_is_on_surface(p)) {
return Vector3::Zero;
}
if (mNormal.dot(p) < 0.0) {
return mNormal;
} else {
return -mNormal;
}
return mNormal;
}
} /* namespace charles */