From 0351d6c093a820e7d04bf8ffd2875e17eb7db57d Mon Sep 17 00:00:00 2001 From: DGriffin91 Date: Mon, 8 Aug 2022 16:22:27 -0700 Subject: [PATCH 1/2] cargo format --- examples/minimal.rs | 72 ++++++++++++++++++----------------- src/controller.rs | 93 +++++++++++++++++++++++++++++++-------------- 2 files changed, 101 insertions(+), 64 deletions(-) diff --git a/examples/minimal.rs b/examples/minimal.rs index 4c14957..3a44bae 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -46,7 +46,8 @@ fn setup( // The other is a "render" player that is what is displayed to the user // This distinction is useful for later on if you want to add multiplayer, // where often time these two ideas are not exactly synced up - commands.spawn() + commands + .spawn() .insert(Collider::capsule(Vec3::Y * 0.5, Vec3::Y * 1.5, 0.5)) .insert(ActiveEvents::COLLISION_EVENTS) .insert(Velocity::zero()) @@ -63,49 +64,50 @@ fn setup( yaw: TAU * 5.0 / 8.0, ..default() }) - .insert(FpsController { - ..default() - }); - commands.spawn_bundle(Camera3dBundle::default()) + .insert(FpsController { ..default() }); + commands + .spawn_bundle(Camera3dBundle::default()) .insert(RenderPlayer(0)); // World - commands.spawn_bundle(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box { - min_x: -20.0, - max_x: 20.0, - min_y: -0.25, - max_y: 0.25, - min_z: -20.0, - max_z: 20.0, - })), - material: materials.add(StandardMaterial { - base_color: Color::hex("E6EED6").unwrap(), + commands + .spawn_bundle(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Box { + min_x: -20.0, + max_x: 20.0, + min_y: -0.25, + max_y: 0.25, + min_z: -20.0, + max_z: 20.0, + })), + material: materials.add(StandardMaterial { + base_color: Color::hex("E6EED6").unwrap(), + ..default() + }), + transform: Transform::identity(), ..default() - }), - transform: Transform::identity(), - ..default() - }) + }) .insert(Collider::cuboid(20.0, 0.25, 20.0)) .insert(RigidBody::Fixed) .insert(Transform::identity()); - commands.spawn_bundle(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Box { - min_x: -1.0, - max_x: 1.0, - min_y: -1.0, - max_y: 1.0, - min_z: -1.0, - max_z: 1.0, - })), - material: materials.add(StandardMaterial { - base_color: Color::hex("DDE2C6").unwrap(), + commands + .spawn_bundle(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Box { + min_x: -1.0, + max_x: 1.0, + min_y: -1.0, + max_y: 1.0, + min_z: -1.0, + max_z: 1.0, + })), + material: materials.add(StandardMaterial { + base_color: Color::hex("DDE2C6").unwrap(), + ..default() + }), + transform: Transform::identity(), ..default() - }), - transform: Transform::identity(), - ..default() - }) + }) .insert(Collider::cuboid(1.0, 1.0, 1.0)) .insert(RigidBody::Fixed) .insert(Transform::from_xyz(4.0, 1.0, 4.0)); diff --git a/src/controller.rs b/src/controller.rs index 0ca3a33..ef47a46 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -1,10 +1,7 @@ use std::f32::consts::*; -use bevy::{ - math::Vec3Swizzles, - prelude::*, -}; use bevy::input::mouse::MouseMotion; +use bevy::{math::Vec3Swizzles, prelude::*}; use bevy_rapier3d::prelude::*; pub struct FpsControllerPlugin; @@ -12,8 +9,7 @@ pub struct FpsControllerPlugin; impl Plugin for FpsControllerPlugin { fn build(&self, app: &mut App) { // TODO: these need to be sequential (exclusive system set) - app - .add_system(fps_controller_input) + app.add_system(fps_controller_input) .add_system(fps_controller_look) .add_system(fps_controller_move) .add_system(fps_controller_render); @@ -130,8 +126,8 @@ pub fn fps_controller_input( key_input: Res>, mut windows: ResMut, mut mouse_events: EventReader, - mut query: Query<(&FpsController, &mut FpsControllerInput)>) -{ + mut query: Query<(&FpsController, &mut FpsControllerInput)>, +) { for (controller, mut input) in query.iter_mut() { let window = windows.get_primary_mut().unwrap(); if window.is_focused() { @@ -141,10 +137,8 @@ pub fn fps_controller_input( } mouse_delta *= controller.sensitivity; - input.pitch = (input.pitch - mouse_delta.y).clamp( - -FRAC_PI_2 + ANGLE_EPSILON, - FRAC_PI_2 - ANGLE_EPSILON, - ); + input.pitch = (input.pitch - mouse_delta.y) + .clamp(-FRAC_PI_2 + ANGLE_EPSILON, FRAC_PI_2 - ANGLE_EPSILON); input.yaw = input.yaw - mouse_delta.x; } @@ -160,9 +154,7 @@ pub fn fps_controller_input( } } -pub fn fps_controller_look( - mut query: Query<(&mut FpsController, &FpsControllerInput)>, -) { +pub fn fps_controller_look(mut query: Query<(&mut FpsController, &FpsControllerInput)>) { for (mut controller, input) in query.iter_mut() { controller.pitch = input.pitch; controller.yaw = input.yaw; @@ -173,8 +165,12 @@ pub fn fps_controller_move( time: Res