From 442515894674296a1bba6956824b92130da18b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Cornill=C3=A8re?= Date: Wed, 7 Aug 2019 13:27:56 +0200 Subject: [PATCH] Add circle debug line for colliders (#104) --- src/systems/collision.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/systems/collision.rs b/src/systems/collision.rs index 1d19545..011cbaf 100644 --- a/src/systems/collision.rs +++ b/src/systems/collision.rs @@ -1,6 +1,6 @@ -use amethyst::renderer::{debug_drawing::DebugLines, palette::Srgba}; +use amethyst::renderer::{debug_drawing::DebugLinesComponent, palette::Srgba}; use amethyst::shrev::{EventChannel, ReaderId}; -use amethyst::{core::Transform, ecs::*}; +use amethyst::{core::math::Point3, core::Transform, ecs::prelude::*}; use log::info; use std::f32; #[cfg(feature = "profiler")] @@ -99,20 +99,17 @@ impl<'s> System<'s> for DebugColliderSystem { type SystemData = ( ReadStorage<'s, collider::Circle>, ReadStorage<'s, Transform>, - Write<'s, DebugLines>, + WriteStorage<'s, DebugLinesComponent>, ); - fn run(&mut self, (circles, locals, mut debug_lines): Self::SystemData) { - for (circle, local) in (&circles, &locals).join() { - let position = local.translation().clone(); - debug_lines.draw_line( - [position.x - circle.radius, position.y, 0.0].into(), - [position.x + circle.radius, position.y, 0.0].into(), - Srgba::new(1.0, 0.5, 0.5, 1.0), - ); - debug_lines.draw_line( - [position.x, position.y - circle.radius, 0.0].into(), - [position.x, position.y + circle.radius, 0.0].into(), + fn run(&mut self, (circles, locals, mut debug_lines_comps): Self::SystemData) { + for (circle, local, db_comp) in (&circles, &locals, &mut debug_lines_comps).join() { + let mut position = local.global_matrix().column(3).xyz(); + position[2] += 1.0; + db_comp.add_circle_2d( + Point3::from(position), + circle.radius, + 16, Srgba::new(1.0, 0.5, 0.5, 1.0), ); }