diff --git a/simulator/src/main.rs b/simulator/src/main.rs index f122afd..711ebb2 100644 --- a/simulator/src/main.rs +++ b/simulator/src/main.rs @@ -2,10 +2,12 @@ use std::cmp::min; use macroquad::prelude::*; use parry2d::math::Pose; +use parry2d::math::Pose2; use parry2d::math::Rot2; use parry2d::math::Vec2; use parry2d::query::contact; use parry2d::shape::Ball; +use parry2d::shape::Segment; use parry2d::shape::Shape; const VIEW_DIST: f32 = 80.0; @@ -44,10 +46,10 @@ impl Robot { } fn detect<'a>(&self, things: impl Iterator) -> Option { - let collider = Ball::new(BOT_RADIUS); + let collider = Segment::new(self.pose.translation, self.view_end()); things - .map(|thing| contact(&self.pose, &collider, thing.0, thing.1, 0.0).unwrap()).flatten() - .map(|contactl| contactl.point1.distance(self.pose.translation)).reduce(|x: f32,y: f32| x.min(y)) + .map(|thing| contact(&Pose2::IDENTITY, &collider, thing.0, thing.1, 0.0).unwrap()).flatten() + .map(|contact| contact.point1.distance(self.pose.translation)).reduce(|x: f32,y: f32| x.min(y)) } } @@ -80,9 +82,10 @@ async fn main() { let mut robots = Vec::new(); robots.push(Robot::new(Vec2 { x: 100.0, y: 100.0 })); + robots.push(Robot::new(Vec2 { x: 140.0, y: 100.0 })); let mut food = Vec::new(); - food.push(Food::new(Vec2 { x: 100.0, y: 100.0 })); + food.push(Food::new(Vec2 { x: 160.0, y: 100.0 })); loop { clear_background(LIGHTGRAY);