@@ -13,41 +13,30 @@ fn main() {
13
13
fn draw_cursor (
14
14
camera_query : Single < ( & Camera , & GlobalTransform ) > ,
15
15
ground : Single < & GlobalTransform , With < Ground > > ,
16
- windows : Query < & Window > ,
16
+ window : Single < & Window > ,
17
17
mut gizmos : Gizmos ,
18
18
) {
19
- let Ok ( windows) = windows. single ( ) else {
20
- return ;
21
- } ;
22
-
23
19
let ( camera, camera_transform) = * camera_query;
24
20
25
- let Some ( cursor_position) = windows. cursor_position ( ) else {
26
- return ;
27
- } ;
28
-
29
- // Calculate a ray pointing from the camera into the world based on the cursor's position.
30
- let Ok ( ray) = camera. viewport_to_world ( camera_transform, cursor_position) else {
31
- return ;
32
- } ;
33
-
34
- // Calculate if and where the ray is hitting the ground plane.
35
- let Some ( distance) =
36
- ray. intersect_plane ( ground. translation ( ) , InfinitePlane3d :: new ( ground. up ( ) ) )
37
- else {
38
- return ;
39
- } ;
40
- let point = ray. get_point ( distance) ;
21
+ if let Some ( cursor_position) = window. cursor_position ( )
22
+ // Calculate a ray pointing from the camera into the world based on the cursor's position.
23
+ && let Ok ( ray) = camera. viewport_to_world ( camera_transform, cursor_position)
24
+ // Calculate if and at what distance the ray is hitting the ground plane.
25
+ && let Some ( distance) =
26
+ ray. intersect_plane ( ground. translation ( ) , InfinitePlane3d :: new ( ground. up ( ) ) )
27
+ {
28
+ let point = ray. get_point ( distance) ;
41
29
42
- // Draw a circle just above the ground plane at that position.
43
- gizmos. circle (
44
- Isometry3d :: new (
45
- point + ground. up ( ) * 0.01 ,
46
- Quat :: from_rotation_arc ( Vec3 :: Z , ground. up ( ) . as_vec3 ( ) ) ,
47
- ) ,
48
- 0.2 ,
49
- Color :: WHITE ,
50
- ) ;
30
+ // Draw a circle just above the ground plane at that position.
31
+ gizmos. circle (
32
+ Isometry3d :: new (
33
+ point + ground. up ( ) * 0.01 ,
34
+ Quat :: from_rotation_arc ( Vec3 :: Z , ground. up ( ) . as_vec3 ( ) ) ,
35
+ ) ,
36
+ 0.2 ,
37
+ Color :: WHITE ,
38
+ ) ;
39
+ }
51
40
}
52
41
53
42
#[ derive( Component ) ]
0 commit comments