Game Development Reference
In-Depth Information
Figure 8-7. Particle-to-obstacle collision
We'll calculate s for each particle against each obstacle to determine contact or pene‐
tration. If we find either, then we'll perform the relative velocity check in the same
manner we did for particle-to-ground collisions to see if the particle is moving toward
the obstacle. If it is, then we have a collision and we'll back up the particle along the
collision normal vector line of action, which is simply the line connecting the centers
of the particle and the obstacle. We'll also compute the impact force like we did earlier
and let the integrator take care of the rest.
OK, now let's look at the new code in CheckForCollisions :
bool CheckForCollisions(Particle* p)
{
.
.
.
// Check for collisions with obstacles
float r;
Vector d;
float s;
for(i=0; i<_NUM_OBSTACLES; i++)
{
r = p->fRadius + Obstacles[i].fRadius;
d = p->vPosition - Obstacles[i].vPosition;
s = d.Magnitude() - r;
 
Search Nedrilad ::




Custom Search