use bevy::prelude::*;
use rapier::dynamics::{ImpulseJointHandle, MultibodyJointHandle};
pub use rapier::dynamics::{JointAxesMask, JointAxis, MotorModel};
use super::{FixedJoint, GenericJoint, PrismaticJoint, RevoluteJoint, RopeJoint, SpringJoint};
#[cfg(feature = "dim3")]
use super::SphericalJoint;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum TypedJoint {
FixedJoint(FixedJoint),
GenericJoint(GenericJoint),
PrismaticJoint(PrismaticJoint),
RevoluteJoint(RevoluteJoint),
RopeJoint(RopeJoint),
#[cfg(feature = "dim3")]
SphericalJoint(SphericalJoint),
SpringJoint(SpringJoint),
}
impl AsMut<GenericJoint> for TypedJoint {
fn as_mut(&mut self) -> &mut GenericJoint {
match self {
TypedJoint::FixedJoint(ref mut j) => &mut j.data,
TypedJoint::GenericJoint(ref mut j) => j,
TypedJoint::PrismaticJoint(ref mut j) => &mut j.data,
TypedJoint::RevoluteJoint(ref mut j) => &mut j.data,
TypedJoint::RopeJoint(ref mut j) => &mut j.data,
#[cfg(feature = "dim3")]
TypedJoint::SphericalJoint(ref mut j) => &mut j.data,
TypedJoint::SpringJoint(ref mut j) => &mut j.data,
}
}
}
impl AsRef<GenericJoint> for TypedJoint {
fn as_ref(&self) -> &GenericJoint {
match self {
TypedJoint::FixedJoint(j) => &j.data,
TypedJoint::GenericJoint(j) => j,
TypedJoint::PrismaticJoint(j) => &j.data,
TypedJoint::RevoluteJoint(j) => &j.data,
TypedJoint::RopeJoint(j) => &j.data,
#[cfg(feature = "dim3")]
TypedJoint::SphericalJoint(j) => &j.data,
TypedJoint::SpringJoint(j) => &j.data,
}
}
}
#[derive(Copy, Clone, Debug, Component)]
pub struct RapierImpulseJointHandle(pub ImpulseJointHandle);
#[derive(Copy, Clone, Debug, Component)]
pub struct RapierMultibodyJointHandle(pub MultibodyJointHandle);
#[derive(Copy, Clone, Debug, PartialEq, Component)]
pub struct ImpulseJoint {
pub parent: Entity,
pub data: TypedJoint,
}
impl ImpulseJoint {
pub fn new(parent: Entity, data: impl Into<TypedJoint>) -> Self {
Self {
parent,
data: data.into(),
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Component)]
pub struct MultibodyJoint {
pub parent: Entity,
pub data: TypedJoint,
}
impl MultibodyJoint {
pub fn new(parent: Entity, data: TypedJoint) -> Self {
Self { parent, data }
}
}