Game Development Reference
In-Depth Information
float b = 2.0f * D3DXVec3Dot(&ray->_direction, &v);
float c = D3DXVec3Dot(&v, &v) - (sphere->_radius * sphere->
_radius);
// find the discriminant
float discriminant = (b * b) - (4.0f * c);
// test for imaginary number
if( discriminant < 0.0f )
return false;
discriminant = sqrtf(discriminant);
float s0 = (-b + discriminant) / 2.0f;
float s1 = (-b - discriminant) / 2.0f;
// if a solution is >= 0, then we intersected the sphere
if( s0 >= 0.0f || s1 >= 0.0f )
return true;
return false;
}
Of course, we have seen BoundingSphere already, but for conve-
nience we show its definition again here:
struct BoundingSphere
{
BoundingSphere();
D3DXVECTOR3 _center;
float
_radius;
};
15.5 Sample Application: Picking
Figure 15.5:
Screen shot of this
chapter's sample
Team-Fly ®
Search WWH ::




Custom Search