Game Development Reference
In-Depth Information
{
// Inside the plane is defined as the direction the normal is facing
float result = D3DXPlaneDotCoord(this, &point);
return (result >= 0.0f);
}
bool Plane::Inside(const Vec3 &point, const float radius) const
{
float fDistance; // calculate our distances to each of the planes
// find the distance to this plane
fDistance = D3DXPlaneDotCoord(this, &point);
// if this distance is < -radius, we are outside
return (fDistance >= -radius);
}
Basically, if you know three points on the surface of the plane, you
ll have enough
information to create it mathematically. You can also create planes in other ways,
and you
'
'
re perfectly free to extend this bare-bones class to create more constructors,
but this simple version goes a surprisingly long way.
Once the plane is initialized, you can ask whether a point or a sphere (defined by a
point and a radius) is on the inside or outside of the plane. Inside is defined as being
on the same side as the plane normal. The plane normal is defined by the coefficients
a , b , and c inside the D3DXPLANE structure and is calculated for you when the
Plane class is constructed.
The Plane is rarely used by itself. It is usually used to create things like BSP trees,
portals, and a camera view frustum, which you ' ll see how to create next.
The Frustum Class
Imagine sitting in front of a computer screen and seeing four lines coming from your
eyeball and intersecting with the corners of the screen. For the sake of simplicity, I
ll
assume you have only one eyeball in the center of your head. These lines continue
into the 3D world of your favorite game. You have a pyramid shape with the point
at your eyeball and its base somewhere out in infinity. Clip the pointy end of the
pyramid with the plane of your computer screen and form a base of your pyramid
at some arbitrary place in the distance. This odd clipped pyramid shape is called
the viewing frustum, as shown in Figure 14.13. The shape is actually a cuboid, since
it is topologically equivalent to a cube, although pushed out of shape. This shape is
what defines the total viewing area of a camera in a 3D game. Any object completely
'
 
Search WWH ::




Custom Search