pub struct FootPlant { /* private fields */ }Expand description
Allocation-free presentation contact state. The caller supplies support queries and elapsed presentation time; this never changes body motion.
Implementations§
Source§impl FootPlant
impl FootPlant
Sourcepub fn new(
max_correction: f32,
half_life: f32,
) -> Result<FootPlant, AnimationError>
pub fn new( max_correction: f32, half_life: f32, ) -> Result<FootPlant, AnimationError>
Uses the original single cutoff: maximum correction distance, upward
normal component strictly above 0.5, and no contact-loss grace period.
Use Self::with_thresholds to opt into hysteresis.
Sourcepub fn with_thresholds(
max_correction: f32,
half_life: f32,
thresholds: FootPlantThresholds,
) -> Result<FootPlant, AnimationError>
pub fn with_thresholds( max_correction: f32, half_life: f32, thresholds: FootPlantThresholds, ) -> Result<FootPlant, AnimationError>
Creates a plant with validated hysteresis. Maximum correction must be
in 0.001..=10 world units and half-life in 0.001..=1 seconds. Invalid
or non-finite configuration returns AnimationError::InvalidPose.
See FootPlantThresholds for a compiling usage example and field limits.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Discards the anchor, normal, weight, grace timer and correction. The
unweighted target returns to the origin; use Self::reset on teleport.
Sourcepub fn reset(&mut self, animated: Vec3) -> Result<FootPose, AnimationError>
pub fn reset(&mut self, animated: Vec3) -> Result<FootPose, AnimationError>
Clears all contact history at a new animated position. A non-finite
position returns AnimationError::InvalidPose without changing state.
use ferravex_math::Vec3;
use ferravex_play::animation::FootPlant;
let mut foot = FootPlant::new(0.5, 0.05)?;
let pose = foot.reset(Vec3::X * 10.)?;
assert_eq!(pose.position, Vec3::X * 10.);
assert_eq!(pose.weight, 0.);
assert_eq!(foot.support(), None);
assert_eq!(foot.correction(), Vec3::ZERO);
foot.clear();
assert_eq!(foot.pose().position, Vec3::ZERO);Sourcepub fn support(&self) -> Option<u64>
pub fn support(&self) -> Option<u64>
Returns the accepted support, including while held during a grace period.
Sourcepub fn thresholds(&self) -> FootPlantThresholds
pub fn thresholds(&self) -> FootPlantThresholds
Returns the validated acquisition/retention configuration.
Sourcepub fn correction(&self) -> Vec3
pub fn correction(&self) -> Vec3
Weighted translation from the last positive-time update’s animated
position: (pose.position - animated) * pose.weight. Add this to that
animated position to apply the contact blend. Zero after clear/reset.
It is bounded by max_correction, subject to floating-point rounding.
Sourcepub fn update(
&mut self,
animated: Vec3,
contact: Option<FootContact>,
plant: bool,
dt: f32,
) -> Result<FootPose, AnimationError>
pub fn update( &mut self, animated: Vec3, contact: Option<FootContact>, plant: bool, dt: f32, ) -> Result<FootPose, AnimationError>
Updates presentation state with finite positions, a unit contact normal
(squared-length tolerance 0.001), and dt in 0..=0.25 seconds.
Invalid input leaves all state unchanged; zero time validates input but
holds all state, so a support delta is not consumed while paused.
Once acquired, an anchor follows the same support’s delta exactly once per positive-time update, independently of blend weight. Query position jitter does not move that anchor. If support motion takes the anchor out of range, a usable contact reanchors it within the correction limit.
Missing/marginal contact holds a bounded anchor for less than
release_delay seconds; absent queries imply no known support motion.
A valid contact resets that timer. plant = false, a different support,
or an out-of-range anchor bypasses the grace period. Release restores the
animated position/up normal immediately while the blend weight decays.