use crate::dynamics::RigidBodySet;
use crate::geometry::{ColliderHandle, ColliderSet, ContactManifold, Shape, ShapeCastHit};
use crate::math::{Isometry, Point, Real, UnitVector, Vector};
use crate::pipeline::{QueryFilter, QueryFilterFlags, QueryPipeline};
use crate::utils;
use na::{RealField, Vector2};
use parry::bounding_volume::BoundingVolume;
use parry::math::Translation;
use parry::query::details::ShapeCastOptions;
use parry::query::{DefaultQueryDispatcher, PersistentQueryDispatcher};
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
/// A length measure used for various options of a character controller.
pub enum CharacterLength {
/// The length is specified relative to some of the character shape’s size.
///
/// For example setting `CharacterAutostep::max_height` to `CharacterLength::Relative(0.1)`
/// for a shape with a height equal to 20.0 will result in a maximum step height
/// of `0.1 * 20.0 = 2.0`.
Relative(Real),
/// The length is specified as an absolute value, independent from the character shape’s size.
///
/// For example setting `CharacterAutostep::max_height` to `CharacterLength::Relative(0.1)`
/// for a shape with a height equal to 20.0 will result in a maximum step height
/// of `0.1` (the shape height is ignored in for this value).
Absolute(Real),
}
impl CharacterLength {
/// Returns `self` with its value changed by the closure `f` if `self` is the `Self::Absolute`
/// variant.
pub fn map_absolute(self, f: impl FnOnce(Real) -> Real) -> Self {
if let Self::Absolute(value) = self {
Self::Absolute(f(value))
} else {
self
}
}
/// Returns `self` with its value changed by the closure `f` if `self` is the `Self::Relative`
/// variant.
pub fn map_relative(self, f: impl FnOnce(Real) -> Real) -> Self {
if let Self::Relative(value) = self {
Self::Relative(f(value))
} else {
self
}
}
fn eval(self, value: Real) -> Real {
match self {
Self::Relative(x) => value * x,
Self::Absolute(x) => x,
}
}
}
#[derive(Debug)]
struct HitInfo {
toi: ShapeCastHit,
is_wall: bool,
is_nonslip_slope: bool,
}
/// Configuration for the auto-stepping character controller feature.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct CharacterAutostep {
/// The maximum step height a character can automatically step over.
pub max_height: CharacterLength,
/// The minimum width of free space that must be available after stepping on a stair.
pub min_width: CharacterLength,
/// Can the character automatically step over dynamic bodies too?
pub include_dynamic_bodies: bool,
}
impl Default for CharacterAutostep {
fn default() -> Self {
Self {
max_height: CharacterLength::Relative(0.25),
min_width: CharacterLength::Relative(0.5),