Game Development Reference
In-Depth Information
// p0/q0 are the spheres last frame
// p1/q1 are the spheres this frame
function SweptSphere( BoundingSphere p0, Boundin-
gSphere q0,
BoundingSphere p1, Boundin-
gSphere q1)
// First calculate v vectors for parametric
equations
Vector3 vp = p1 . center - p0 . center
Vector3 vq = q1 . center - q0 . center
// Calculate A and B
// A = P0 - Q0
Vector3 A = p0 . center - q0 . center
// B = vp - vq
Vector3 B = vp - vq
// Calculate a, b, and c
// a = B dot B
float a = DotProduct( B , B )
// b = 2(A dot B)
float b = 2 * (DotProduct( A , B )
// c = (A dot A) - (rp + rq) * (rp + rq)
float c = DotProduct( A , A ) - (( q0 . radius +
p0 . radius ) *
( q0 . radius +
p0 . radius ))
// Now calculate the discriminant (b^2 - 4ac)
float disc = b * b - 4 * a * c
if disc >= 0
// If we needed the value of t, we could cal-
culate it with:
// t = (-b - sqrt(disc)) / (2a)
// However, this simplified function just re-
turns true to say
// than an intersection occurred.
return true
Search WWH ::




Custom Search