render robots in scene
This commit is contained in:
parent
71a8fb559a
commit
c8f80c8657
4 changed files with 65 additions and 2 deletions
1
simulator/.gitignore
vendored
Normal file
1
simulator/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
target
|
||||||
7
simulator/Cargo.lock
generated
7
simulator/Cargo.lock
generated
|
|
@ -174,6 +174,12 @@ dependencies = [
|
||||||
"libm",
|
"libm",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glam"
|
||||||
|
version = "0.34.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "627003914c6057c9c8f0832ee4f870b5a4f599d0cfa83f4072675114860cd0ff"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glamx"
|
name = "glamx"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
|
@ -463,6 +469,7 @@ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
|
||||||
name = "simulator"
|
name = "simulator"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"glam 0.34.3",
|
||||||
"macroquad",
|
"macroquad",
|
||||||
"parry2d",
|
"parry2d",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,6 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
glam = "0.34.3"
|
||||||
macroquad = "0.4.16"
|
macroquad = "0.4.16"
|
||||||
parry2d = "0.31.1"
|
parry2d = "0.31.1"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,57 @@
|
||||||
fn main() {
|
use macroquad::prelude::*;
|
||||||
println!("Hello, world!");
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue