use crate::scene::legacy_physics::dim3::body::RigidBodyContainer;
use crate::scene::legacy_physics::dim3::collider::ColliderContainer;
use crate::scene::legacy_physics::dim3::joint::JointContainer;
use rapier3d::{
dynamics::{CCDSolver, IntegrationParameters, IslandManager},
geometry::{BroadPhase, NarrowPhase},
pipeline::EventHandler,
};
use rg3d_core::visitor::prelude::*;
use std::fmt::{Debug, Formatter};
pub type NativeRigidBodyHandle = rapier3d::dynamics::RigidBodyHandle;
pub type NativeJointHandle = rapier3d::dynamics::JointHandle;
pub type NativeColliderHandle = rapier3d::geometry::ColliderHandle;
pub type Vector<N> = rapier3d::prelude::Vector<N>;
pub type Point<N> = rapier3d::prelude::Point<N>;
pub type NativeRay = rapier3d::prelude::Ray;
pub type Isometry<N> = rapier3d::prelude::Isometry<N>;
pub type Translation<N> = rapier3d::prelude::Translation<N>;
pub type AngVector<N> = rapier3d::prelude::AngVector<N>;
pub type Rotation<N> = rapier3d::prelude::Rotation<N>;
pub mod body;
pub mod collider;
pub mod desc;
pub mod joint;
macro_rules! define_rapier_handle {
($(#[$meta:meta])* $type_name:ident) => {
$(#[$meta])*
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct $type_name(pub rg3d_core::uuid::Uuid);
impl From<rg3d_core::uuid::Uuid> for $type_name {
fn from(inner: rg3d_core::uuid::Uuid) -> Self {
Self(inner)
}
}
impl From<$type_name> for rg3d_core::uuid::Uuid {
fn from(v: $type_name) -> Self {
v.0
}
}
impl Visit for $type_name {
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
visitor.enter_region(name)?;
self.0.visit("Id", visitor)?;
visitor.leave_region()
}
}
};
}
define_rapier_handle!(
RigidBodyHandle
);
define_rapier_handle!(
ColliderHandle
);
define_rapier_handle!(
JointHandle
);
pub struct PhysicsWorld {
pub gravity: Vector<f32>,
pub integration_parameters: IntegrationParameters,
pub broad_phase: BroadPhase,
pub narrow_phase: NarrowPhase,
pub ccd_solver: CCDSolver,
pub islands: IslandManager,
pub bodies: RigidBodyContainer,
pub colliders: ColliderContainer,
pub joints: JointContainer,
pub event_handler: Box<dyn EventHandler>,
}
impl Debug for PhysicsWorld {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Physics")
}
}
impl Default for PhysicsWorld {
fn default() -> Self {
Self::new()
}
}
impl PhysicsWorld {
pub fn new() -> Self {
Self {
gravity: Vector::new(0.0, -9.81, 0.0),
integration_parameters: IntegrationParameters::default(),
broad_phase: BroadPhase::new(),
narrow_phase: NarrowPhase::new(),
ccd_solver: CCDSolver::new(),
islands: IslandManager::new(),
bodies: RigidBodyContainer::new(),
colliders: ColliderContainer::new(),
joints: JointContainer::new(),
event_handler: Box::new(()),
}
}
}