pub struct Joint { /* private fields */ }Implementations§
Source§impl Joint
impl Joint
pub fn peak_load(&self) -> JointLoad
pub fn bodies(&self) -> [RigidBodyHandle; 2]
pub fn description(&self) -> JointDesc
Sourcepub fn set_motor(
&mut self,
motor: Option<JointMotor>,
) -> Result<(), PhysicsError>
pub fn set_motor( &mut self, motor: Option<JointMotor>, ) -> Result<(), PhysicsError>
Replaces the motor transactionally, preserving the existing error type.
Use Self::set_limits_and_motor for field-specific errors.
Sourcepub fn set_limits(
&mut self,
limits: Option<[f32; 2]>,
) -> Result<(), PhysicsError>
pub fn set_limits( &mut self, limits: Option<[f32; 2]>, ) -> Result<(), PhysicsError>
Replaces angular limits transactionally, preserving the existing error type.
Use Self::set_limits_and_motor for field-specific errors.
Sourcepub fn set_limits_and_motor(
&mut self,
limits: Option<[f32; 2]>,
motor: Option<JointMotor>,
) -> Result<(), JointValidationError>
pub fn set_limits_and_motor( &mut self, limits: Option<[f32; 2]>, motor: Option<JointMotor>, ) -> Result<(), JointValidationError>
Replaces angular limits and the motor together, or changes nothing.
None removes the corresponding setting. Nonempty settings require a
hinge; finite limits must satisfy -pi <= lower <= upper <= pi. Equal
endpoints are allowed. Motor bounds are checked by JointMotor::validate.
Position targets outside the limits retain the solver’s target clamping.
A rejected edit leaves the description and solver state intact. An identical edit does not wake the bodies or invalidate cached impulses. An accepted change uses the existing dirty flag so the next physics step clears cached impulses and wakes connected bodies. Handles, anchors and the captured reference rotation are preserved.
use ferravex_physics::{d2, JointMotor};
let mut world = d2::PhysicsWorld::default();
let anchor = world.insert_body(d2::RigidBodyBuilder::fixed()).unwrap();
let rotor = world.add_box([0.; 2], [0.5, 0.2], true);
let handle = world.insert_joint(anchor, rotor, d2::JointBuilder::hinge()).unwrap();
let joint = world.joints.get_mut(handle).unwrap();
joint.set_limits_and_motor(
Some([-0.6, 0.8]), Some(JointMotor::position(0.5, 20., 8., 80.)),
).unwrap();
let before = joint.description();
assert!(joint.set_limits_and_motor(Some([1., -1.]), None).is_err());
assert_eq!(joint.description(), before);
world.step(1. / 120.);