From 84baf6c12552e6c202026109037956be60351bee Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Thu, 15 Feb 2024 23:43:17 -0300 Subject: [PATCH 01/14] [add] Added creation to another tip in arrows --- crates/bevy_gizmos/src/arrows.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/bevy_gizmos/src/arrows.rs b/crates/bevy_gizmos/src/arrows.rs index 541fc6edab79b..ed7a3d58709d1 100644 --- a/crates/bevy_gizmos/src/arrows.rs +++ b/crates/bevy_gizmos/src/arrows.rs @@ -13,6 +13,7 @@ pub struct ArrowBuilder<'a, 'w, 's, T: GizmoConfigGroup> { start: Vec3, end: Vec3, color: Color, + double_ended: bool, tip_length: f32, } @@ -35,6 +36,12 @@ impl ArrowBuilder<'_, '_, '_, T> { pub fn with_tip_length(&mut self, length: f32) { self.tip_length = length; } + + /// Adds another tip to the arrow, appended in the start point. + /// the default is only one tip at the end point. + pub fn with_double_end(&mut self) { + self.double_ended = true; + } } impl Drop for ArrowBuilder<'_, '_, '_, T> { @@ -47,8 +54,8 @@ impl Drop for ArrowBuilder<'_, '_, '_, T> { self.gizmos.line(self.start, self.end, self.color); // now the hard part is to draw the head in a sensible way // put us in a coordinate system where the arrow is pointing towards +x and ends at the origin - let pointing = (self.end - self.start).normalize(); - let rotation = Quat::from_rotation_arc(Vec3::X, pointing); + let pointing_end = (self.end - self.start).normalize(); + let rotation_end = Quat::from_rotation_arc(Vec3::X, pointing_end); let tips = [ Vec3::new(-1., 1., 0.), Vec3::new(-1., 0., 1.), @@ -58,11 +65,22 @@ impl Drop for ArrowBuilder<'_, '_, '_, T> { // - extend the vectors so their length is `tip_length` // - rotate the world so +x is facing in the same direction as the arrow // - translate over to the tip of the arrow - let tips = tips.map(|v| rotation * (v.normalize() * self.tip_length) + self.end); - for v in tips { + let tips_end = tips.map(|v| rotation_end * (v.normalize() * self.tip_length) + self.end); + for v in tips_end { // then actually draw the tips self.gizmos.line(self.end, v, self.color); } + // If this arrow is double ended, we draw the other head at the start point + if self.double_ended { + let pointing_start = (self.start - self.end).normalize(); + let rotation_start = Quat::from_rotation_arc(Vec3::X, pointing_start); + let tips_start = + tips.map(|v| rotation_start * (v.normalize() * self.tip_length) + self.start); + for v in tips_start { + // draw the start points tips + self.gizmos.line(self.start, v, self.color); + } + } } } @@ -88,6 +106,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { start, end, color, + double_ended: false, tip_length: length / 10., } } From 8c814459e3cd2396e5d63b7114fb09461a72d89a Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Thu, 15 Feb 2024 23:57:00 -0300 Subject: [PATCH 02/14] [add] Added new double ended arrow to the example --- examples/3d/3d_gizmos.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index a3805c12d9296..9469b63689eb3 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -191,6 +191,14 @@ fn draw_example_collection( .circle_segments(64); gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, Color::YELLOW); + + { + // We can create more complex arrows using the arror builder. + let mut arrow_builder = + gizmos.arrow(Vec3::ZERO, Vec3::from_array([-1.5, 1.5, 1.5]), Color::GREEN); + arrow_builder.with_double_end(); + arrow_builder.with_tip_length(0.5); + }; } fn draw_primitives( From c6b3c07ea5af6a09f3e34c4d0064fa49c4cc376e Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Fri, 16 Feb 2024 01:28:27 -0300 Subject: [PATCH 03/14] [add] Added new arrow to the gizmos 2d example --- examples/2d/2d_gizmos.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/2d/2d_gizmos.rs b/examples/2d/2d_gizmos.rs index 1e7129f51949f..0c00d7460635d 100644 --- a/examples/2d/2d_gizmos.rs +++ b/examples/2d/2d_gizmos.rs @@ -128,6 +128,14 @@ fn draw_example_collection( Vec2::from_angle(sin / -10. + PI / 2.) * 50., Color::YELLOW, ); + + { + // We can create more complex arrows using the arrow builder. + let mut arrow_builder = + gizmos.arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., Color::GREEN); + arrow_builder.with_double_end(); + arrow_builder.with_tip_length(10.); + }; } fn draw_primitives( From a78cd1b8ba7264b139e79457e83eee4b22bdb839 Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Fri, 16 Feb 2024 01:28:50 -0300 Subject: [PATCH 04/14] [doc] Fixed word in docs --- examples/3d/3d_gizmos.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index 9469b63689eb3..dc2f1644e0023 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -193,7 +193,7 @@ fn draw_example_collection( gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, Color::YELLOW); { - // We can create more complex arrows using the arror builder. + // We can create more complex arrows using the arrow builder. let mut arrow_builder = gizmos.arrow(Vec3::ZERO, Vec3::from_array([-1.5, 1.5, 1.5]), Color::GREEN); arrow_builder.with_double_end(); From c174dfcefc6ea00a02ac2a83f62b9fe57b46bf9f Mon Sep 17 00:00:00 2001 From: pablo-lua <126117294+pablo-lua@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:46:05 -0300 Subject: [PATCH 05/14] [style] Removed unnecessary code Co-authored-by: Afonso Lage --- examples/2d/2d_gizmos.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/2d/2d_gizmos.rs b/examples/2d/2d_gizmos.rs index 0c00d7460635d..ef963bcbdef44 100644 --- a/examples/2d/2d_gizmos.rs +++ b/examples/2d/2d_gizmos.rs @@ -129,13 +129,11 @@ fn draw_example_collection( Color::YELLOW, ); - { - // We can create more complex arrows using the arrow builder. - let mut arrow_builder = - gizmos.arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., Color::GREEN); - arrow_builder.with_double_end(); - arrow_builder.with_tip_length(10.); - }; + // You can create more complex arrows using the arrow builder. + let mut arrow_builder = + gizmos.arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., Color::GREEN); + arrow_builder.with_double_end(); + arrow_builder.with_tip_length(10.); } fn draw_primitives( From 8dfd3d1c23007e21fd78fa2da92c14787448600f Mon Sep 17 00:00:00 2001 From: pablo-lua <126117294+pablo-lua@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:47:59 -0300 Subject: [PATCH 06/14] [style] Remove unnecessary code in example Co-authored-by: Afonso Lage --- examples/3d/3d_gizmos.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index dc2f1644e0023..8b169bb5157ea 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -192,13 +192,11 @@ fn draw_example_collection( gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, Color::YELLOW); - { - // We can create more complex arrows using the arrow builder. - let mut arrow_builder = - gizmos.arrow(Vec3::ZERO, Vec3::from_array([-1.5, 1.5, 1.5]), Color::GREEN); - arrow_builder.with_double_end(); - arrow_builder.with_tip_length(0.5); - }; + // You can create more complex arrows using the arrow builder. + let mut arrow_builder = + gizmos.arrow(Vec3::ZERO, Vec3::from_array([-1.5, 1.5, 1.5]), Color::GREEN); + arrow_builder.with_double_end(); + arrow_builder.with_tip_length(0.5); } fn draw_primitives( From 59edb63dcfe1050fa3c63e80a97ccccfe0856a96 Mon Sep 17 00:00:00 2001 From: pablo-lua <126117294+pablo-lua@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:49:34 -0300 Subject: [PATCH 07/14] [rem] Remove unnecessary comment Co-authored-by: Afonso Lage --- crates/bevy_gizmos/src/arrows.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_gizmos/src/arrows.rs b/crates/bevy_gizmos/src/arrows.rs index ed7a3d58709d1..d9e03fbd70496 100644 --- a/crates/bevy_gizmos/src/arrows.rs +++ b/crates/bevy_gizmos/src/arrows.rs @@ -70,7 +70,6 @@ impl Drop for ArrowBuilder<'_, '_, '_, T> { // then actually draw the tips self.gizmos.line(self.end, v, self.color); } - // If this arrow is double ended, we draw the other head at the start point if self.double_ended { let pointing_start = (self.start - self.end).normalize(); let rotation_start = Quat::from_rotation_arc(Vec3::X, pointing_start); From eabf3af0e2860214be2171f01e1f2c989e6d6d28 Mon Sep 17 00:00:00 2001 From: Pablo Reinhardt Date: Fri, 16 Feb 2024 10:07:07 -0300 Subject: [PATCH 08/14] [alt] Changed arrow position and color --- examples/3d/3d_gizmos.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index 8b169bb5157ea..36a3a5e9691f5 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -194,7 +194,7 @@ fn draw_example_collection( // You can create more complex arrows using the arrow builder. let mut arrow_builder = - gizmos.arrow(Vec3::ZERO, Vec3::from_array([-1.5, 1.5, 1.5]), Color::GREEN); + gizmos.arrow(Vec3::from_array([2., 0., 2.]), Vec3::from_array([2., 2., 2.]), Color::ORANGE_RED); arrow_builder.with_double_end(); arrow_builder.with_tip_length(0.5); } From 65ee21ce5e98479ecf9b2391e91073dafe7b40d3 Mon Sep 17 00:00:00 2001 From: Pablo Reinhardt Date: Fri, 16 Feb 2024 10:13:47 -0300 Subject: [PATCH 09/14] [fix] Fix CI job error --- examples/3d/3d_gizmos.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index 36a3a5e9691f5..b3d3dbcee7c1f 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -193,8 +193,11 @@ fn draw_example_collection( gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, Color::YELLOW); // You can create more complex arrows using the arrow builder. - let mut arrow_builder = - gizmos.arrow(Vec3::from_array([2., 0., 2.]), Vec3::from_array([2., 2., 2.]), Color::ORANGE_RED); + let mut arrow_builder = gizmos.arrow( + Vec3::from_array([2., 0., 2.]), + Vec3::from_array([2., 2., 2.]), + Color::ORANGE_RED, + ); arrow_builder.with_double_end(); arrow_builder.with_tip_length(0.5); } From ef2ae1e2e69f2f929bd3d9e93ddd548c1b8f5146 Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Wed, 21 Feb 2024 20:18:55 -0300 Subject: [PATCH 10/14] [add] Added examples again --- examples/2d/2d_gizmos.rs | 0 examples/3d/3d_gizmos.rs | 0 examples/gizmos/2d_gizmos.rs | 6 ++++++ examples/gizmos/3d_gizmos.rs | 10 ++++++++++ 4 files changed, 16 insertions(+) delete mode 100644 examples/2d/2d_gizmos.rs delete mode 100644 examples/3d/3d_gizmos.rs diff --git a/examples/2d/2d_gizmos.rs b/examples/2d/2d_gizmos.rs deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/examples/gizmos/2d_gizmos.rs b/examples/gizmos/2d_gizmos.rs index fb414201edcf4..5505dc54b81d0 100644 --- a/examples/gizmos/2d_gizmos.rs +++ b/examples/gizmos/2d_gizmos.rs @@ -78,6 +78,12 @@ fn draw_example_collection( Vec2::from_angle(sin / -10. + PI / 2.) * 50., Color::YELLOW, ); + + // You can create more complex arrows using the arrow builder. + let mut arrow_builder = + gizmos.arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., Color::GREEN); + arrow_builder.with_double_end(); + arrow_builder.with_tip_length(10.); } fn update_config( diff --git a/examples/gizmos/3d_gizmos.rs b/examples/gizmos/3d_gizmos.rs index 543db056c43ed..e1387203f28d1 100644 --- a/examples/gizmos/3d_gizmos.rs +++ b/examples/gizmos/3d_gizmos.rs @@ -128,6 +128,16 @@ fn draw_example_collection( .circle_segments(64); gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, Color::YELLOW); + + + // You can create more complex arrows using the arrow builder. + let mut arrow_builder = gizmos.arrow( + Vec3::from_array([2., 0., 2.]), + Vec3::from_array([2., 2., 2.]), + Color::ORANGE_RED, + ); + arrow_builder.with_double_end(); + arrow_builder.with_tip_length(0.5); } fn update_config( From 25a30c4dc6c583322742bd0dce16e5f1da6d9cb8 Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Wed, 21 Feb 2024 20:30:39 -0300 Subject: [PATCH 11/14] [style] CI fix --- examples/gizmos/3d_gizmos.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/gizmos/3d_gizmos.rs b/examples/gizmos/3d_gizmos.rs index e1387203f28d1..b0c2dd261f6d7 100644 --- a/examples/gizmos/3d_gizmos.rs +++ b/examples/gizmos/3d_gizmos.rs @@ -129,7 +129,6 @@ fn draw_example_collection( gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, Color::YELLOW); - // You can create more complex arrows using the arrow builder. let mut arrow_builder = gizmos.arrow( Vec3::from_array([2., 0., 2.]), From 07068001aa12057eee1b2ba5baf77a0dc7412915 Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Fri, 1 Mar 2024 21:37:25 -0300 Subject: [PATCH 12/14] [alt] Changed some types and format --- crates/bevy_gizmos/src/arrows.rs | 3 ++- examples/gizmos/2d_gizmos.rs | 7 ++++--- examples/gizmos/3d_gizmos.rs | 15 ++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/bevy_gizmos/src/arrows.rs b/crates/bevy_gizmos/src/arrows.rs index 19af599cf11e5..dd333da129403 100644 --- a/crates/bevy_gizmos/src/arrows.rs +++ b/crates/bevy_gizmos/src/arrows.rs @@ -45,8 +45,9 @@ impl ArrowBuilder<'_, '_, '_, T> { /// Adds another tip to the arrow, appended in the start point. /// the default is only one tip at the end point. - pub fn with_double_end(&mut self) { + pub fn with_double_end(mut self) -> Self { self.double_ended = true; + self } } diff --git a/examples/gizmos/2d_gizmos.rs b/examples/gizmos/2d_gizmos.rs index 73a7314150cf4..3a2b757fd8781 100644 --- a/examples/gizmos/2d_gizmos.rs +++ b/examples/gizmos/2d_gizmos.rs @@ -89,9 +89,10 @@ fn draw_example_collection( ); // You can create more complex arrows using the arrow builder. - let mut arrow_builder = gizmos.arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN); - arrow_builder.with_double_end(); - arrow_builder.with_tip_length(10.); + gizmos + .arrow_2d(Vec2::ZERO, Vec2::from_angle(sin / -10.) * 50., GREEN) + .with_double_end() + .with_tip_length(10.); } fn update_config( diff --git a/examples/gizmos/3d_gizmos.rs b/examples/gizmos/3d_gizmos.rs index 127054ae7a697..aa48689be95dd 100644 --- a/examples/gizmos/3d_gizmos.rs +++ b/examples/gizmos/3d_gizmos.rs @@ -139,13 +139,14 @@ fn draw_example_collection( gizmos.arrow(Vec3::ZERO, Vec3::ONE * 1.5, YELLOW); // You can create more complex arrows using the arrow builder. - let mut arrow_builder = gizmos.arrow( - Vec3::from_array([2., 0., 2.]), - Vec3::from_array([2., 2., 2.]), - ORANGE_RED, - ); - arrow_builder.with_double_end(); - arrow_builder.with_tip_length(0.5); + gizmos + .arrow( + Vec3::from_array([2., 0., 2.]), + Vec3::from_array([2., 2., 2.]), + ORANGE_RED, + ) + .with_double_end() + .with_tip_length(0.5); } fn update_config( From f2e9d7331bbe4a5442482bebd9106129f28781ce Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Tue, 9 Apr 2024 20:07:43 -0300 Subject: [PATCH 13/14] [alt] Changed used creation method for Vec3 --- examples/gizmos/3d_gizmos.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gizmos/3d_gizmos.rs b/examples/gizmos/3d_gizmos.rs index 92d86bb297e8d..cf028296fbd69 100644 --- a/examples/gizmos/3d_gizmos.rs +++ b/examples/gizmos/3d_gizmos.rs @@ -140,8 +140,8 @@ fn draw_example_collection( // You can create more complex arrows using the arrow builder. gizmos .arrow( - Vec3::from_array([2., 0., 2.]), - Vec3::from_array([2., 2., 2.]), + Vec3::new(2., 0., 2.), + Vec3::new(2., 2., 2.), ORANGE_RED, ) .with_double_end() From 20a9b4ab015c197fd298eb2074977446ac81cb93 Mon Sep 17 00:00:00 2001 From: pablo-lua Date: Tue, 9 Apr 2024 20:11:00 -0300 Subject: [PATCH 14/14] [style] Cargo fmt --- examples/gizmos/3d_gizmos.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/gizmos/3d_gizmos.rs b/examples/gizmos/3d_gizmos.rs index cf028296fbd69..c7ff73ab50cd7 100644 --- a/examples/gizmos/3d_gizmos.rs +++ b/examples/gizmos/3d_gizmos.rs @@ -139,11 +139,7 @@ fn draw_example_collection( // You can create more complex arrows using the arrow builder. gizmos - .arrow( - Vec3::new(2., 0., 2.), - Vec3::new(2., 2., 2.), - ORANGE_RED, - ) + .arrow(Vec3::new(2., 0., 2.), Vec3::new(2., 2., 2.), ORANGE_RED) .with_double_end() .with_tip_length(0.5); }