use crate::dynamics::joint::{GenericJoint, GenericJointBuilder, JointAxesMask};
use crate::dynamics::{JointAxis, MotorModel};
use crate::math::{Point, Real, UnitVector};
use super::{JointLimits, JointMotor};
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(transparent)]
pub struct RopeJoint {
pub data: GenericJoint,
}
impl RopeJoint {
pub fn new() -> Self {
let data = GenericJointBuilder::new(JointAxesMask::FREE_FIXED_AXES)
.coupled_axes(JointAxesMask::LIN_AXES)
.build();
Self { data }
}
pub fn data(&self) -> &GenericJoint {
&self.data
}
pub fn contacts_enabled(&self) -> bool {
self.data.contacts_enabled
}
pub fn set_contacts_enabled(&mut self, enabled: bool) -> &mut Self {
self.data.set_contacts_enabled(enabled);
self
}
#[must_use]
pub fn local_anchor1(&self) -> Point<Real> {
self.data.local_anchor1()
}
pub fn set_local_anchor1(&mut self, anchor1: Point<Real>) -> &mut Self {
self.data.set_local_anchor1(anchor1);
self
}
#[must_use]
pub fn local_anchor2(&self) -> Point<Real> {
self.data.local_anchor2()
}
pub fn set_local_anchor2(&mut self, anchor2: Point<Real>) -> &mut Self {
self.data.set_local_anchor2(anchor2);
self
}
#[must_use]
pub fn local_axis1(&self) -> UnitVector<Real> {
self.data.local_axis1()
}
pub fn set_local_axis1(&mut self, axis1: UnitVector<Real>) -> &mut Self {
self.data.set_local_axis1(axis1);
self
}
#[must_use]
pub fn local_axis2(&self) -> UnitVector<Real> {
self.data.local_axis2()
}
pub fn set_local_axis2(&mut self, axis2: UnitVector<Real>) -> &mut Self {
self.data.set_local_axis2(axis2);
self
}
#[must_use]
pub fn motor(&self, axis: JointAxis) -> Option<&JointMotor> {
self.data.motor(axis)
}
pub fn set_motor_model(&mut self, model: MotorModel) -> &mut Self {
self.data.set_motor_model(JointAxis::X, model);
self.data.set_motor_model(JointAxis::Y, model);
#[cfg(feature = "dim3")]
self.data.set_motor_model(JointAxis::Z, model);
self
}
pub fn set_motor_velocity(&mut self, target_vel: Real, factor: Real) -> &mut Self {
self.data
.set_motor_velocity(JointAxis::X, target_vel, factor);
self.data
.set_motor_velocity(JointAxis::Y, target_vel, factor);
#[cfg(feature = "dim3")]
self.data
.set_motor_velocity(JointAxis::Z, target_vel, factor);
self
}
pub fn set_motor_position(
&mut self,
target_pos: Real,
stiffness: Real,
damping: Real,
) -> &mut Self {
self.data
.set_motor_position(JointAxis::X, target_pos, stiffness, damping);
self.data
.set_motor_position(JointAxis::Y, target_pos, stiffness, damping);
#[cfg(feature = "dim3")]
self.data
.set_motor_position(JointAxis::Z, target_pos, stiffness, damping);
self
}
pub fn set_motor(
&mut self,
target_pos: Real,
target_vel: Real,
stiffness: Real,
damping: Real,
) -> &mut Self {
self.data
.set_motor(JointAxis::X, target_pos, target_vel, stiffness, damping);
self.data
.set_motor(JointAxis::Y, target_pos, target_vel, stiffness, damping);
#[cfg(feature = "dim3")]
self.data
.set_motor(JointAxis::Y, target_pos, target_vel, stiffness, damping);
self
}
pub fn set_motor_max_force(&mut self, max_force: Real) -> &mut Self {
self.data.set_motor_max_force(JointAxis::X, max_force);
self.data.set_motor_max_force(JointAxis::Y, max_force);
#[cfg(feature = "dim3")]
self.data.set_motor_max_force(JointAxis::Z, max_force);
self
}
#[must_use]
pub fn limits(&self, axis: JointAxis) -> Option<&JointLimits<Real>> {
self.data.limits(axis)
}
pub fn set_limits(&mut self, limits: [Real; 2]) -> &mut Self {
self.data.set_limits(JointAxis::X, limits);
self.data.set_limits(JointAxis::Y, limits);
#[cfg(feature = "dim3")]
self.data.set_limits(JointAxis::Z, limits);
self
}
}
impl Into<GenericJoint> for RopeJoint {
fn into(self) -> GenericJoint {
self.data
}
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct RopeJointBuilder(pub RopeJoint);
impl RopeJointBuilder {
pub fn new() -> Self {
Self(RopeJoint::new())
}
#[must_use]
pub fn contacts_enabled(mut self, enabled: bool) -> Self {
self.0.set_contacts_enabled(enabled);
self
}
#[must_use]
pub fn local_anchor1(mut self, anchor1: Point<Real>) -> Self {
self.0.set_local_anchor1(anchor1);
self
}
#[must_use]
pub fn local_anchor2(mut self, anchor2: Point<Real>) -> Self {
self.0.set_local_anchor2(anchor2);
self
}
#[must_use]
pub fn local_axis1(mut self, axis1: UnitVector<Real>) -> Self {
self.0.set_local_axis1(axis1);
self
}
#[must_use]
pub fn local_axis2(mut self, axis2: UnitVector<Real>) -> Self {
self.0.set_local_axis2(axis2);
self
}
#[must_use]
pub fn motor_model(mut self, model: MotorModel) -> Self {
self.0.set_motor_model(model);
self
}
#[must_use]
pub fn motor_velocity(mut self, target_vel: Real, factor: Real) -> Self {
self.0.set_motor_velocity(target_vel, factor);
self
}
#[must_use]
pub fn motor_position(mut self, target_pos: Real, stiffness: Real, damping: Real) -> Self {
self.0.set_motor_position(target_pos, stiffness, damping);
self
}
#[must_use]
pub fn set_motor(
mut self,
target_pos: Real,
target_vel: Real,
stiffness: Real,
damping: Real,
) -> Self {
self.0.set_motor(target_pos, target_vel, stiffness, damping);
self
}
#[must_use]
pub fn motor_max_force(mut self, max_force: Real) -> Self {
self.0.set_motor_max_force(max_force);
self
}
#[must_use]
pub fn limits(mut self, limits: [Real; 2]) -> Self {
self.0.set_limits(limits);
self
}
#[must_use]
pub fn build(self) -> RopeJoint {
self.0
}
}
impl Into<GenericJoint> for RopeJointBuilder {
fn into(self) -> GenericJoint {
self.0.into()
}
}