food detection
This commit is contained in:
parent
c167f1d99c
commit
fe5f5b5f93
1 changed files with 7 additions and 4 deletions
|
|
@ -2,10 +2,12 @@ use std::cmp::min;
|
||||||
|
|
||||||
use macroquad::prelude::*;
|
use macroquad::prelude::*;
|
||||||
use parry2d::math::Pose;
|
use parry2d::math::Pose;
|
||||||
|
use parry2d::math::Pose2;
|
||||||
use parry2d::math::Rot2;
|
use parry2d::math::Rot2;
|
||||||
use parry2d::math::Vec2;
|
use parry2d::math::Vec2;
|
||||||
use parry2d::query::contact;
|
use parry2d::query::contact;
|
||||||
use parry2d::shape::Ball;
|
use parry2d::shape::Ball;
|
||||||
|
use parry2d::shape::Segment;
|
||||||
use parry2d::shape::Shape;
|
use parry2d::shape::Shape;
|
||||||
|
|
||||||
const VIEW_DIST: f32 = 80.0;
|
const VIEW_DIST: f32 = 80.0;
|
||||||
|
|
@ -44,10 +46,10 @@ impl Robot {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detect<'a>(&self, things: impl Iterator<Item = (&'a Pose, &'a dyn Shape)>) -> Option<f32> {
|
fn detect<'a>(&self, things: impl Iterator<Item = (&'a Pose, &'a dyn Shape)>) -> Option<f32> {
|
||||||
let collider = Ball::new(BOT_RADIUS);
|
let collider = Segment::new(self.pose.translation, self.view_end());
|
||||||
things
|
things
|
||||||
.map(|thing| contact(&self.pose, &collider, thing.0, thing.1, 0.0).unwrap()).flatten()
|
.map(|thing| contact(&Pose2::IDENTITY, &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(|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();
|
let mut robots = Vec::new();
|
||||||
robots.push(Robot::new(Vec2 { x: 100.0, y: 100.0 }));
|
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();
|
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 {
|
loop {
|
||||||
clear_background(LIGHTGRAY);
|
clear_background(LIGHTGRAY);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue