diff --git a/Cargo.toml b/Cargo.toml index ad36a872c7..88df3f64f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -528,6 +528,17 @@ description = "Shows how to create graphics that snap to the pixel grid by rende category = "2D Rendering" wasm = true +[[example]] +name = "bounding_2d" +path = "examples/2d/bounding_2d.rs" +doc-scrape-examples = true + +[package.metadata.example.bounding_2d] +name = "2D Bounding Volume Intersections" +description = "Showcases bounding volumes and intersection tests" +category = "2D Rendering" +wasm = true + # 3D Rendering [[example]] name = "3d_scene" diff --git a/examples/2d/bounding_2d.rs b/examples/2d/bounding_2d.rs new file mode 100644 index 0000000000..ff121d7d8c --- /dev/null +++ b/examples/2d/bounding_2d.rs @@ -0,0 +1,444 @@ +//! This example demonstrates bounding volume intersections. + +use bevy::{math::bounding::*, prelude::*}; + +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .init_state::() + .add_systems(Startup, setup) + .add_systems( + Update, + (update_text, spin, update_volumes, update_test_state), + ) + .add_systems( + PostUpdate, + ( + render_shapes, + ( + aabb_intersection_system.run_if(in_state(Test::AabbSweep)), + circle_intersection_system.run_if(in_state(Test::CircleSweep)), + ray_cast_system.run_if(in_state(Test::RayCast)), + aabb_cast_system.run_if(in_state(Test::AabbCast)), + bounding_circle_cast_system.run_if(in_state(Test::CircleCast)), + ), + render_volumes, + ) + .chain(), + ) + .run(); +} + +#[derive(Component)] +struct Spin; + +fn spin(time: Res