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
Add axes_2d gizmo. #12334
base: main
Are you sure you want to change the base?
Add axes_2d gizmo. #12334
Changes from 2 commits
6fdc189
0dba551
345fedb
e8d66fa
2486977
a837a7f
2be1412
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -125,7 +125,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { | |||||||||
end: Vec2, | ||||||||||
color: impl Into<Color>, | ||||||||||
) -> ArrowBuilder<'_, 'w, 's, T> { | ||||||||||
self.arrow(start.extend(0.), end.extend(0.), color) | ||||||||||
let length = (end - start).length(); | ||||||||||
ArrowBuilder { | ||||||||||
gizmos: self, | ||||||||||
start: start.extend(0.), | ||||||||||
end: end.extend(0.), | ||||||||||
color: color.into(), | ||||||||||
tip_length: length / 10., | ||||||||||
} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to be consistent with the 3d arrow drawing method, but I realize now that was not a smart change. |
||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -163,3 +170,36 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { | |||||||||
self.arrow(start, end_z, BLUE); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should adress both methods in the same impl if possible and move this to the impl above this. |
||||||||||
/// Draw a set of axes local to the given transform (`transform`), with length scaled by a factor | ||||||||||
/// of `base_length`. | ||||||||||
/// | ||||||||||
/// This should be called for each frame the axes need to be rendered. | ||||||||||
/// | ||||||||||
/// # Example | ||||||||||
/// ``` | ||||||||||
/// # use bevy_gizmos::prelude::*; | ||||||||||
/// # use bevy_ecs::prelude::*; | ||||||||||
/// # use bevy_transform::components::Transform; | ||||||||||
/// # #[derive(Component)] | ||||||||||
/// # struct AxesComponent; | ||||||||||
/// fn draw_axes_2d( | ||||||||||
/// mut gizmos: Gizmos, | ||||||||||
/// query: Query<&Transform, With<AxesComponent>>, | ||||||||||
/// ) { | ||||||||||
/// for &transform in &query { | ||||||||||
/// gizmos.axes_2d(transform, 1.); | ||||||||||
/// } | ||||||||||
/// } | ||||||||||
/// # bevy_ecs::system::assert_is_system(draw_axes_2d); | ||||||||||
/// ``` | ||||||||||
pub fn axes_2d(&mut self, transform: impl TransformPoint, base_length: f32) { | ||||||||||
let start = transform.transform_point(Vec3::ZERO); | ||||||||||
let end_x = transform.transform_point(base_length * Vec3::X); | ||||||||||
let end_y = transform.transform_point(base_length * Vec3::Y); | ||||||||||
|
||||||||||
self.arrow_2d(start.into(), end_x.into(), RED); | ||||||||||
self.arrow_2d(start.into(), end_y.into(), GREEN); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and you'll need to import |
||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,8 @@ fn draw_example_collection( | |
Vec2::from_angle(sin / -10. + PI / 2.) * 50., | ||
YELLOW, | ||
); | ||
|
||
gizmos.axes_2d(Transform::from_translation(Vec3::new(sin, 0.0, 0.0)), 25.0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this example is already quite crowded. this will also put it on the grid gizmo already present, making it hard to read |
||
} | ||
|
||
fn update_config( | ||
|
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.
you should avoid changing this