1
Fork 0

render robots in scene

This commit is contained in:
Andy Killorin 2026-11-08 23:48:02 -05:00
parent 71a8fb559a
commit c8f80c8657
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
4 changed files with 65 additions and 2 deletions

1
simulator/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
target

7
simulator/Cargo.lock generated
View file

@ -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",
]

View file

@ -4,5 +4,6 @@ version = "0.1.0"
edition = "2024"
[dependencies]
glam = "0.34.3"
macroquad = "0.4.16"
parry2d = "0.31.1"

View file

@ -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
}
}