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:
parent
82c7e75e11
commit
1a5a46c468
1 changed files with 7 additions and 10 deletions
|
@ -92,7 +92,7 @@ Plane::DoesIntersect(const Ray &ray,
|
||||||
|
|
||||||
/* The denominator for the t equation above. */
|
/* The denominator for the t equation above. */
|
||||||
Double vd = mNormal.dot(ray.direction);
|
Double vd = mNormal.dot(ray.direction);
|
||||||
if (vd == 0.0) {
|
if (NearZero(vd)) {
|
||||||
/* The ray is parallel to the plane. */
|
/* The ray is parallel to the plane. */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,10 @@ Plane::DoesIntersect(const Ray &ray,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TooFar(t0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
t.push_back(t0);
|
t.push_back(t0);
|
||||||
return true;
|
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
|
* where (A, B, C) are the coordinates of the normal vector, and D is the
|
||||||
* distance along that vector from the origin.
|
* distance along that vector from the origin.
|
||||||
*/
|
*/
|
||||||
Double x = mNormal.x * p.x;
|
return NearZero(mNormal.dot(p) + mDistance);
|
||||||
Double y = mNormal.y * p.y;
|
|
||||||
Double z = mNormal.z * p.z;
|
|
||||||
return (x + y + z + mDistance) == 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,11 +144,7 @@ Plane::compute_normal(const Vector3 &p)
|
||||||
if (!point_is_on_surface(p)) {
|
if (!point_is_on_surface(p)) {
|
||||||
return Vector3::Zero;
|
return Vector3::Zero;
|
||||||
}
|
}
|
||||||
if (mNormal.dot(p) < 0.0) {
|
|
||||||
return mNormal;
|
return mNormal;
|
||||||
} else {
|
|
||||||
return -mNormal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace charles */
|
} /* namespace charles */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue