Collision System

Started by
0 comments, last by cippyboy 20 years, 4 months ago
I don`t know if this may be a new collision system but I would want to know if someone came up with this earlier and already has something huge build upon it. So the algorithm would sound like this->sphere to sphere collision(with the radius) based upon a contact object(sphere 1) and the triangle (sphere 2). Sphere 2 would be Computed out of the G of triangle as center and the distance to any vertex as the radius...

//Sphere1 is predefinable

Sphere2.Center=Triangle.Center;
Sphere2.Radius=Triangle.Vertex[0]-Triangle.Center;

float Dist=Vector3(Sphere2.Center-Sphere1.Center).length();
float rads=Sphere1.Radius+Sphere2.Radius;
if (Dist<rads) {//we collided->Test succesufull

}
I think it should mostly work on surfaces wich have polys with the same sizes, or be equally distant to each other anyway it might prove faster than sometinng else... I`m gonna do a test in the future.

Relative Games - My apps

Advertisement
What code are you using that this is a usefull function. (just curious)

And: if Vector3(...).length() calculates the distance, you''d better just do this:
#define kwad(a) ((a)*(a))//Sphere1 is predefinableSphere2.Center=Triangle.Center;Sphere2.Radius=Triangle.Vertex[0]-Triangle.Center;float Dist=Vector3(Sphere2.Center-Sphere1.Center).lengthNOSQRT();float rads=kwad(Sphere1.Radius+Sphere2.Radius);if (Dist<rads) {//we collided->Test succesufull}

lengthNOSQRT() would return the distance variable before running the square root operation on it.
This way you won''t need the square root which is very expensive.
As you won''t need the exact distance (only if it''s more/less then the total radius) the result should be the same (even more precise).
- growl -

This topic is closed to new replies.

Advertisement