@@ -17,6 +17,7 @@ pub struct ArrowBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
17
17
start : Vec3 ,
18
18
end : Vec3 ,
19
19
color : Color ,
20
+ double_ended : bool ,
20
21
tip_length : f32 ,
21
22
}
22
23
@@ -41,6 +42,13 @@ impl<T: GizmoConfigGroup> ArrowBuilder<'_, '_, '_, T> {
41
42
self . tip_length = length;
42
43
self
43
44
}
45
+
46
+ /// Adds another tip to the arrow, appended in the start point.
47
+ /// the default is only one tip at the end point.
48
+ pub fn with_double_end ( mut self ) -> Self {
49
+ self . double_ended = true ;
50
+ self
51
+ }
44
52
}
45
53
46
54
impl < T : GizmoConfigGroup > Drop for ArrowBuilder < ' _ , ' _ , ' _ , T > {
@@ -53,8 +61,8 @@ impl<T: GizmoConfigGroup> Drop for ArrowBuilder<'_, '_, '_, T> {
53
61
self . gizmos . line ( self . start , self . end , self . color ) ;
54
62
// now the hard part is to draw the head in a sensible way
55
63
// put us in a coordinate system where the arrow is pointing towards +x and ends at the origin
56
- let pointing = ( self . end - self . start ) . normalize ( ) ;
57
- let rotation = Quat :: from_rotation_arc ( Vec3 :: X , pointing ) ;
64
+ let pointing_end = ( self . end - self . start ) . normalize ( ) ;
65
+ let rotation_end = Quat :: from_rotation_arc ( Vec3 :: X , pointing_end ) ;
58
66
let tips = [
59
67
Vec3 :: new ( -1. , 1. , 0. ) ,
60
68
Vec3 :: new ( -1. , 0. , 1. ) ,
@@ -64,11 +72,21 @@ impl<T: GizmoConfigGroup> Drop for ArrowBuilder<'_, '_, '_, T> {
64
72
// - extend the vectors so their length is `tip_length`
65
73
// - rotate the world so +x is facing in the same direction as the arrow
66
74
// - translate over to the tip of the arrow
67
- let tips = tips. map ( |v| rotation * ( v. normalize ( ) * self . tip_length ) + self . end ) ;
68
- for v in tips {
75
+ let tips_end = tips. map ( |v| rotation_end * ( v. normalize ( ) * self . tip_length ) + self . end ) ;
76
+ for v in tips_end {
69
77
// then actually draw the tips
70
78
self . gizmos . line ( self . end , v, self . color ) ;
71
79
}
80
+ if self . double_ended {
81
+ let pointing_start = ( self . start - self . end ) . normalize ( ) ;
82
+ let rotation_start = Quat :: from_rotation_arc ( Vec3 :: X , pointing_start) ;
83
+ let tips_start =
84
+ tips. map ( |v| rotation_start * ( v. normalize ( ) * self . tip_length ) + self . start ) ;
85
+ for v in tips_start {
86
+ // draw the start points tips
87
+ self . gizmos . line ( self . start , v, self . color ) ;
88
+ }
89
+ }
72
90
}
73
91
}
74
92
@@ -100,6 +118,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
100
118
start,
101
119
end,
102
120
color : color. into ( ) ,
121
+ double_ended : false ,
103
122
tip_length : length / 10. ,
104
123
}
105
124
}
0 commit comments