From d0cb6ce28aa57dab2495f1948004145353614646 Mon Sep 17 00:00:00 2001 From: Flima Desktop Date: Tue, 9 Dec 2025 21:47:05 +0000 Subject: [PATCH] pre aerodynamics --- src/camera.rs | 4 ++-- src/drone.rs | 14 ++++++++++---- src/drone/pidcontroller.rs | 7 ++++++- src/engine.rs | 3 ++- src/main.rs | 12 ++++++------ src/rendering.rs | 4 ++-- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index acf8ff5..10b33f4 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,7 +1,7 @@ use macroquad::prelude::*; -const MOVE_SPEED: f32 = 1.0; -const LOOK_SPEED: f32 = 0.01; +const MOVE_SPEED: f32 = 0.1; +const LOOK_SPEED: f32 = 0.05; pub struct FirstPersonCamera { pub position: Vec3, diff --git a/src/drone.rs b/src/drone.rs index 191d4dc..e40f022 100644 --- a/src/drone.rs +++ b/src/drone.rs @@ -43,6 +43,8 @@ pub struct Drone { pub rb_handle: rp::RigidBodyHandle, motor_characteristics: MotorCharacteristics, pub controller: Box, + width: f32, + height: f32, } impl Drone { @@ -63,18 +65,20 @@ impl Drone { * Values are kind of random for now. Calculating them requires the final model * A Poor Man's fluid simulation :D */ - .linear_damping(0.2) // Damps velocity slowly - .angular_damping(0.2) // Damps angular velocity slowly + // .linear_damping(0.2) // Damps velocity slowly + // .angular_damping(0.2) // Damps angular velocity slowly .build(), ); + let width = 0.40; + let height = 0.25; world.register_collider( - rp::ColliderBuilder::cuboid(5.0, 0.5, 5.0) + rp::ColliderBuilder::cuboid(width / 2.0, height / 2.0, width / 2.0) .mass(mass) .restitution(0.3) .build(), drone_rb_handle, Some(ColliderExtraData { - color: macroquad::color::WHITE, + color: macroquad::color::RED, }), ); @@ -86,6 +90,8 @@ impl Drone { rb_handle: drone_rb_handle, controller: controller, motor_characteristics: motor_characteristics, + width, + height, }; } diff --git a/src/drone/pidcontroller.rs b/src/drone/pidcontroller.rs index 9eaa70e..559517d 100644 --- a/src/drone/pidcontroller.rs +++ b/src/drone/pidcontroller.rs @@ -65,7 +65,12 @@ impl DroneController for PIDController { fn set_motor_characteristics(&self, _motor_characteristics: &MotorCharacteristics) {} fn get_motor_throttles(&self) -> [f32; 4] { self.get_angular_velocity(); - return [1.0, 1.0, 1.0, 1.0]; + return [ + self.input.throttle_input, + self.input.throttle_input, + self.input.throttle_input, + self.input.throttle_input, + ]; } /* diff --git a/src/engine.rs b/src/engine.rs index bcc04e5..744d73a 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -121,7 +121,8 @@ impl World { impl Default for World { fn default() -> Self { let gravity: na::Vector3 = rp::vector![0.0, -9.81, 0.0]; - let integration_parameters = rp::IntegrationParameters::default(); + let mut integration_parameters = rp::IntegrationParameters::default(); + integration_parameters.set_inv_dt(800.0); let physics_pipeline = rp::PhysicsPipeline::new(); let island_manager = rp::IslandManager::new(); let broad_phase = rp::DefaultBroadPhase::new(); diff --git a/src/main.rs b/src/main.rs index d9f1d53..2606db5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ fn window_conf() -> mq::Conf { window_resizable: true, // fullscreen: true, platform: mq::miniquad::conf::Platform { - // linux_backend: mq::miniquad::conf::LinuxBackend::WaylandOnly, + linux_backend: mq::miniquad::conf::LinuxBackend::WaylandOnly, ..Default::default() }, ..Default::default() @@ -38,7 +38,7 @@ async fn main() { // Ground collider world.register_free_collider( - ColliderBuilder::cuboid(250.0, 5.0, 250.0) + ColliderBuilder::cuboid(20.0, 1.0, 20.0) .restitution(0.5) .build(), None, @@ -46,7 +46,7 @@ async fn main() { let mut controller = drone::pidcontroller::PIDController::default(); controller.set_input(JoystickInput { - throttle_input: 1.0, + throttle_input: 0.4, yaw_input: 0.05, roll_input: 0.0, pitch_input: 0.0, @@ -55,8 +55,8 @@ async fn main() { &mut world, Box::new(controller), drone::MotorCharacteristics { - max_thrust: 3.0, - max_torque: 2.0, + max_thrust: 2.3, + max_torque: 0.01, ..Default::default() }, 0.350, @@ -107,7 +107,7 @@ async fn main() { // Rendering renderer.draw(&mut world); - if world.tick % 60 == 0 { + if world.tick % (800 / 30) == 0 { world.clear_ofb(); renderer.update_light(&world); mq::next_frame().await; diff --git a/src/rendering.rs b/src/rendering.rs index 4bf39e7..66ddb60 100644 --- a/src/rendering.rs +++ b/src/rendering.rs @@ -171,7 +171,7 @@ impl Renderer { .set_filter(mq::FilterMode::Nearest); let light = Light::new(); - let camera = FirstPersonCamera::new(mq::vec3(-400.0, 100.0, 0.0)); + let camera = FirstPersonCamera::new(mq::vec3(-50.0, 20.0, 0.0)); let mut r = Renderer { base_material: material, depth_material, @@ -269,7 +269,7 @@ impl Renderer { // mq::draw_sphere(self.light.position, 0.25, None, mq::WHITE); - mq::draw_grid(20, 1., mq::BLACK, mq::GRAY); + // mq::draw_grid(20, 1., mq::BLACK, mq::GRAY); mq::gl_use_default_material(); mq::set_default_camera(); }