-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
#ifndef _MOOF_PLANE_HH_
#define _MOOF_PLANE_HH_
namespace moof {
+// forward declarations
template <int D> class aabb;
template <int D> class sphere;
-
/**
- * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A,
- * B, C] is normal to the plane.
+ * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A, B,
+ * C] is normal to the plane.
*/
struct plane : public shape<3>
{
enum halfspace
{
- negative = -1,
+ negative = -1,
intersecting = 0,
- positive = 1
+ positive = 1
};
plane() {}
normal(a, b, c),
d(scalar) {}
-
bool intersect_ray(const ray3& ray, ray3::contact& hit)
{
// solve: [(ray.point + t*ray.direction) dot normal] + d = 0
if (hit.distance < SCALAR(0.0)) return false;
if (numer >= 0.0) hit.normal = normal;
- else hit.normal = -normal;
+ else hit.normal = -normal;
return true;
}
-
/* Causes the normal of the plane to become normalized. The scalar may
* also be changed to keep the equation true. Word to the wise: don't
* normalize a plane if the normal is the zero vector.
void normalize()
{
scalar mag = normal.length();
-
normal /= mag;
d /= mag;
}
scalar distance = distance_to_point(point);
if (is_equal(distance, 0.0)) return intersecting;
- else if (distance < 0.0) return negative;
- else return positive;
+ else if (distance < 0.0) return negative;
+ return positive;
}
halfspace intersects(const aabb<3>& aabb) const;