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

Explanation use of property group #80

Closed
gregmax17 opened this issue Jul 20, 2024 · 12 comments
Closed

Explanation use of property group #80

gregmax17 opened this issue Jul 20, 2024 · 12 comments
Labels
question Further information is requested

Comments

@gregmax17
Copy link
Contributor

Can you provide more info on how the collision filtering works with the group property, is more for our use or is it used internally?

@Prozi
Copy link
Owner

Prozi commented Jul 24, 2024

for your use. will explain shortly. for now refer to demo stress test @gregmax17

@RedPhoenixQ
Copy link
Contributor

I read through the code and will give an explanation to the best of my understanding.

It appears to only be used by the canInteract function. Is like a double bitmask where the top 16 bits are the groups that it can interact with and the bottom 16 are the groups it belongs to. Bodies with the same group number will always be able to interact.

The predefined groups use less than the first 8 bits so the upper 8 bits out of the lower 16 should probably be used for custom groups, 0b00000001 << 16 to 0b10000000 << 16.

  • Predefined groups:
    • 0b00000000_00000000_00000000_00111111
  • Candidates for custom groups:
    • 0b00000000_00000000_11111111_11000000
  • "canInteract"-flags (corresponding to the group_value << 16):
    • 0b11111111_11111111_00000000_00000000

Example:

  • Body 1
    • 0b00000000_00000000_00000001_00000000
  • Body 2
    • 0b11111111_11111111_00000011_00000000
  • Body 3
    • 0b00000010_00000000_00000100_00000000

Body 1 has the first custom group but cannot interact with any other groups except itself because the first 16 bits are all zeros, only bodies with an identical value can interact with it.
Body 2 has the first and second group and can interact with all other custom groups , but only if that body also can interact with is custom group.
Body 3 has the third group but can interact with the second group.
This means that Body 2 and Body 3 can interact with each other but no other body can interact with Body 1 because it doesn't allow interactions with any other custom group.

@RedPhoenixQ
Copy link
Contributor

@Prozi If you would like I could make a PR with this documentation added to the group property and the canInteract function with a simple version of this explanation, mainly this part:

  • Predefined groups:
    • 0b00000000_00000000_00000000_00111111
  • Candidates for custom groups:
    • 0b00000000_00000000_11111111_11000000
  • "canInteract"-flags (corresponding to the group_value << 16):
    • 0b11111111_11111111_00000000_00000000

@noih
Copy link
Contributor

noih commented Aug 13, 2024

The concept of group comes from Box2D's filtering. Here are two links, hope they're helpful.

Box2D Doc (Box2D > Simulation > Shapes > Filtering)
Box2D Tutorial: Collision filtering

@Prozi
Copy link
Owner

Prozi commented Aug 22, 2024

@Prozi If you would like I could make a PR with this documentation added to the group property and the canInteract function with a simple version of this explanation, mainly this part:

  • Predefined groups:

    • 0b00000000_00000000_00000000_00111111
  • Candidates for custom groups:

    • 0b00000000_00000000_11111111_11000000
  • "canInteract"-flags (corresponding to the group_value << 16):

    • 0b11111111_11111111_00000000_00000000

I always love contributions and merge requests so please do

@Prozi
Copy link
Owner

Prozi commented Aug 22, 2024

The concept of group comes from Box2D's filtering. Here are two links, hope they're helpful.

Box2D Doc (Box2D > Simulation > Shapes > Filtering) Box2D Tutorial: Collision filtering

Thank you for the links

@RedPhoenixQ if you could someway include both of those as also references for docs please do

I think if I recall correctly @noih is the author of those group functions in detect-collisions

Thank you both for using our great library!

@Prozi
Copy link
Owner

Prozi commented Sep 5, 2024

@Prozi If you would like I could make a PR with this documentation added to the group property and the canInteract function with a simple version of this explanation, mainly this part:

  • Predefined groups:

    • 0b00000000_00000000_00000000_00111111
  • Candidates for custom groups:

    • 0b00000000_00000000_11111111_11000000
  • "canInteract"-flags (corresponding to the group_value << 16):

    • 0b11111111_11111111_00000000_00000000

@RedPhoenixQ any update on that PR please?

@gregmax17
Copy link
Contributor Author

I'm anxious and excited for collision filtering like this. It would be really helpful!

RedPhoenixQ added a commit to RedPhoenixQ/detect-collisions that referenced this issue Sep 25, 2024
@RedPhoenixQ
Copy link
Contributor

@Prozi sorry for the long pause without response. I've made a PR now

Prozi pushed a commit that referenced this issue Oct 3, 2024
* docs: add documentation for groups

Refs: #80

* docs: don't overwrite docs for group in bodies

Having a doc comment on the getter will have priority over the docs
provided in the BodyOptions interface
@Prozi Prozi added the question Further information is requested label Oct 3, 2024
@Prozi
Copy link
Owner

Prozi commented Oct 3, 2024

thank you very much @RedPhoenixQ

your mr was really good

I ran all the precommit scripts on it and published it here (and on npm)

https://github.com/Prozi/detect-collisions/releases/tag/v9.17.0

@gregmax17 can we close this now if the link above is explaining ok?

@gregmax17
Copy link
Contributor Author

Thank you!

@Prozi
Copy link
Owner

Prozi commented Oct 11, 2024

yay! @gregmax17 closing as resolved

@Prozi Prozi closed this as completed Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants