pub struct DistanceConstraint {
pub body_a: BodyHandle,
pub body_b: BodyHandle,
pub anchor_a: Vec2,
pub anchor_b: Vec2,
pub rest_length: f32,
pub compliance: f32,
/* private fields */
}Expand description
Maintain a fixed distance between two local anchor points on two bodies. With compliance = 0 this is a rigid rod; compliance > 0 gives spring behavior.
Fields§
§body_a: BodyHandle§body_b: BodyHandle§anchor_a: Vec2§anchor_b: Vec2§rest_length: f32§compliance: f320.0 = rigid rod, >0 = soft spring (XPBD compliance).
Implementations§
Source§impl DistanceConstraint
impl DistanceConstraint
pub fn new( body_a: BodyHandle, anchor_a: Vec2, body_b: BodyHandle, anchor_b: Vec2, rest_length: f32, ) -> Self
Sourcepub fn rigid_rod(
body_a: BodyHandle,
anchor_a: Vec2,
body_b: BodyHandle,
anchor_b: Vec2,
rest_length: f32,
) -> Self
pub fn rigid_rod( body_a: BodyHandle, anchor_a: Vec2, body_b: BodyHandle, anchor_b: Vec2, rest_length: f32, ) -> Self
Create a rigid rod (exact distance, zero compliance).
Sourcepub fn soft(
body_a: BodyHandle,
anchor_a: Vec2,
body_b: BodyHandle,
anchor_b: Vec2,
rest_length: f32,
compliance: f32,
) -> Self
pub fn soft( body_a: BodyHandle, anchor_a: Vec2, body_b: BodyHandle, anchor_b: Vec2, rest_length: f32, compliance: f32, ) -> Self
Create a soft spring (positive compliance = 1/k).
pub fn with_compliance(self, c: f32) -> Self
Trait Implementations§
Source§impl Clone for DistanceConstraint
impl Clone for DistanceConstraint
Source§fn clone(&self) -> DistanceConstraint
fn clone(&self) -> DistanceConstraint
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Constraint for DistanceConstraint
impl Constraint for DistanceConstraint
Source§fn compute_cdot(&self, bodies: &HashMap<BodyHandle, BodyState>) -> f32
fn compute_cdot(&self, bodies: &HashMap<BodyHandle, BodyState>) -> f32
Compute the velocity constraint violation (Cdot = J * v).
Source§fn compute_c(&self, bodies: &HashMap<BodyHandle, BodyState>) -> f32
fn compute_c(&self, bodies: &HashMap<BodyHandle, BodyState>) -> f32
Compute the position constraint violation (C).
Source§fn get_compliance(&self) -> f32
fn get_compliance(&self) -> f32
XPBD compliance (inverse stiffness). 0 = rigid.
Source§fn effective_mass(&self, bodies: &HashMap<BodyHandle, BodyState>) -> f32
fn effective_mass(&self, bodies: &HashMap<BodyHandle, BodyState>) -> f32
Compute effective constraint mass (1 / (J M^-1 J^T)).
Source§fn apply_impulse(
&self,
bodies: &mut HashMap<BodyHandle, BodyState>,
lambda: f32,
)
fn apply_impulse( &self, bodies: &mut HashMap<BodyHandle, BodyState>, lambda: f32, )
Apply the corrective impulse to body states.
Source§fn accumulated_impulse(&self) -> f32
fn accumulated_impulse(&self) -> f32
Accumulated impulse for warm starting.
fn reset_accumulated(&mut self)
fn add_accumulated(&mut self, d: f32)
Source§fn body_handles(&self) -> Vec<BodyHandle>
fn body_handles(&self) -> Vec<BodyHandle>
Bodies involved in this constraint.
Source§fn bias(&self, bodies: &HashMap<BodyHandle, BodyState>, dt: f32) -> f32
fn bias(&self, bodies: &HashMap<BodyHandle, BodyState>, dt: f32) -> f32
Baumgarte position bias.
Source§fn prepare(&mut self, _bodies: &HashMap<BodyHandle, BodyState>, _dt: f32)
fn prepare(&mut self, _bodies: &HashMap<BodyHandle, BodyState>, _dt: f32)
Prepare the constraint for the current step (pre-compute cached values).
Source§fn solve_velocity(
&mut self,
bodies: &mut HashMap<BodyHandle, BodyState>,
dt: f32,
)
fn solve_velocity( &mut self, bodies: &mut HashMap<BodyHandle, BodyState>, dt: f32, )
Solve velocity constraint (one iteration).
Source§fn solve_position(
&mut self,
bodies: &mut HashMap<BodyHandle, BodyState>,
dt: f32,
)
fn solve_position( &mut self, bodies: &mut HashMap<BodyHandle, BodyState>, dt: f32, )
Solve position constraint using XPBD (one sub-step).
Source§fn impulse_bounds(&self) -> (f32, f32)
fn impulse_bounds(&self) -> (f32, f32)
Whether this constraint has an upper/lower impulse clamp.
Auto Trait Implementations§
impl Freeze for DistanceConstraint
impl RefUnwindSafe for DistanceConstraint
impl Send for DistanceConstraint
impl Sync for DistanceConstraint
impl Unpin for DistanceConstraint
impl UnsafeUnpin for DistanceConstraint
impl UnwindSafe for DistanceConstraint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.