Skip to content
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

pick nits from example bounding_2d #12563

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions examples/2d/bounding_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Comment on lines +287 to +291
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this logic appeared in two places. I pulled it into a function with a name that explains what it's trying to do.


fn draw_ray(gizmos: &mut Gizmos, ray: &RayCast2d) {
gizmos.line_2d(
ray.ray.origin,
ray.ray.origin + *ray.ray.direction * ray.max,
WHITE,
);
for r in [1., 2., 3.] {
gizmos.circle_2d(ray.ray.origin, r, FUCHSIA);
}
draw_filled_circle(gizmos, ray.ray.origin, FUCHSIA);
}

fn get_and_draw_ray(gizmos: &mut Gizmos, time: &Time) -> RayCast2d {
Expand Down Expand Up @@ -323,9 +327,11 @@ fn ray_cast_system(
};
**intersects = toi.is_some();
if let Some(toi) = toi {
for r in [1., 2., 3.] {
gizmos.circle_2d(ray_cast.ray.origin + *ray_cast.ray.direction * toi, r, LIME);
}
draw_filled_circle(
&mut gizmos,
ray_cast.ray.origin + *ray_cast.ray.direction * toi,
LIME,
);
}
}
}
Expand All @@ -350,9 +356,7 @@ fn aabb_cast_system(
**intersects = toi.is_some();
if let Some(toi) = toi {
gizmos.rect_2d(
aabb_cast.ray.ray.origin
+ *aabb_cast.ray.ray.direction * toi
+ aabb_cast.aabb.center(),
aabb_cast.ray.ray.origin + *aabb_cast.ray.ray.direction * toi,
Comment on lines -353 to +359
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aabb_cast.aabb.center() is always Vec2(0.0, 0.0), and so adding it here has no effect on the position of the rendered rect_2d

0.,
aabb_cast.aabb.half_size() * 2.,
LIME,
Expand Down Expand Up @@ -381,9 +385,7 @@ fn bounding_circle_cast_system(
**intersects = toi.is_some();
if let Some(toi) = toi {
gizmos.circle_2d(
circle_cast.ray.ray.origin
+ *circle_cast.ray.ray.direction * toi
+ circle_cast.circle.center(),
circle_cast.ray.ray.origin + *circle_cast.ray.ray.direction * toi,
Comment on lines -384 to +388
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto for this circle_2d

circle_cast.circle.radius(),
LIME,
);
Expand Down