# Sphere-Mesh Collision Detection and Response

This topic is 4101 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
1) the 'distance' algorithm should give you some more information than just the distance. Either the closest point on the triangle, or some simple way to calculate it (barycentric coordinates). When you get the closest point, that gives you the plane of collision as well (normal of plane is (position - closestPoint).Normalised()).

2) Typically, you have a velocity vector, and a different vector for the view direction. They are two different things most of the time. Think of the velocity vector the direction of the body, and the camera direction the view direction.

Look at this from Telemachos for swept ellipsoid / triangle collision (even though I think the algorithm is flawed).

I have a demo as well, but it's not using swept test.

##### Share on other sites
Thank you for helping! I know this site, and I keep trying to learn, but could somebody tell me, what is pOrigin in this function (found on the website Oliii linked)? I think it is a point that lies on the plane. And could somebody explain what is going on at the dot products? I don't know what the first and second dot products do, but the third calculates the cos of the angle of the plane and the ray.

double intersectRayPlane(D3DVECTOR rOrigin, D3DVECTOR rVector, D3DVECTOR pOrigin, D3DVECTOR pNormal) {

double d = - (dot(pNormal,pOrigin));
double numer = dot(pNormal,rOrigin) + d;
double denom = dot(pNormal,rVector);

if (denom == 0) // normal is orthogonal to vector, cant intersect
return (-1.0f);
return -(numer / denom);
}

##### Share on other sites
pOrigin is any point on the plane (i.e. a vertex of the triangle).

The ray-plane equation is a basic linear equation solving.

ray : P = C + V * t (C = centre of sphere, V = velocity).
plane eq : (C-P).N = 0 (P is a point on plane, your pOrigin).
solve eqaution for t

((C-P).N + V.N * t) = 0
t = ((C-P).N) / (V.N)

##### Share on other sites
Oh my god! I made it! Collision detection and response are working even if I don't understand the half of it, because I was just copying. Don't misunderstand me, I'm going to learn the functions tomorrow, but I had to try it if it was working for me. So cooooooool :) Thank you very much for the link and for helping! I'll write if I don't know something. :]

no problemo :)

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013596
×