Collider shape: use a trait-object instead of an enum.
This commit is contained in:
@@ -91,7 +91,7 @@ impl MassProperties {
|
||||
}
|
||||
|
||||
#[cfg(feature = "dim3")]
|
||||
/// Reconstructs the inverse angular inertia tensor of the rigid body from its principal inertia values and axii.
|
||||
/// Reconstructs the inverse angular inertia tensor of the rigid body from its principal inertia values and axes.
|
||||
pub fn reconstruct_inverse_inertia_matrix(&self) -> Matrix3<f32> {
|
||||
let inv_principal_inertia = self.inv_principal_inertia_sqrt.map(|e| e * e);
|
||||
self.principal_inertia_local_frame.to_rotation_matrix()
|
||||
@@ -103,7 +103,7 @@ impl MassProperties {
|
||||
}
|
||||
|
||||
#[cfg(feature = "dim3")]
|
||||
/// Reconstructs the angular inertia tensor of the rigid body from its principal inertia values and axii.
|
||||
/// Reconstructs the angular inertia tensor of the rigid body from its principal inertia values and axes.
|
||||
pub fn reconstruct_inertia_matrix(&self) -> Matrix3<f32> {
|
||||
let principal_inertia = self.inv_principal_inertia_sqrt.map(|e| utils::inv(e * e));
|
||||
self.principal_inertia_local_frame.to_rotation_matrix()
|
||||
|
||||
@@ -4,21 +4,19 @@ use crate::geometry::Capsule;
|
||||
use crate::math::{Point, PrincipalAngularInertia, Rotation, Vector};
|
||||
|
||||
impl MassProperties {
|
||||
pub(crate) fn from_capsule(density: f32, a: Point<f32>, b: Point<f32>, radius: f32) -> Self {
|
||||
let half_height = (b - a).norm() / 2.0;
|
||||
pub(crate) fn from_capsule(density: f32, half_height: f32, radius: f32) -> Self {
|
||||
let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius);
|
||||
let (ball_vol, ball_unit_i) = Self::ball_volume_unit_angular_inertia(radius);
|
||||
let cap_vol = cyl_vol + ball_vol;
|
||||
let cap_mass = cap_vol * density;
|
||||
let mut cap_unit_i = cyl_unit_i + ball_unit_i;
|
||||
let local_com = na::center(&a, &b);
|
||||
|
||||
#[cfg(feature = "dim2")]
|
||||
{
|
||||
let h = half_height * 2.0;
|
||||
let extra = h * h * 0.5 + h * radius * 3.0 / 8.0;
|
||||
cap_unit_i += extra;
|
||||
Self::new(local_com, cap_mass, cap_unit_i * cap_mass)
|
||||
Self::new(Point::origin(), cap_mass, cap_unit_i * cap_mass)
|
||||
}
|
||||
|
||||
#[cfg(feature = "dim3")]
|
||||
@@ -27,12 +25,11 @@ impl MassProperties {
|
||||
let extra = h * h * 0.5 + h * radius * 3.0 / 8.0;
|
||||
cap_unit_i.x += extra;
|
||||
cap_unit_i.z += extra;
|
||||
let local_frame = Capsule::new(a, b, radius).rotation_wrt_y();
|
||||
Self::with_principal_inertia_frame(
|
||||
local_com,
|
||||
Point::origin(),
|
||||
cap_mass,
|
||||
cap_unit_i * cap_mass,
|
||||
local_frame,
|
||||
Rotation::identity(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user