pre aerodynamics
This commit is contained in:
parent
2e8842ca24
commit
d0cb6ce28a
|
|
@ -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,
|
||||
|
|
|
|||
14
src/drone.rs
14
src/drone.rs
|
|
@ -43,6 +43,8 @@ pub struct Drone {
|
|||
pub rb_handle: rp::RigidBodyHandle,
|
||||
motor_characteristics: MotorCharacteristics,
|
||||
pub controller: Box<dyn DroneController>,
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -121,7 +121,8 @@ impl World {
|
|||
impl Default for World {
|
||||
fn default() -> Self {
|
||||
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 island_manager = rp::IslandManager::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,
|
||||
// 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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue