From ba9750e26512acd73a14cc49ba1837e0b6bcc113 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Tue, 14 Mar 2023 00:07:10 +0800 Subject: [PATCH] =?UTF-8?q?cargo=20fmt=E4=B8=80=E9=81=8D=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/Difficult_Rocket_rs/src/src/lib.rs | 6 +- libs/Difficult_Rocket_rs/src/src/simulator.rs | 97 +++++++++---------- 2 files changed, 50 insertions(+), 53 deletions(-) diff --git a/libs/Difficult_Rocket_rs/src/src/lib.rs b/libs/Difficult_Rocket_rs/src/src/lib.rs index 888040d..697b3d1 100644 --- a/libs/Difficult_Rocket_rs/src/src/lib.rs +++ b/libs/Difficult_Rocket_rs/src/src/lib.rs @@ -6,10 +6,10 @@ * ------------------------------- */ -mod sr1_render; +mod render; mod simulator; mod sr1_data; -mod render; +mod sr1_render; mod types; use pyo3::prelude::*; @@ -41,4 +41,4 @@ fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_class::()?; m.add_class::()?; Ok(()) -} \ No newline at end of file +} diff --git a/libs/Difficult_Rocket_rs/src/src/simulator.rs b/libs/Difficult_Rocket_rs/src/src/simulator.rs index fe5d11f..a16fdce 100644 --- a/libs/Difficult_Rocket_rs/src/src/simulator.rs +++ b/libs/Difficult_Rocket_rs/src/src/simulator.rs @@ -6,63 +6,60 @@ * ------------------------------- */ -use rapier2d_f64::prelude::*; use pyo3::prelude::*; +use rapier2d_f64::prelude::*; #[pyfunction] #[pyo3(name = "simluation")] pub fn simluation() -> PyResult<()> { - let mut rigid_body_set = RigidBodySet::new(); - let mut collider_set = ColliderSet::new(); + let mut rigid_body_set = RigidBodySet::new(); + let mut collider_set = ColliderSet::new(); - /* Create the ground. */ - let collider = ColliderBuilder::cuboid(100.0, 0.1).build(); - collider_set.insert(collider); + /* Create the ground. */ + let collider = ColliderBuilder::cuboid(100.0, 0.1).build(); + collider_set.insert(collider); - /* Create the bouncing ball. */ - let rigid_body = RigidBodyBuilder::dynamic() - .translation(vector![0.0, 10.0]) - .build(); - let collider = ColliderBuilder::ball(0.5).restitution(0.7).build(); - let ball_body_handle = rigid_body_set.insert(rigid_body); - collider_set.insert_with_parent(collider, ball_body_handle, &mut rigid_body_set); + /* Create the bouncing ball. */ + let rigid_body = RigidBodyBuilder::dynamic() + .translation(vector![0.0, 10.0]) + .build(); + let collider = ColliderBuilder::ball(0.5).restitution(0.7).build(); + let ball_body_handle = rigid_body_set.insert(rigid_body); + collider_set.insert_with_parent(collider, ball_body_handle, &mut rigid_body_set); - /* Create other structures necessary for the simulation. */ - let gravity = vector![0.0, -9.81]; - let integration_parameters = IntegrationParameters::default(); - let mut physics_pipeline = PhysicsPipeline::new(); - let mut island_manager = IslandManager::new(); - let mut broad_phase = BroadPhase::new(); - let mut narrow_phase = NarrowPhase::new(); - let mut impulse_joint_set = ImpulseJointSet::new(); - let mut multibody_joint_set = MultibodyJointSet::new(); - let mut ccd_solver = CCDSolver::new(); - let physics_hooks = (); - let event_handler = (); + /* Create other structures necessary for the simulation. */ + let gravity = vector![0.0, -9.81]; + let integration_parameters = IntegrationParameters::default(); + let mut physics_pipeline = PhysicsPipeline::new(); + let mut island_manager = IslandManager::new(); + let mut broad_phase = BroadPhase::new(); + let mut narrow_phase = NarrowPhase::new(); + let mut impulse_joint_set = ImpulseJointSet::new(); + let mut multibody_joint_set = MultibodyJointSet::new(); + let mut ccd_solver = CCDSolver::new(); + let physics_hooks = (); + let event_handler = (); - /* Run the game loop, stepping the simulation once per frame. */ - for _ in 0..200 { - physics_pipeline.step( - &gravity, - &integration_parameters, - &mut island_manager, - &mut broad_phase, - &mut narrow_phase, - &mut rigid_body_set, - &mut collider_set, - &mut impulse_joint_set, - &mut multibody_joint_set, - &mut ccd_solver, - None, - &physics_hooks, - &event_handler, - ); + /* Run the game loop, stepping the simulation once per frame. */ + for _ in 0..200 { + physics_pipeline.step( + &gravity, + &integration_parameters, + &mut island_manager, + &mut broad_phase, + &mut narrow_phase, + &mut rigid_body_set, + &mut collider_set, + &mut impulse_joint_set, + &mut multibody_joint_set, + &mut ccd_solver, + None, + &physics_hooks, + &event_handler, + ); - let ball_body = &rigid_body_set[ball_body_handle]; - println!( - "Ball altitude: {}", - ball_body.translation().y - ); - } - Ok(()) -} \ No newline at end of file + let ball_body = &rigid_body_set[ball_body_handle]; + println!("Ball altitude: {}", ball_body.translation().y); + } + Ok(()) +}