use crate::dynamics::{
MassProperties, RigidBodyActivation, RigidBodyCcd, RigidBodyChanges, RigidBodyColliders,
RigidBodyDamping, RigidBodyDominance, RigidBodyForces, RigidBodyIds, RigidBodyMassProps,
RigidBodyMassPropsFlags, RigidBodyPosition, RigidBodyType, RigidBodyVelocity,
};
use crate::geometry::{
Collider, ColliderHandle, ColliderMassProperties, ColliderParent, ColliderPosition,
ColliderShape,
};
use crate::math::{AngVector, Isometry, Point, Real, Rotation, Translation, Vector};
use crate::utils::{self, WAngularInertia, WCross};
use na::ComplexField;
use num::Zero;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
/// A rigid body.
///
/// To create a new rigid-body, use the `RigidBodyBuilder` structure.
#[derive(Debug, Clone)]
pub struct RigidBody {
pub rb_pos: RigidBodyPosition, // TODO ECS: public only for initial tests with bevy_rapier.
pub rb_mprops: RigidBodyMassProps, // TODO ECS: public only for initial tests with bevy_rapier.
pub rb_vels: RigidBodyVelocity, // TODO ECS: public only for initial tests with bevy_rapier.
pub rb_damping: RigidBodyDamping, // TODO ECS: public only for initial tests with bevy_rapier.
pub rb_forces: RigidBodyForces, // TODO ECS: public only for initial tests with bevy_rapier.
pub rb_ccd: RigidBodyCcd, // TODO ECS: public only for initial tests with bevy_rapier.
pub rb_ids: RigidBodyIds, // TODO ECS: public only for initial tests with bevy_rapier.
pub rb_colliders: RigidBodyColliders, // TODO ECS: public only for initial tests with bevy_rapier.
/// Whether or not this rigid-body is sleeping.
pub rb_activation: RigidBodyActivation, // TODO ECS: public only for initial tests with bevy_rapier.
pub changes: RigidBodyChanges, // TODO ECS: public only for initial tests with bevy_rapier.
/// The status of the body, governing how it is affected by external forces.
pub rb_type: RigidBodyType, // TODO ECS: public only for initial tests with bevy_rapier
/// The dominance group this rigid-body is part of.
pub rb_dominance: RigidBodyDominance,
/// User-defined data associated to this rigid-body.
pub user_data: u128,
}
impl RigidBody {
fn new() -> Self {
Self {
rb_pos: RigidBodyPosition::default(),
rb_mprops: RigidBodyMassProps::default(),
rb_vels: RigidBodyVelocity::default(),
rb_damping: RigidBodyDamping::default(),
rb_forces: RigidBodyForces::default(),
rb_ccd: RigidBodyCcd::default(),
rb_ids: RigidBodyIds::default(),
rb_colliders: RigidBodyColliders::default(),
rb_activation: RigidBodyActivation::new_active(),
changes: RigidBodyChanges::all(),
rb_type: RigidBodyType::Dynamic,
rb_dominance: RigidBodyDominance::default(),
user_data: 0,
}
}
pub(crate) fn reset_internal_references(&mut self) {
self.rb_colliders.0 = Vec::new();
self.rb_ids = Default::default();
}
pub fn user_data(&self) -> u128 {
self.user_data
}
pub fn set_user_data(&mut self, data: u128) {
self.user_data = data;
}
#[inline]
pub fn rb_activation(&self) -> &RigidBodyActivation {
&self.rb_activation
}
#[inline]
pub fn activation_mut(&mut self) -> &mut RigidBodyActivation {
&mut self.rb_activation
}
#[inline]
pub(crate) fn changes(&self) -> RigidBodyChanges {
self.changes
}
#[inline]
pub(crate) fn changes_mut_internal(&mut self) -> &mut RigidBodyChanges {
&mut self.changes
}
#[inline]
pub fn linear_damping(&self) -> Real {
self.rb_damping.linear_damping
}
#[inline]
pub fn set_linear_damping(&mut self, damping: Real) {
self.rb_damping.linear_damping = damping;
}
#[inline]
pub fn angular_damping(&self) -> Real {
self.rb_damping.angular_damping
}
#[inline]
pub fn set_angular_damping(&mut self, damping: Real) {
self.rb_damping.angular_damping = damping
}
/// The status of this rigid-body.
pub fn rb_type(&self) -> RigidBodyType {
self.rb_type
}
/// Sets the status of this rigid-body.
pub fn set_rb_type(&mut self, status: RigidBodyType) {
if status != self.rb_type {
self.changes.insert(RigidBodyChanges::TYPE);
self.rb_type = status;
}
}
/// The mass properties of this rigid-body.
#[inline]
pub fn mass_properties(&self) -> &MassProperties {