Sign in to follow this  

Sphere-Mesh Collision Detection and Response

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! Sorry for opening the 202424th topic about collision detection, but I've looked around the other topics, and found not much useable stuff for me. So, I have a .3ds model and a camera with position, velocity vector and ellipsoid radius. I can convert every coordinate to ellipsoid space and vice-versa, not that is the problem, but detecting the collision and do response step for it. I've read LOTS of books/articles and other stuff about this, but because every article describes another solution for doing it, I couldn't understand everything. :S I know a few steps: 1. Convert every coordinate into ellipsoid space 2. Get the plane of each triangle in the mesh 3. If the distance between the triangle and the position is smaller than the radius, then it's collided. But how do I get the intersection point? What vector would I have to project onto the triangle plane for the response? Does the velocity vector point to my next position after the next step, or it points to my 'nose' (if I look up 90 degree, would it be on the top of my head?) ? What if I'm strafing? Please help! I've been trying to do this correctly for more than a year. :(

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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. :]

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this