Game Development Reference
In-Depth Information
constant is a small value we define such that we consider any number
smaller than it equal to zero. This is necessary because due to floating-
point imprecision, a number that should really be zero may be off
slightly. Thus, comparing it to zero would fail. We therefore test if a
floating-point variable is zero by testing if it's less than EPSILON . The
following function illustrates how EPSILON can be used to test if two
floating-point values are equal:
bool Equals(float lhs, float rhs)
{
// if lhs == rhs their difference should be zero
return fabs(lhs - rhs) < EPSILON ? true : false;
}
11.4.2 Bounding Volume Types
To facilitate work with bounding spheres and bounding volumes, it is
natural to implement classes representing each. We implement such
classes now in the d3d namespace:
struct BoundingBox
{
BoundingBox();
bool isPointInside(D3DXVECTOR3& p);
D3DXVECTOR3 _min;
D3DXVECTOR3 _max;
};
struct BoundingSphere
{
BoundingSphere();
D3DXVECTOR3 _center;
float
_radius;
};
d3d::BoundingBox::BoundingBox()
{
// infinite small bounding box
_min.x = d3d::INFINITY;
_min.y = d3d::INFINITY;
_min.z = d3d::INFINITY;
_max.x = -d3d::INFINITY;
_max.y = -d3d::INFINITY;
_max.z = -d3d::INFINITY;
}
bool d3d::BoundingBox::isPointInside(D3DXVECTOR3& p)
{
// is the point inside the bounding box?
if(p.x >= _min.x && p.y >= _min.y && p.z >= _min.z &&
Search WWH ::




Custom Search