dimforge / parry

2D and 3D collision-detection library for Rust.
https://parry.rs
Apache License 2.0
555 stars 96 forks source link

SharedShape 2D convex decomposition produces bad results if polygon is clockwise #55

Closed xlambein closed 2 years ago

xlambein commented 2 years ago

Hi!

I don't know whether this is a bug or a problem in the docs, but if you do a convex decomposition with a clockwise polygon, each shape in the decomposition will also be clockwise, and therefore will not work properly with SharedShape::convex_polyline. In turn, this means that the resulting compound shape will not work as expected.

https://github.com/dimforge/parry/blob/d4b01c50af4f951163407bb94a8e884816ea3c4a/src/shape/shared_shape.rs#L200-L208

The docs for SharedShape::convex_decomposition don't mention that shapes have to be counter-clockwise, and neither do the user guides. Similarly, the docs for SharedShape::convex_polyline don't mention that either, and it's only when looking at ConvexPolygon::from_convex_polyline that the counter-clockwise condition is ever mentioned.

Thanks for the amazing engine btw :-) people who played my LDJam game kept saying they were impressed by the physics, for which y'all are 100% responsible.

sebcrozet commented 2 years ago

Hi! Could you please try again with the master branch? It should be fixed by a recent PR (https://github.com/dimforge/parry/pull/53), but a new version of parry including this fix hasn’t been released yet.

xlambein commented 2 years ago

Ah sorry, I looked up the problem but only in issues, not in PRs! I'll try it out.

There's still the (small) detail about the docs for SharedShape::convex_polyline, but not sure it's worth keeping the issue open for that?

sebcrozet commented 2 years ago

Mmh, you are correct, the docs should be made more precise about the expected orientation!

but not sure it's worth keeping the issue open for that?

Let’s make another issue with a more suited title for that.

xlambein commented 2 years ago

Cool, I'll do that if you want :-)