Ncollide – 2D and 3D collision detection library
ncollide.org
ncollide.org
It looks interesting but what makes this library any better than what's come before? Why should I learn Rust to use it or really for any computational geometry problem?
Ehhh, I haven't seen a really good, super robust solution for mesh vs. mesh. Deciding whether two meshes collide is simple enough, but robustly pulling out associated information like overlap volumes, penetration depths, etc gets pretty hairy pretty quickly - you start running into similar problems to mesh booleans.
Or, alternatively, the reason why mesh vs mesh is never used in video games is that it hasn't been solved well yet and we have to stick to simplified collision geometry and the resulting glitches we get in games?
Maybe I am just a web programmer who is really bad at math and programming but this seems like a crazy thing to rewrite for many projects. Even if it only takes a day or an afternoon that is time you could have spent proving if your idea works.
I struggled so long and basically put my hobby game on ice after failing to sort out capsule plane collisions! :(
What language is your own library in?
Capsule-plane collisions are pretty simple, simple enough that I can outline here. The first thing you want to do is find the sphere on the capsule to perform the test on, call this time t_X. Create a line from the segment (starts at t_0, ends at t_1) bounding the capsule and determine its intersection point with the plane. If there is no intersection, just set t_x to mean(t_0, t_1), or halfway on the capsule's segment. If there is an intersection, and the time is between t_0 and t_1, set t_x to that time. Otherwise clamp it between t_0 and t_1. Now you have a sphere and a position (the time t_x on the capsule segment), and you can perform a moving sphere - plane collision. This algorithm works because the premise - the point on a capsule closest to a plane will always get closer to the plane, unless the capsule is moving away - is sound, as far as I can tell.
It was specifically capsule/triangle collision I got stuck on.
I had reasoned that with just capsule triangle I could do a 3D platform game on a mesh. However, I kept getting very wrong bounces off of edges.
And blog about the collision detection in general.
Not just for me, for the next hobby coder bumping into this.
What if the capsule is spinning like a boomerang while moving toward the plane?
I notice that they have decomposition of non-convex objects into a union of convex objects. That's very useful. Convex polyhedron vs convex polyhedron is very fast, only slightly worse that constant time for repeated tests on moving objects. (GJK is the preferred convex vs convex test.)
Mesh vs mesh is generally slow, although there are "polygon soup" systems that just compare triangles and understand no higher structure. Meshes are not necessarily solids; collision detection is better for things which are definitely solids. Other objects vs. height field is very useful in games; that's what you use for terrain.
Collision detection which drives a non-trivial physics system has to have certain properties. It helps a lot if the forces are differentiable against object movement. If there are infinitesimal movements which result in discontinuous changes in forces, physics models won't work right. This causes such artifacts as objects lying on the ground which vibrate. The closest point vector is shifting from corner to corner as two planes come into parallelism. It's static indeterminism in action. The solution is a multi-point contact model, where you have several closest point vectors with distances, and compute forces for each point of support. If you have at least three, stability is possible. If you're working on legged locomotion, and care about foot/ground contact and friction, you need that.
Ncollide's videos look good. Although check the first one where the balls fall into a cone. At the top, there's one ball perched stably on top of another ball.
I used to do this stuff.[1]
[1] https://news.ycombinator.com/item?id=11359181https://news.yc...
There are models of non-smooth interactions that get used in mechanics, graphics, and robotics - I'm thinking Baraff and Moreau and Stewart and Trinkle type stuff. You end up with dynamics formulated as differential inclusions, but it all still works out.
https://doc.rust-lang.org/book/ffi.html#calling-rust-code-fr...