2025-11-23 18:40:48 +00:00
|
|
|
use macroquad::prelude as mq;
|
2026-01-06 16:41:14 +00:00
|
|
|
use rapier3d::prelude::*;
|
2025-11-23 18:40:48 +00:00
|
|
|
|
|
|
|
|
mod engine;
|
|
|
|
|
use engine::*;
|
2026-01-06 16:41:14 +00:00
|
|
|
|
2025-11-23 23:43:48 +00:00
|
|
|
mod camera;
|
2025-12-07 00:41:00 +00:00
|
|
|
mod drone;
|
2025-11-28 20:39:09 +00:00
|
|
|
mod rendering;
|
2025-11-23 23:43:48 +00:00
|
|
|
|
2026-02-04 23:01:09 +00:00
|
|
|
mod config;
|
2025-11-23 18:40:48 +00:00
|
|
|
mod graphics_util;
|
|
|
|
|
|
2026-01-06 16:41:14 +00:00
|
|
|
use crate::{drone::fpvcontroller::JoystickInput, rendering::Renderer};
|
2025-11-28 20:39:09 +00:00
|
|
|
|
2025-12-08 22:34:01 +00:00
|
|
|
fn window_conf() -> mq::Conf {
|
|
|
|
|
mq::Conf {
|
|
|
|
|
window_title: "RustDroneSim".to_owned(),
|
|
|
|
|
window_resizable: true,
|
2026-01-06 16:41:14 +00:00
|
|
|
// fullscreen: true,
|
2025-12-08 22:34:01 +00:00
|
|
|
platform: mq::miniquad::conf::Platform {
|
2026-01-06 16:41:14 +00:00
|
|
|
// linux_backend: mq::miniquad::conf::LinuxBackend::WaylandOnly,
|
2025-12-08 22:34:01 +00:00
|
|
|
..Default::default()
|
|
|
|
|
},
|
|
|
|
|
..Default::default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[macroquad::main(window_conf)]
|
2025-11-23 18:40:48 +00:00
|
|
|
async fn main() {
|
2026-01-06 16:41:14 +00:00
|
|
|
/* World Setup */
|
2026-01-06 17:05:52 +00:00
|
|
|
let mut world = World::new(600.0);
|
2026-01-06 16:41:14 +00:00
|
|
|
|
|
|
|
|
world.register_free_collider(
|
|
|
|
|
ColliderBuilder::cuboid(30.0, 1.0, 30.0)
|
|
|
|
|
.translation(vector![0.0, -2.0, 0.0])
|
|
|
|
|
.restitution(0.5)
|
|
|
|
|
.build(),
|
|
|
|
|
None,
|
2025-12-15 00:08:10 +00:00
|
|
|
);
|
|
|
|
|
|
2026-01-06 16:41:14 +00:00
|
|
|
let mut drone_controller = drone::pidcontroller::PIDController::default();
|
|
|
|
|
drone_controller.set_input(JoystickInput {
|
2026-01-06 17:05:52 +00:00
|
|
|
throttle_input: 0.2,
|
|
|
|
|
yaw_input: 0.2,
|
|
|
|
|
roll_input: 0.2,
|
2026-01-06 16:41:14 +00:00
|
|
|
pitch_input: 0.0,
|
|
|
|
|
});
|
|
|
|
|
let mut drone_obj = drone::Drone::new(
|
2025-12-15 00:08:10 +00:00
|
|
|
&mut world,
|
2026-01-06 16:41:14 +00:00
|
|
|
Box::new(drone_controller),
|
2025-12-15 00:08:10 +00:00
|
|
|
drone::MotorCharacteristics {
|
2026-01-06 16:41:14 +00:00
|
|
|
max_thrust: 2.6,
|
|
|
|
|
max_torque: 0.5,
|
2025-12-15 00:08:10 +00:00
|
|
|
..Default::default()
|
|
|
|
|
},
|
2026-01-06 16:41:14 +00:00
|
|
|
0.350,
|
2025-12-15 00:08:10 +00:00
|
|
|
);
|
|
|
|
|
|
2026-01-06 16:41:14 +00:00
|
|
|
/* Renderer Setup */
|
|
|
|
|
let camera = camera::AttachedCamera::new(
|
|
|
|
|
drone_obj.rb_handle,
|
|
|
|
|
vector![1.0, 0.0, 0.0],
|
|
|
|
|
vector![0.5, 0.0, 0.0],
|
|
|
|
|
);
|
|
|
|
|
let mut renderer = Renderer::new(Box::new(camera));
|
2025-12-15 00:08:10 +00:00
|
|
|
|
2026-01-06 16:41:14 +00:00
|
|
|
renderer.light.set_location(
|
|
|
|
|
vector![70.0, 150.0, -90.0].into(),
|
|
|
|
|
vector![-0.4, -0.7, 0.6].into(),
|
2025-12-15 00:08:10 +00:00
|
|
|
);
|
2026-01-06 16:41:14 +00:00
|
|
|
renderer.update_light(&world);
|
2025-12-15 00:08:10 +00:00
|
|
|
|
2026-01-06 16:41:14 +00:00
|
|
|
loop {
|
|
|
|
|
renderer.update_camera(&world);
|
2025-12-14 22:04:04 +00:00
|
|
|
|
2026-01-06 16:41:14 +00:00
|
|
|
if mq::is_key_pressed(mq::KeyCode::Q) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-12-14 22:04:04 +00:00
|
|
|
|
2026-01-06 16:41:14 +00:00
|
|
|
// Physics
|
|
|
|
|
world.step();
|
|
|
|
|
let _ = clearscreen::clear();
|
|
|
|
|
drone_obj.process_tick(&mut world);
|
2025-12-07 00:41:00 +00:00
|
|
|
|
2026-01-06 16:41:14 +00:00
|
|
|
// Rendering
|
|
|
|
|
renderer.draw(&mut world);
|
|
|
|
|
|
2026-01-06 17:05:52 +00:00
|
|
|
if world.tick % (10) == 0 {
|
2026-01-06 16:41:14 +00:00
|
|
|
// renderer.update_light(&world);
|
|
|
|
|
// world.clear_ofb();
|
|
|
|
|
mq::next_frame().await;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|