bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.36k stars 272 forks source link

Convex shape zoo #8

Closed RossNordby closed 5 years ago

RossNordby commented 6 years ago

At the time of writing, testing focuses on spheres for simplicity while getting all the core systems up and running. But games need more than spheres.

In rough order of priority, the engine needs:

  1. Spheres
  2. Boxes
  3. Capsules
  4. Convex hulls
  5. Triangles (though only as a part of other group types, like meshes; pretty sure no one ever used v1's TriangleShape by itself)
  6. Cylinders
  7. Cones

Convex hulls will be by far the most difficult of the bunch. All of their collision pairs are pretty complicated and don't SIMDify easily.

And an important note: we are avoiding the use of GJK/MPR/EPA for narrow phase collision detection across the board. While they work reasonably well, they come with too many implicit requirements and tuning knobs that trip people up. Dozens of pair types will be required.

RossNordby commented 6 years ago

Strongly consider leaving cylinders and cones out of the first v2 release. Reasoning:

  1. Cuts convex pair zoo from 28 to 15.
  2. Cylinders and cones are quite a bit rarer in practice compared to other shapes.
  3. Their implementations are very complicated compared to the sphere/capsule pairs.
  4. Convex hulls can approximate them. (They'll probably be much slower, though.)
  5. Value in earlier 'stable' release, plus we need to be pruning not-strictly-necessary features due to time constraints over the next several months.
RossNordby commented 6 years ago

Spheres, boxes, and capsules are implemented in the alpha.

Cylinder priority should actually be pretty high, given that wheels are a thing. Convex hulls likely more important, still.

Alan-FGR commented 5 years ago

Lol, I came here to discuss whether cylinders and cones are even worth implementing since I've seen that in the Readme.md, but I see that got some thought already. I personally don't think they're worth implementing tbh, of course wheels are a thing, but most games just emulate wheels anyway, collision using a cylinder shape certainly would be more accurate than the typical 'single raycast' approach, but that can be improved, and also a naive implementation with a cylinder and coloumb friction model isn't perfect too. In any case, vehicles in special aren't an easy thing to achieve... you simply can't just naively attach cylinders to some chassis and hope that's going to work, you need to simulate stabilization bars too. Have you thought about a vehicle SDK like PhysX?

RossNordby commented 5 years ago

It's true that cylinders aren't extremely high value in general, but there are two reasons I'd still like them in the first release:

  1. They would benefit the simulations I'm working on, which are the entire reason why v2 exists, and
  2. after 3 weeks of barely-failed attempts to come up with a GJK/MPR-beating approach, I've entered a duel of principle with cylinders- I must defeat them!

Have you thought about a vehicle SDK like PhysX?

v1 had a dedicated 'Vehicle' type that used ray or sweep tests for wheels plus its own constraints. I was never too happy with it due to the fundamentally nonphysical nature of the wheels, especially as I've gradually pushed for more and more interactive physicality in simulation.

It is possible to make a pretty decent constraints+physical wheels car- v1 has a few demos showing some options including a sway bar if I remember correctly. Similar approaches in v2 would be much faster and also more stable, so the need for a dedicated vehicle type with proper engine simulation and tire friction modelling is limited to high fidelity racing simulators- which I'm not making.

(To anyone that is interested in making a high fidelity racing sim in v2, I'd recommend creating custom constraints as needed rather than trying to create an entirely special-cased system. Updating at 600+ hz is often feasible, too.)

Alan-FGR commented 5 years ago

Those are definitely two great reasons to implement cylinders. Also, it's good to know you're actually using Bepu 2 in your projects as opposed to just solving problems that don't exist for people who might eventually have them. I've seen plenty of projects, most notably game engines fail/die because they didn't have a game to drive development and just tried to solve general problems nobody really was having. Keep up the incredibly good work! Bepu 2 is very promising and overall it's the best example of high-performance modern C# code I know of.

RossNordby commented 5 years ago

Cylinders (and convex hulls) have been defeated. Cones won't be in the release and aren't on any near term roadmaps.

Also,

Convex hulls will be by far the most difficult of the bunch

was a silly thing to say.