Fix formatting

This commit is contained in:
Jan Nils Ferner
2023-02-04 18:12:15 +01:00
parent 220d2b09ab
commit da671fd99a
2 changed files with 24 additions and 26 deletions

View File

@@ -1,6 +1,6 @@
use std::f32::consts::PI;
use rapier2d::prelude::*; use rapier2d::prelude::*;
use rapier_testbed2d::Testbed; use rapier_testbed2d::Testbed;
use std::f32::consts::PI;
pub fn init_world(testbed: &mut Testbed) { pub fn init_world(testbed: &mut Testbed) {
/* /*

View File

@@ -232,8 +232,7 @@ impl KinematicCharacterController {
filter, filter,
) { ) {
// We hit something, compute the allowed self. // We hit something, compute the allowed self.
let allowed_dist = let allowed_dist = toi.toi - (toi.normal1.dot(&translation_dir)).abs() * offset;
toi.toi - (toi.normal1.dot(&translation_dir)).abs() * offset;
let allowed_translation = *translation_dir * allowed_dist; let allowed_translation = *translation_dir * allowed_dist;
result.translation += allowed_translation; result.translation += allowed_translation;
translation_remaining -= allowed_translation; translation_remaining -= allowed_translation;
@@ -271,7 +270,6 @@ impl KinematicCharacterController {
translation_remaining -= allowed_translation; translation_remaining -= allowed_translation;
} }
} }
} else { } else {
// No interference along the path. // No interference along the path.
result.translation += translation_remaining; result.translation += translation_remaining;
@@ -422,13 +420,11 @@ impl KinematicCharacterController {
kinematic_parent.velocity_at_point(&contact_point); kinematic_parent.velocity_at_point(&contact_point);
let normal_target_mvt = target_vel.dot(&normal) * dt; let normal_target_mvt = target_vel.dot(&normal) * dt;
let normal_current_mvt = let normal_current_mvt = translation_remaining.dot(&normal);
translation_remaining.dot(&normal);
manifold_center += contact_point.coords; manifold_center += contact_point.coords;
*translation_remaining += normal *translation_remaining +=
* (normal_target_mvt - normal_current_mvt); normal * (normal_target_mvt - normal_current_mvt);
} }
} }
@@ -488,13 +484,16 @@ impl KinematicCharacterController {
let climbing = self.up.dot(&slope_translation) >= 0.0; let climbing = self.up.dot(&slope_translation) >= 0.0;
climbing climbing
.then(||(angle_with_floor <= self.max_slope_climb_angle) // Are we allowed to climb? .then(|| {
.then_some(horizontal_translation )) (angle_with_floor <= self.max_slope_climb_angle) // Are we allowed to climb?
.unwrap_or_else(|| (angle_with_floor >= self.min_slope_slide_angle)// Are we allowed to slide? .then_some(horizontal_translation)
})
.unwrap_or_else(|| {
(angle_with_floor >= self.min_slope_slide_angle) // Are we allowed to slide?
.then_some(slope_translation) .then_some(slope_translation)
.unwrap_or(horizontal_translation) .unwrap_or(horizontal_translation)
.into()) .into()
})
} }
fn split_into_components(&self, translation: &Vector<Real>) -> [Vector<Real>; 2] { fn split_into_components(&self, translation: &Vector<Real>) -> [Vector<Real>; 2] {
@@ -503,7 +502,6 @@ impl KinematicCharacterController {
[vertical_translation, horizontal_translation] [vertical_translation, horizontal_translation]
} }
fn compute_dims(&self, character_shape: &dyn Shape) -> Vector2<Real> { fn compute_dims(&self, character_shape: &dyn Shape) -> Vector2<Real> {
let extents = character_shape.compute_local_aabb().extents(); let extents = character_shape.compute_local_aabb().extents();
let up_extent = extents.dot(&self.up); let up_extent = extents.dot(&self.up);
@@ -550,8 +548,10 @@ impl KinematicCharacterController {
let shifted_character_pos = Translation::from(*self.up * max_height) * character_pos; let shifted_character_pos = Translation::from(*self.up * max_height) * character_pos;
let horizontal_dir = match (*translation_remaining - *self.up * translation_remaining.dot(&self.up)) let horizontal_dir = match (*translation_remaining
.try_normalize(1.0e-5) { - *self.up * translation_remaining.dot(&self.up))
.try_normalize(1.0e-5)
{
Some(dir) => dir, Some(dir) => dir,
None => return false, None => return false,
}; };
@@ -602,13 +602,12 @@ impl KinematicCharacterController {
false, false,
filter, filter,
) { ) {
let [vertical_slope_translation, horizontal_slope_translation] = let [vertical_slope_translation, horizontal_slope_translation] = self
self.split_into_components(translation_remaining) .split_into_components(translation_remaining)
.map(|remaining| subtract_hit(remaining, &hit, offset)); .map(|remaining| subtract_hit(remaining, &hit, offset));
let slope_translation = horizontal_slope_translation + vertical_slope_translation; let slope_translation = horizontal_slope_translation + vertical_slope_translation;
let angle_with_floor = self.up.angle(&hit.normal1); let angle_with_floor = self.up.angle(&hit.normal1);
let climbing = self.up.dot(&slope_translation) >= 0.0; let climbing = self.up.dot(&slope_translation) >= 0.0;
@@ -623,8 +622,7 @@ impl KinematicCharacterController {
.cast_shape( .cast_shape(
bodies, bodies,
colliders, colliders,
&(Translation::from(horizontal_dir * min_width) &(Translation::from(horizontal_dir * min_width) * shifted_character_pos),
* shifted_character_pos),
&-self.up, &-self.up,
character_shape, character_shape,
max_height, max_height,