Archived

This topic is now archived and is closed to further replies.

gamein

BSP / Sphere Collision

Recommended Posts

gamein    122
I have a BSP tree for my scene geometry (solid node based BSP -- not leafy) and I also have the ability to determine the line of sight between two points (ie. pretty much a ray/bsp collision function). My player is represented by a bounding sphere to account for the fact that he is a little larger than a single point Does anyone know how to calculate the collision between the polys of the BSP and the sphere representing the player? One more thing actually. I am also implementing a lightmapper. I was going to calculate the ray between the lumel and the light source and then use the line of sight test to see if the ray is blocked by some other triangle in the tree. The triangle must be facing the light source to be a blocker. Does this make any sense?

Share this post


Link to post
Share on other sites
LilBudyWizer    491
Perhaps not exactly what you are looking for, but that never stopped me...

    
bool TestSphere(Sphere sphere, Plane plane, Velocity W, float &T)
{
sdist = Dot(plane.N,sphere.C) - plane.d;
if (sdist > sphere.r)
{
dotNW = Dot(plane.N, W);
if (dotNW < 0)
{
T = (sphere.r - sdist)/dotNW;
return(true);
}
else
return(false);
}
else if (sdist < -sphere.r)
{
dotNW = Dot(plane.N, W);
if (dotNW > 0)
{
T = -(sphere.r - sdist)/dotNW;
return(true);
}
else
return(false);
}
else
{
T = 0;
return(true);
}
}


The function returns true if there is a collision and false if there is not. If there is a collision then T would be the time of first collision. Scaling the normal of the plane by the radius, reversing it and adding it to the center of the sphere at that time will give you a point of collision. Then you have to determine if that point is in any of the coplaner polygons for that node. Ok, so I don''t know what I''m talking about, but it sounds good. I copied it out of 3D Game Engine Design.

Share this post


Link to post
Share on other sites