Ray-Plane intersection
Hello
For my collision detection routine (for detecting collision of a ray with the world polys), this is what I do:
1) check if the ray crosses the plane of the poly
2) if so work out the intersection point
3) work out a plane equation for each edge of the poly and check to see if the intersection point lies in front of all of them
now the slowest part of this process is where i work out the intersection point. Here is the method I use:
sVector3D dir;
float n, d, length;
sVector3D_Subtract (end, start, &dir);
sVector3D_Normalize (&dir);
//work out a normalized vector in the direction start to end
//a bit of algebra to work out how much we need to scale
//this direction vector to get to the plane
n = -((polyplane.Normal.x*start->x ) + (polyplane.Normal.y*start->y) + (polyplane.Normal.z*start->z) + polyplane.Dist);
d = (polyplane.Normal.x*dir.x) + (polyplane.Normal.y*dir.y) + (polyplane.Normal.z*dir.z);
length = n/d;
sVector3D_Scale (&dir, length);
impact.x = start->x + dir.x;
impact.y = start->y + dir.y;
impact.z = start->z + dir.z;
It looks complicated but comes from a simple substituting and rearranging the plane equation. Now I know there has to be a faster method to calculate this intersection point. Can anyone help me with it?
Thanks
I think probably the best way to optimise collision detection is to make sure you only check collision against as few polygons as possible.
Use some sort of space partitioning algorithm (BSP, octree?) to quickly reject all the polygons in the area apart from those near to the player.
If you''re already doing this, then just ignore me.
Use some sort of space partitioning algorithm (BSP, octree?) to quickly reject all the polygons in the area apart from those near to the player.
If you''re already doing this, then just ignore me.
Yes your are right. At the moment I am working on collision with the terrain. I can check about 2000 polys without noticing any preformance hit, however normally I find only the polygons which are along the ray, and use them for checking. I''ll be using a BSP later for my indoor stuff.
Still I''m interested to know if it is possible speed up my interesection point finding algorithm. Your code can never be to fast
Thanks for the reply
Still I''m interested to know if it is possible speed up my interesection point finding algorithm. Your code can never be to fast

Thanks for the reply
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement