float radius = 10;
float distS = plane.GetDistance(org);
float distD = plane.GetDistance(dest);
vector3 ray = dest - org;
ray.normalize();
if(distS == distD)
continue;
// either we are hitting the plane either we crossed it.
if( (fabs(distD) < radius) ||
(distS>0 && distD<0) ||
(distS<0 && distD>0))
{
// Get intersection point on the plane.
vector3 intersection = org + ray*distS;
// Check if the intersection is within the triangle
vector3 edge1 = pt2-pt1;
vector3 norm1 = CrossProduct(edge1,plane.normal);
norm1.normalize();
Plane plane1(norm1,pt1);
if(plane1.GetSide(pt3) == Plane::POSITIVE_SIDE)
{
plane1.normal = -plane1.normal;
}
float dist1 = plane1.GetDistance(intersection);
if(dist1 > radius)
continue;
vector3 edge2 = pt3-pt2;
vector3 norm2 = CrossProduct(edge2,plane.normal);
norm2.normalize();
Plane plane2(norm2,pt2);
if(plane2.GetSide(pt1) == Plane::POSITIVE_SIDE)
{
plane2.normal = -plane2.normal;
}
float dist2 = plane2.GetDistance(intersection);
if(dist2 > radius)
continue;
vector3 edge3 = pt1-pt3;
vector3 norm3 = CrossProduct(edge3,plane.normal);
norm3.normalize();
Plane plane3(norm3,pt3);
if(plane3.GetSide(pt2) == Plane::POSITIVE_SIDE)
{
plane3.normal = -plane3.normal;
}
float dist3 = plane3.GetDistance(intersection);
if(dist3 > radius)
continue;
// Our ray intersect the triangle
sphere triangle collision detecion
Hi, I am trying to do a sphere triangle collision detection using the following steps, but something is wrong.
- Compute the distance from source/dest point to the plane.
- Check if a collision with the plane has occured
- Find the intersection point (of the ray) on the plane
- Build up the 3 edge plane
- Check if the sphere is within the 3 planes
Maybe the logic is just wrong, any suggestion ?
Edited by - eweber on March 31, 2002 2:55:59 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement