bevy_rapier2d/dynamics/
fixed_joint.rsuse crate::dynamics::{GenericJoint, GenericJointBuilder};
use crate::math::{Rot, Vect};
use rapier::dynamics::JointAxesMask;
use super::TypedJoint;
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(transparent)]
pub struct FixedJoint {
pub data: GenericJoint,
}
impl Default for FixedJoint {
fn default() -> Self {
FixedJoint::new()
}
}
impl FixedJoint {
#[must_use]
pub fn new() -> Self {
let data = GenericJointBuilder::new(JointAxesMask::LOCKED_FIXED_AXES).build();
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_basis1(&self) -> Rot {
self.data.local_basis1()
}
pub fn set_local_basis1(&mut self, local_basis: Rot) -> &mut Self {
self.data.set_local_basis1(local_basis);
self
}
#[must_use]
pub fn local_basis2(&self) -> Rot {
self.data.local_basis2()
}
pub fn set_local_basis2(&mut self, local_basis: Rot) -> &mut Self {
self.data.set_local_basis2(local_basis);
self
}
#[must_use]
pub fn local_anchor1(&self) -> Vect {
self.data.local_anchor1()
}
pub fn set_local_anchor1(&mut self, anchor1: Vect) -> &mut Self {
self.data.set_local_anchor1(anchor1);
self
}
#[must_use]
pub fn local_anchor2(&self) -> Vect {
self.data.local_anchor2()
}
pub fn set_local_anchor2(&mut self, anchor2: Vect) -> &mut Self {
self.data.set_local_anchor2(anchor2);
self
}
}
impl From<FixedJoint> for GenericJoint {
fn from(joint: FixedJoint) -> GenericJoint {
joint.data
}
}
#[derive(Copy, Clone, Debug, PartialEq, Default)]
pub struct FixedJointBuilder(FixedJoint);
impl FixedJointBuilder {
pub fn new() -> Self {
Self(FixedJoint::new())
}
#[must_use]
pub fn local_basis1(mut self, local_basis: Rot) -> Self {
self.0.set_local_basis1(local_basis);
self
}
#[must_use]
pub fn local_basis2(mut self, local_basis: Rot) -> Self {
self.0.set_local_basis2(local_basis);
self
}
#[must_use]
pub fn local_anchor1(mut self, anchor1: Vect) -> Self {
self.0.set_local_anchor1(anchor1);
self
}
#[must_use]
pub fn local_anchor2(mut self, anchor2: Vect) -> Self {
self.0.set_local_anchor2(anchor2);
self
}
#[must_use]
pub fn build(self) -> FixedJoint {
self.0
}
}
impl From<FixedJointBuilder> for TypedJoint {
fn from(joint: FixedJointBuilder) -> TypedJoint {
joint.0.into()
}
}
impl From<FixedJoint> for TypedJoint {
fn from(joint: FixedJoint) -> TypedJoint {
TypedJoint::FixedJoint(joint)
}
}