Game Development Reference
In-Depth Information
#endif //__cplusplus
FLOAT a, b, c, d;
} D3DXPLANE, *LPD3DXPLANE;
where
a
,
b
, and
c
form the components of the plane's normal vector
n
and
d
is the constant
d
, from equation (8).
Point and Plane Spatial Relation
Equation (8) is primarily useful for testing the location of points relative
to the plane. For example, given the plane (
n
,
d
), we can test how a par-
ticular point
p
is in relation with the plane:
If
n
p
+
d
= 0, then
p
is coplanar with the plane.
If
n
p
+
d
> 0, then
p
is in front of the plane and in the plane's
positive half-space.
If
n
p
+
d
< 0, then
p
is in back of the plane and in the plane's
negative half-space.
Note:
If the plane's normal vector
n
is of unit length, then
n
p
+
d
gives the shortest signed distance from the plane to the point
p
.
This next D3DX function evaluates
n
p
+
d
for a particular plane and
point:
FLOAT D3DXPlaneDotCoord(
CONST D3DXPLANE *pP,
// plane.
CONST D3DXVECTOR3 *pV
// point.
);
// Test the locality of a point relative to a plane.
D3DXPLANE p(0.0f, 1.0f, 0.0f, 0.0f);
D3DXVECTOR3 v(3.0f, 5.0f, 2.0f);
float x = D3DXPlaneDotCoord( &p, &v );
if( x approximately equals 0.0f )
// v is coplanar to the plane.
if(x>0)
//visinpositive half-space.
if(x<0)
//visinnegative half-space.
Note:
We say “approximately equals” due to floating-point impreci-
sion. See the note in the section titled “Vector Equality.”
Note:
Methods similar to
D3DXPlaneDotCoord
are
D3DXPlaneDot
and
D3DXPlaneDotNormal
. See the DirectX documentation for details.
Construction
Besides directly specifying the normal and signed distance of a plane,
we can calculate these two components in two ways. Given the normal
n
and a known point on the plane
p
0
, we can solve for the
d
component:
Search WWH ::
Custom Search