dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.77k stars 235 forks source link

Feature: Rotation visualization for Ball 2d collider in debug mode #657

Closed rsk700 closed 3 days ago

rsk700 commented 2 weeks ago

Ball 2d collider requires some type of visualization in debug mode for rotations, as it is not possible to see rotations from collider shape itself, here is example I quick hacked:

https://github.com/dimforge/rapier/assets/816292/7156eab0-587a-4ab2-9971-43ca81220a33

I've added radius line in render_shape, but it doesn't look like this debug visualization belongs this function, if it is ok, I can submit patch:

TypedShape::Ball(s) => {
                let vtx = &self.instances[&TypeId::of::<Ball>()];
                backend.draw_line_strip(
                    object,
                    vtx,
                    pos,
                    &Vector::repeat(s.radius * 2.0),
                    color,
                    true,
                );
                backend.draw_line(
                    object,
                    pos * Point::new(s.radius * 0.2, 0.0),
                    pos * Point::new(s.radius * 0.8, 0.0),
                    color,
                )
            }
Vrixyz commented 2 weeks ago

Thanks for the suggestion ! In order to validate a path to implementation, I'd like to discuss current behaviour:

Currently, the testbed demo 2d in javascript provides a rotation gizmo, but I'm not sure where this is originating from, as it's the only example having such debug info 🤔 .

collision groups example

Screenshot 2024-06-18 at 10 47 43

rsk700 commented 2 weeks ago

Your are right, there is already rotation gizmo implemented in debug renderer https://docs.rs/rapier2d/latest/rapier2d/pipeline/struct.DebugRenderMode.html#associatedconstant.RIGID_BODY_AXES

But it looks like api to set flag is not exposes in TestbedApp, flag hard coded here in resource to bevy app: https://github.com/dimforge/rapier/blob/master/src_testbed/debug_render.rs#L25

and there is no way to change it because resource is private for testbed crate, so question now how to expose those flags to user?

btw I don't see v0.20.0 tag, it looks like it is not tagged in repository, v0.19.0 is the last tag

Vrixyz commented 2 weeks ago

Thanks for sharing your investigation, that helps! Right now I'm not sure either about how to expose it 😅, I might have ideas when I'll have encountered this codebase more.

I added the tag https://github.com/dimforge/rapier/releases/tag/v0.20.0.

Vrixyz commented 1 week ago

Your suggested patch is fine to me ! It's useful and discreet enough 👍 .

As you volunteered to submit a pull request I'm encouraging you to do so, otherwise I'll adopt it 😄

I'd welcome a comment like "// Draw a line to visualize rotation", because as you noticed this render would have a slightly different behaviour than the others.