Adding to Oskuro's post...
Given a point(sphere center + radius)
Use the plane equation to find the distance (Ax + By + Cz + D = 0) We want to find D.
So, we come up with D = -(Ax + By + Cz)
Basically, the negated dot product of the normal of the plane and the point.
normal is the triangle normal of the terrain and vpoint is your point to test.
1
| planeDistance = - ((normal.x * vpoint.x) + (normal.y * vpoint.y) + (normal.z * vpoint.z)) |
After finding the distance, you need to know what side of the triangle your point is.
We use the famous distance formula to find the distance the center point of the sphere is from the polygon's plane.
1
| distance = (vnormal.x * vcenter.x + vnormal.y * vcenter.y + vnormal.z * vcenter.z + planeDistance) |
where: vcenter is the center of the sphere.
Now check where the sphere lies in relation to the plane defined by your triangle...
If the absolute value of the distance we just found is less than the radius, the sphere intersected the plane.
1 2 3 4 5 6 7 8 9 10 11 12 13
| if( abs(distance) < radius ) { INTERSECTS } else if( abs(distance) >= radius ) { FRONT } else { BEHIND } |
Then just project the sphere's center to the plane and do your response.