-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Support transforming bounding volumes #11681
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
Support transforming bounding volumes #11681
Conversation
Co-authored-by: Mateusz Wachowiak <[email protected]>
…/bevy into bounding-transformations
I changed it so that the rotation methods also rotate the centers of bounding volumes around the origin. This is important when you have e.g. a local AABB of a collider that is offset, and need to transform the AABB to match the collider's global pose. This is also what Parry does. |
adding rotation to something called "axis aligned" feel strange to me |
For prior art, this is Parry's equivalent: https://docs.rs/parry3d/latest/parry3d/bounding_volume/struct.Aabb.html#method.transform_by There are cases where AABBs are stored in local space and then transformed into world space, which requires computing the rotated version of the AABB. It's not computing the actual OBB (Oriented Bounding Box) but the AABB of the rotated shape. I agree rotation might not be the best term, but I'm not sure what a better name would be. |
This feels more like a We could call this |
It's not necessarily a sweep or revolve in the sense that if you rotated a uniform AABB 90 degrees, it would be the same as the original AABB, not some AABB that contains all of the "swept" space. It's essentially just a merged version of the original AABB and the "rotated" one. |
If it was |
Okay, noted. Hmm, not quite correct either then. I'm fine to just follow parry's naming for now. |
Some more prior art in terms of naming and why we even need bounding volume transformations like these. Quotes from Christer Ericson's famous book Real-Time Collision Detection (chapters 4.1 and 4.2):
We could also remove the separate rotation and translation methods and only keep Even more prior art: |
The bounding boxes remain axis-aligned after rotation/transformation, right? Docs need to state that much more clearly. Otherwise seems useful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is well motivated and matches the implementation in parry. I agree the naming is confusing but it conforms with standard practice and the docs clarify things further.
Looks good for merge, but I do have a non-blocking question about intended use. rotate_by
appears to be non-decreasing in volume. Do repeated rotations by pi/4 cause the box extents to grow monotonically? How do you avoid arbitrarily large bounding boxes after repeated transformations?
Yes.
The idea here is that we store the AABB in local space and only rotate that every time. From Real-Time Collision Detection, chapter 4.2.6:
|
That makes sense. I would love it if you could work that into the docs somewhere (unless it already is and I missed it). Edit for clarity: Specifically the bit about it only producing an "approximate" bounding box, and it usually not being good practice to rotate the same box multiple times. |
Added a mention of how rotation can result in the AABB not being as tightly fitting, and how you should avoid successive rotations to the same AABB. This only really applies to axis-aligned volumes, so I didn't add this on the |
Looks great! Could we get that note added to the 3d bounds as well? This is looking really really solid. |
Dunno how I missed that... That's what I get for writing docs at midnight 😅 Made a quick PR to add the note for |
# Objective Make it straightforward to translate and rotate bounding volumes. ## Solution Add `translate_by`/`translated_by`, `rotate_by`/`rotated_by`, `transform_by`/`transformed_by` methods to the `BoundingVolume` trait. This follows the naming used for mesh transformations (see bevyengine#11454 and bevyengine#11675). --- ## Changelog - Added `translate_by`/`translated_by`, `rotate_by`/`rotated_by`, `transform_by`/`transformed_by` methods to the `BoundingVolume` trait and implemented them for the bounding volumes - Renamed `Position` associated type to `Translation` --------- Co-authored-by: Mateusz Wachowiak <[email protected]>
# Objective Fixes bevyengine#12310. bevyengine#11681 added transformations for bounding volumes, but I accidentally only added a note in the docs about repeated rotations for `Aabb2d` and not `Aabb3d`. ## Solution Copy the docs over to `Aabb3d`.
# Objective Make it straightforward to translate and rotate bounding volumes. ## Solution Add `translate_by`/`translated_by`, `rotate_by`/`rotated_by`, `transform_by`/`transformed_by` methods to the `BoundingVolume` trait. This follows the naming used for mesh transformations (see bevyengine#11454 and bevyengine#11675). --- ## Changelog - Added `translate_by`/`translated_by`, `rotate_by`/`rotated_by`, `transform_by`/`transformed_by` methods to the `BoundingVolume` trait and implemented them for the bounding volumes - Renamed `Position` associated type to `Translation` --------- Co-authored-by: Mateusz Wachowiak <[email protected]>
Objective
Make it straightforward to translate and rotate bounding volumes.
Solution
Add
translate_by
/translated_by
,rotate_by
/rotated_by
,transform_by
/transformed_by
methods to theBoundingVolume
trait. This follows the naming used for mesh transformations (see #11454 and #11675).Changelog
translate_by
/translated_by
,rotate_by
/rotated_by
,transform_by
/transformed_by
methods to theBoundingVolume
trait and implemented them for the bounding volumesPosition
associated type toTranslation