From 6adfdb034145ecff363b3aa8ab71e4fabc481531 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Sat, 25 May 2024 14:50:51 -0400 Subject: [PATCH] Adds a test cube for testing debug drawing of AABB colliders --- crates/core/src/core.rs | 11 +++++--- crates/physics/src/components.rs | 5 +++- crates/physics/src/lib.rs | 23 +++++++++++++--- crates/physics/src/systems.rs | 45 ++++++++++++++++++++++++++++++-- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/crates/core/src/core.rs b/crates/core/src/core.rs index 8a3bc2a..40ee0cf 100644 --- a/crates/core/src/core.rs +++ b/crates/core/src/core.rs @@ -1,5 +1,5 @@ -use bevy::prelude::*; +use bevy::{pbr::wireframe::{Wireframe, WireframePlugin}, prelude::*}; use physics::{PhysicsPlugin, components::Velocity}; @@ -8,7 +8,7 @@ impl Plugin for CorePlugin { fn build(&self, app: &mut App) { - app.add_plugins(PhysicsPlugin) + app.add_plugins((PhysicsPlugin {debug_draw_colliders: true})) .add_systems(Startup, setup); } } @@ -35,13 +35,16 @@ fn setup(mut commands: Commands, server: Res, mut ambient_light: Re ..default() }); + // TESTING: + + // BRICK let brick_handle: Handle = server.load("brick.glb#Scene0"); - commands.spawn(SceneBundle { + commands.spawn((SceneBundle { scene: brick_handle, transform: Transform::from_xyz(0.0, 7.0, 0.0), .. default() - }); + }, Wireframe)); // BALL let ball_handle: Handle = server.load("ball.glb#Scene0"); diff --git a/crates/physics/src/components.rs b/crates/physics/src/components.rs index ae46881..bdcc527 100644 --- a/crates/physics/src/components.rs +++ b/crates/physics/src/components.rs @@ -123,4 +123,7 @@ impl AABB true } -} \ No newline at end of file +} + +#[derive(Component)] +pub struct ColliderDebug; \ No newline at end of file diff --git a/crates/physics/src/lib.rs b/crates/physics/src/lib.rs index e38cef4..661f8fa 100644 --- a/crates/physics/src/lib.rs +++ b/crates/physics/src/lib.rs @@ -2,13 +2,30 @@ pub mod components; pub mod systems; -use bevy::prelude::*; +use bevy::{pbr::wireframe::WireframePlugin, prelude::*}; + +pub struct PhysicsPlugin +{ + pub debug_draw_colliders: bool, +} -pub struct PhysicsPlugin; impl Plugin for PhysicsPlugin { fn build(&self, app: &mut App) { - app.add_systems(Update, systems::update_movement); + app.add_plugins(WireframePlugin) + .add_systems(Update, systems::update_movement); + + if self.debug_draw_colliders + { + app.add_systems(Startup, systems::debug_draw_aabbs); + } + } +} + +impl Default for PhysicsPlugin +{ + fn default() -> Self { + Self { debug_draw_colliders: false } } } \ No newline at end of file diff --git a/crates/physics/src/systems.rs b/crates/physics/src/systems.rs index dafd762..b034496 100644 --- a/crates/physics/src/systems.rs +++ b/crates/physics/src/systems.rs @@ -1,7 +1,7 @@ -use bevy::prelude::*; +use bevy::{pbr::wireframe::{Wireframe, WireframeColor}, prelude::*}; -use crate::components::Velocity; +use crate::components::{ColliderDebug, Velocity, AABB}; pub(crate) fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res