]>
Dogcows Code - chaz/yoink/blob - src/Moof/Plane.hh
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #ifndef _MOOF_PLANE_HH_
13 #define _MOOF_PLANE_HH_
15 #include <Moof/Math.hh>
16 #include <Moof/Shape.hh>
22 template <int D
> class Aabb
;
23 template <int D
> class Sphere
;
27 * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A,
28 * B, C] is normal to the plane.
31 struct Plane
: public Shape
<3>
44 Plane(const Vector3
& vector
, Scalar scalar
) :
47 Plane(Scalar a
, Scalar b
, Scalar c
, Scalar scalar
) :
52 bool intersectRay(const Ray
<3>& ray
, Ray
<3>::Contact
& hit
)
54 // solve: [(ray.point + t*ray.direction) dot normal] + d = 0
56 Scalar denom
= cml::dot(ray
.direction
, normal
);
58 // check for parallel condition
59 if (denom
== SCALAR(0.0))
61 if (isEqual(cml::dot(ray
.point
, normal
), -d
))
63 // the ray lies on the plane
64 hit
.distance
= SCALAR(0.0);
65 hit
.normal
.set(0.0, 0.0, 0.0);
73 Scalar numer
= cml::dot(ray
.point
, normal
) + d
;
74 hit
.distance
= -numer
/ denom
;
75 if (hit
.distance
< SCALAR(0.0)) return false;
77 if (numer
>= 0.0) hit
.normal
= normal
;
78 else hit
.normal
= -normal
;
83 /* Causes the normal of the plane to become normalized. The scalar may
84 * also be changed to keep the equation true. Word to the wise: don't
85 * normalize a plane if the normal is the zero vector.
89 Scalar mag
= normal
.length();
96 * Determine the shortest distance between a point and the plane.
98 Scalar
getDistanceToPoint(const Vector3
& point
) const
100 return cml::dot(point
, normal
) + d
;
103 Halfspace
intersects(const Vector3
& point
) const
105 Scalar distance
= getDistanceToPoint(point
);
107 if (isEqual(distance
, 0.0)) return INTERSECT
;
108 else if (distance
< 0.0) return NEGATIVE
;
109 else return POSITIVE
;
112 Halfspace
intersects(const Aabb
<3>& aabb
) const;
113 Halfspace
intersects(const Sphere
<3>& sphere
) const;
119 #endif // _MOOF_PLANE_HH_
This page took 0.036632 seconds and 4 git commands to generate.