use rapier::dynamics::{JointHandle, JointParams, RigidBodyHandle};
use rapier::geometry::ColliderHandle;
use rapier::math::{Isometry, Translation, Vector};
#[cfg(feature = "dim2")]
use rapier::na::UnitComplex;
#[cfg(feature = "dim3")]
use rapier::na::{Quaternion, UnitQuaternion};
use shipyard::EntityId;
#[derive(Debug)]
pub struct RigidBodyHandleComponent(RigidBodyHandle);
impl From<RigidBodyHandle> for RigidBodyHandleComponent {
fn from(handle: RigidBodyHandle) -> Self {
Self(handle)
}
}
impl RigidBodyHandleComponent {
pub fn handle(&self) -> RigidBodyHandle {
self.0
}
}
#[derive(Debug)]
pub struct ColliderHandleComponent(ColliderHandle);
impl From<ColliderHandle> for ColliderHandleComponent {
fn from(handle: ColliderHandle) -> Self {
Self(handle)
}
}
impl ColliderHandleComponent {
pub fn handle(&self) -> ColliderHandle {
self.0
}
}
#[derive(Debug)]
pub struct JointHandleComponent {
pub(crate) handle: JointHandle,
entity1: EntityId,
entity2: EntityId,
}
impl JointHandleComponent {
pub(crate) fn new(handle: JointHandle, entity1: EntityId, entity2: EntityId) -> Self {
Self {
handle,
entity1,
entity2,
}
}
pub fn handle(&self) -> JointHandle {
self.handle
}
pub fn entity1(&self) -> EntityId {
self.entity1
}
pub fn entity2(&self) -> EntityId {
self.entity2
}
}
pub struct JointBuilderComponent {
pub(crate) params: JointParams,
pub(crate) entity1: EntityId,
pub(crate) entity2: EntityId,
}
impl JointBuilderComponent {
pub fn new<J>(joint: J, entity1: EntityId, entity2: EntityId) -> Self
where
J: Into<JointParams>,
{
JointBuilderComponent {
params: joint.into(),
entity1,
entity2,
}
}
}
pub struct PhysicsInterpolationComponent(pub Option<Isometry<f32>>);
impl Default for PhysicsInterpolationComponent {
fn default() -> Self {
PhysicsInterpolationComponent(None)
}
}
impl PhysicsInterpolationComponent {
#[cfg(feature = "dim2")]
pub fn new(translation: Vector<f32>, rotation_angle: f32) -> Self {
Self(Some(Isometry::from_parts(
Translation::from(translation),
UnitComplex::new(rotation_angle),
)))
}
#[cfg(feature = "dim3")]
pub fn new(translation: Vector<f32>, rotation: Quaternion<f32>) -> Self {
Self(Some(Isometry::from_parts(
Translation::from(translation),
UnitQuaternion::from_quaternion(rotation),
)))
}
}