pick nits from example bounding_2d (#12563)
# Objective - went through bounding_2d example with a fine-toothed comb and found two small issues ## Solution - pulled "draw a small filled-in circle" logic into a function - removed impotent addition of aabb / circle origin (identically `Vec2(0.0, 0.0)`)
This commit is contained in:
parent
0950348916
commit
70d8ce7762
@ -284,15 +284,19 @@ fn setup(mut commands: Commands, loader: Res<AssetServer>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_filled_circle(gizmos: &mut Gizmos, position: Vec2, color: Srgba) {
|
||||||
|
for r in [1., 2., 3.] {
|
||||||
|
gizmos.circle_2d(position, r, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_ray(gizmos: &mut Gizmos, ray: &RayCast2d) {
|
fn draw_ray(gizmos: &mut Gizmos, ray: &RayCast2d) {
|
||||||
gizmos.line_2d(
|
gizmos.line_2d(
|
||||||
ray.ray.origin,
|
ray.ray.origin,
|
||||||
ray.ray.origin + *ray.ray.direction * ray.max,
|
ray.ray.origin + *ray.ray.direction * ray.max,
|
||||||
WHITE,
|
WHITE,
|
||||||
);
|
);
|
||||||
for r in [1., 2., 3.] {
|
draw_filled_circle(gizmos, ray.ray.origin, FUCHSIA);
|
||||||
gizmos.circle_2d(ray.ray.origin, r, FUCHSIA);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_and_draw_ray(gizmos: &mut Gizmos, time: &Time) -> RayCast2d {
|
fn get_and_draw_ray(gizmos: &mut Gizmos, time: &Time) -> RayCast2d {
|
||||||
@ -323,9 +327,11 @@ fn ray_cast_system(
|
|||||||
};
|
};
|
||||||
**intersects = toi.is_some();
|
**intersects = toi.is_some();
|
||||||
if let Some(toi) = toi {
|
if let Some(toi) = toi {
|
||||||
for r in [1., 2., 3.] {
|
draw_filled_circle(
|
||||||
gizmos.circle_2d(ray_cast.ray.origin + *ray_cast.ray.direction * toi, r, LIME);
|
&mut gizmos,
|
||||||
}
|
ray_cast.ray.origin + *ray_cast.ray.direction * toi,
|
||||||
|
LIME,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,9 +356,7 @@ fn aabb_cast_system(
|
|||||||
**intersects = toi.is_some();
|
**intersects = toi.is_some();
|
||||||
if let Some(toi) = toi {
|
if let Some(toi) = toi {
|
||||||
gizmos.rect_2d(
|
gizmos.rect_2d(
|
||||||
aabb_cast.ray.ray.origin
|
aabb_cast.ray.ray.origin + *aabb_cast.ray.ray.direction * toi,
|
||||||
+ *aabb_cast.ray.ray.direction * toi
|
|
||||||
+ aabb_cast.aabb.center(),
|
|
||||||
0.,
|
0.,
|
||||||
aabb_cast.aabb.half_size() * 2.,
|
aabb_cast.aabb.half_size() * 2.,
|
||||||
LIME,
|
LIME,
|
||||||
@ -381,9 +385,7 @@ fn bounding_circle_cast_system(
|
|||||||
**intersects = toi.is_some();
|
**intersects = toi.is_some();
|
||||||
if let Some(toi) = toi {
|
if let Some(toi) = toi {
|
||||||
gizmos.circle_2d(
|
gizmos.circle_2d(
|
||||||
circle_cast.ray.ray.origin
|
circle_cast.ray.ray.origin + *circle_cast.ray.ray.direction * toi,
|
||||||
+ *circle_cast.ray.ray.direction * toi
|
|
||||||
+ circle_cast.circle.center(),
|
|
||||||
circle_cast.circle.radius(),
|
circle_cast.circle.radius(),
|
||||||
LIME,
|
LIME,
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user