Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounded Corners Rect support? #7

Open
lgxm3z opened this issue Sep 7, 2022 · 6 comments
Open

Rounded Corners Rect support? #7

lgxm3z opened this issue Sep 7, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@lgxm3z
Copy link

lgxm3z commented Sep 7, 2022

No description provided.

@lgxm3z lgxm3z changed the title Round Rect support? Rounded Corners Rect support? Sep 7, 2022
@isaac-mason
Copy link
Member

isaac-mason commented Sep 16, 2022

Can you share more about use cases for rounded rectangles?

Right now this could be approximated with a polygon, or (naively) created with a compound body.

If you're aware of any other 2d physics engines that have support for rounded rectangles, that would be useful for reference too.

@lgxm3z
Copy link
Author

lgxm3z commented Sep 17, 2022

@isaac-mason Well, it would practically work as a capsule...

It could be very useful for top down games, platform games or any other game that wants to have some shape variations giving a more "pixel perfect" impression.

image

@isaac-mason isaac-mason added the enhancement New feature or request label Sep 18, 2022
@isaac-mason
Copy link
Member

Thanks @runtothedoor.

I don't have time to drive implementation for this right now. If someone wants this and is willing to contribute some code, in the short term I can give guidance and help with reviews and testing. I might get some time for this in the coming months.

In the meantime, I'll leave this issue open. Feel free to share more about use cases, ideas for implementation, other physics libraries that support this shape, etc.

If it's useful, I can create some examples for how to approximate this shape too, let me know.

@lgxm3z
Copy link
Author

lgxm3z commented Sep 18, 2022

Thanks @runtothedoor.

I don't have time to drive implementation for this right now. If someone wants this and is willing to contribute some code, in the short term I can give guidance and help with reviews and testing. I might get some time for this in the coming months.

In the meantime, I'll leave this issue open. Feel free to share more about use cases, ideas for implementation, other physics libraries that support this shape, etc.

If it's useful, I can create some examples for how to approximate this shape too, let me know.

An approximate example of the shape would be perfect. Currently I don't have that much time available either but I will try to contribute to the implementation of this feature soon.

@isaac-mason
Copy link
Member

Okay great :)

I am away from home for a while, but putting together an example for this is on my to-do list for when I'm back.

@isaac-mason
Copy link
Member

isaac-mason commented Nov 21, 2022

The matter-js lib provides a utility that takes vertices for a polygon, and returns vertices with rounded corners, with configurable quality. See Vertices.chamfer in matter-js: https://github.com/liabru/matter-js/blob/e49834d1e0574348cea3edd4a06d60edf1a67fa0/src/geometry/Vertices.js#L270

A similar approach could be used in user-land with p2-es.

Having full support for rounded rects with their own narrowphases is a notable amount more work. The polygon approach likely covers 99% of use cases.

If there's interest, something similar could be added to p2-es.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants