diff --git a/simulator/.gitignore b/simulator/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/simulator/.gitignore @@ -0,0 +1 @@ +target diff --git a/simulator/Cargo.lock b/simulator/Cargo.lock index 9d66758..59521cb 100644 --- a/simulator/Cargo.lock +++ b/simulator/Cargo.lock @@ -174,6 +174,12 @@ dependencies = [ "libm", ] +[[package]] +name = "glam" +version = "0.34.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "627003914c6057c9c8f0832ee4f870b5a4f599d0cfa83f4072675114860cd0ff" + [[package]] name = "glamx" version = "0.3.1" @@ -463,6 +469,7 @@ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" name = "simulator" version = "0.1.0" dependencies = [ + "glam 0.34.3", "macroquad", "parry2d", ] diff --git a/simulator/Cargo.toml b/simulator/Cargo.toml index 339b09c..adccad3 100644 --- a/simulator/Cargo.toml +++ b/simulator/Cargo.toml @@ -4,5 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] +glam = "0.34.3" macroquad = "0.4.16" parry2d = "0.31.1" diff --git a/simulator/src/main.rs b/simulator/src/main.rs index e7a11a9..0691deb 100644 --- a/simulator/src/main.rs +++ b/simulator/src/main.rs @@ -1,3 +1,57 @@ -fn main() { - println!("Hello, world!"); +use macroquad::prelude::*; +use parry2d::math::Pose; +use parry2d::math::Rot2; +use parry2d::math::Vec2; + +const VIEW_DIST: f32 = 80.0; +const BOT_RADIUS: f32 = 16.0; + +struct Robot { + pose: Pose, + alive: bool, +} + +impl Robot { + fn new(position: Vec2) -> Self { + let pose:Pose = Pose::from_translation(position.to_array().into()); + Self { pose, alive: true } + } + + fn move_step(&mut self, forward: f32, right: f32) { + self.pose.translation += self.ahead() * forward; + self.pose.rotation *= Rot2::from_angle(right); + } + + pub fn ahead(&self) -> Vec2 { + Vec2::new(self.pose.rotation.re, self.pose.rotation.im) + } + + pub fn draw(&self) { + let tl = self.pose.translation; + let tl2 = self.pose.translation + self.ahead() * VIEW_DIST; + draw_circle(tl.x, tl.y, BOT_RADIUS, BLACK); + draw_line(tl.x, tl.y, tl2.x, tl2.y, 2.0, BLUE); + draw_circle(tl.x, tl.y, BOT_RADIUS-1.0, YELLOW); + } +} + +#[macroquad::main("Adversarial Foraging Simulator")] +async fn main() { + + let mut robots = Vec::new(); + + robots.push(Robot::new(Vec2 { x: 100.0, y: 100.0 })); + + loop { + clear_background(LIGHTGRAY); + + + for robot in &mut robots { + robot.move_step(1.1,0.01); + println!("loop"); + robot.draw(); + } + draw_text("HELLO", 20.0, 20.0, 30.0, DARKGRAY); + next_frame().await // TODO: framerate cap + } }