jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.46k stars 418 forks source link

[Feature Request] gjk treat quadratics as polyhedrons with convex radius #935

Closed ocohen closed 6 months ago

ocohen commented 7 months ago

Hi,

I'm hoping there's already a way to do this, but based on what I saw while debugging the ShapeCast code it looks like when sweeping a sphere the convex radius is 0, and the sphere's support function has the radius embedded in it.

When working on past engines we've seen great stability and perf improvements by treating the sphere (and capsule) as a point (line) with a convex radius as the radius.

Is this approach supported? It seems like it should be possible based on the convex radius variables passed around, but I was seeing them as 0 for the sphere. Maybe there's a different type of sphere I am missing?

Thanks for the great library

jrouwe commented 7 months ago

I think you're looking for ShapeCastSettings::mUseShrunkenShapeAndConvexRadius = true.

ocohen commented 7 months ago

Yes that's it, I figured there was a setting I was missing. Question - is there any reason why capsules and spheres don't always assume this is true? I get why you might not want this for convexes that have hard edges, but for quadratics is there a case where you don't want this?

jrouwe commented 7 months ago

I haven't run into the issues that you're talking about yet. It wouldn't be hard to change the behavior but then I would need to do some checking if there is indeed a quality / perf difference.

jrouwe commented 6 months ago

Hello, this is implemented now. In my tests it gave a significant performance boost.

ocohen commented 6 months ago

Awesome, I did something similar in our project (more hacky than yours) for spheres and capsules. Thanks for following up