pre aerodynamics
This commit is contained in:
parent
2e8842ca24
commit
d0cb6ce28a
|
|
@ -1,7 +1,7 @@
|
||||||
use macroquad::prelude::*;
|
use macroquad::prelude::*;
|
||||||
|
|
||||||
const MOVE_SPEED: f32 = 1.0;
|
const MOVE_SPEED: f32 = 0.1;
|
||||||
const LOOK_SPEED: f32 = 0.01;
|
const LOOK_SPEED: f32 = 0.05;
|
||||||
|
|
||||||
pub struct FirstPersonCamera {
|
pub struct FirstPersonCamera {
|
||||||
pub position: Vec3,
|
pub position: Vec3,
|
||||||
|
|
|
||||||
14
src/drone.rs
14
src/drone.rs
|
|
@ -43,6 +43,8 @@ pub struct Drone {
|
||||||
pub rb_handle: rp::RigidBodyHandle,
|
pub rb_handle: rp::RigidBodyHandle,
|
||||||
motor_characteristics: MotorCharacteristics,
|
motor_characteristics: MotorCharacteristics,
|
||||||
pub controller: Box<dyn DroneController>,
|
pub controller: Box<dyn DroneController>,
|
||||||
|
width: f32,
|
||||||
|
height: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drone {
|
impl Drone {
|
||||||
|
|
@ -63,18 +65,20 @@ impl Drone {
|
||||||
* Values are kind of random for now. Calculating them requires the final model
|
* Values are kind of random for now. Calculating them requires the final model
|
||||||
* A Poor Man's fluid simulation :D
|
* A Poor Man's fluid simulation :D
|
||||||
*/
|
*/
|
||||||
.linear_damping(0.2) // Damps velocity slowly
|
// .linear_damping(0.2) // Damps velocity slowly
|
||||||
.angular_damping(0.2) // Damps angular velocity slowly
|
// .angular_damping(0.2) // Damps angular velocity slowly
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
|
let width = 0.40;
|
||||||
|
let height = 0.25;
|
||||||
world.register_collider(
|
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)
|
.mass(mass)
|
||||||
.restitution(0.3)
|
.restitution(0.3)
|
||||||
.build(),
|
.build(),
|
||||||
drone_rb_handle,
|
drone_rb_handle,
|
||||||
Some(ColliderExtraData {
|
Some(ColliderExtraData {
|
||||||
color: macroquad::color::WHITE,
|
color: macroquad::color::RED,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -86,6 +90,8 @@ impl Drone {
|
||||||
rb_handle: drone_rb_handle,
|
rb_handle: drone_rb_handle,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
motor_characteristics: motor_characteristics,
|
motor_characteristics: motor_characteristics,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,12 @@ impl DroneController for PIDController {
|
||||||
fn set_motor_characteristics(&self, _motor_characteristics: &MotorCharacteristics) {}
|
fn set_motor_characteristics(&self, _motor_characteristics: &MotorCharacteristics) {}
|
||||||
fn get_motor_throttles(&self) -> [f32; 4] {
|
fn get_motor_throttles(&self) -> [f32; 4] {
|
||||||
self.get_angular_velocity();
|
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,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,8 @@ impl World {
|
||||||
impl Default for World {
|
impl Default for World {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let gravity: na::Vector3<f32> = rp::vector![0.0, -9.81, 0.0];
|
let gravity: na::Vector3<f32> = 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 physics_pipeline = rp::PhysicsPipeline::new();
|
||||||
let island_manager = rp::IslandManager::new();
|
let island_manager = rp::IslandManager::new();
|
||||||
let broad_phase = rp::DefaultBroadPhase::new();
|
let broad_phase = rp::DefaultBroadPhase::new();
|
||||||
|
|
|
||||||
12
src/main.rs
12
src/main.rs
|
|
@ -18,7 +18,7 @@ fn window_conf() -> mq::Conf {
|
||||||
window_resizable: true,
|
window_resizable: true,
|
||||||
// fullscreen: true,
|
// fullscreen: true,
|
||||||
platform: mq::miniquad::conf::Platform {
|
platform: mq::miniquad::conf::Platform {
|
||||||
// linux_backend: mq::miniquad::conf::LinuxBackend::WaylandOnly,
|
linux_backend: mq::miniquad::conf::LinuxBackend::WaylandOnly,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
@ -38,7 +38,7 @@ async fn main() {
|
||||||
|
|
||||||
// Ground collider
|
// Ground collider
|
||||||
world.register_free_collider(
|
world.register_free_collider(
|
||||||
ColliderBuilder::cuboid(250.0, 5.0, 250.0)
|
ColliderBuilder::cuboid(20.0, 1.0, 20.0)
|
||||||
.restitution(0.5)
|
.restitution(0.5)
|
||||||
.build(),
|
.build(),
|
||||||
None,
|
None,
|
||||||
|
|
@ -46,7 +46,7 @@ async fn main() {
|
||||||
|
|
||||||
let mut controller = drone::pidcontroller::PIDController::default();
|
let mut controller = drone::pidcontroller::PIDController::default();
|
||||||
controller.set_input(JoystickInput {
|
controller.set_input(JoystickInput {
|
||||||
throttle_input: 1.0,
|
throttle_input: 0.4,
|
||||||
yaw_input: 0.05,
|
yaw_input: 0.05,
|
||||||
roll_input: 0.0,
|
roll_input: 0.0,
|
||||||
pitch_input: 0.0,
|
pitch_input: 0.0,
|
||||||
|
|
@ -55,8 +55,8 @@ async fn main() {
|
||||||
&mut world,
|
&mut world,
|
||||||
Box::new(controller),
|
Box::new(controller),
|
||||||
drone::MotorCharacteristics {
|
drone::MotorCharacteristics {
|
||||||
max_thrust: 3.0,
|
max_thrust: 2.3,
|
||||||
max_torque: 2.0,
|
max_torque: 0.01,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
0.350,
|
0.350,
|
||||||
|
|
@ -107,7 +107,7 @@ async fn main() {
|
||||||
// Rendering
|
// Rendering
|
||||||
renderer.draw(&mut world);
|
renderer.draw(&mut world);
|
||||||
|
|
||||||
if world.tick % 60 == 0 {
|
if world.tick % (800 / 30) == 0 {
|
||||||
world.clear_ofb();
|
world.clear_ofb();
|
||||||
renderer.update_light(&world);
|
renderer.update_light(&world);
|
||||||
mq::next_frame().await;
|
mq::next_frame().await;
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ impl Renderer {
|
||||||
.set_filter(mq::FilterMode::Nearest);
|
.set_filter(mq::FilterMode::Nearest);
|
||||||
|
|
||||||
let light = Light::new();
|
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 {
|
let mut r = Renderer {
|
||||||
base_material: material,
|
base_material: material,
|
||||||
depth_material,
|
depth_material,
|
||||||
|
|
@ -269,7 +269,7 @@ impl Renderer {
|
||||||
|
|
||||||
// mq::draw_sphere(self.light.position, 0.25, None, mq::WHITE);
|
// 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::gl_use_default_material();
|
||||||
mq::set_default_camera();
|
mq::set_default_camera();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue