From faec3d5d46c88e2949179dd2789899e5cf26ed48 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 12 Oct 2020 18:33:58 +0200 Subject: Start adding cylinders. --- src/dynamics/mass_properties_capsule.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/dynamics/mass_properties_capsule.rs') diff --git a/src/dynamics/mass_properties_capsule.rs b/src/dynamics/mass_properties_capsule.rs index 5f08958..77ba96d 100644 --- a/src/dynamics/mass_properties_capsule.rs +++ b/src/dynamics/mass_properties_capsule.rs @@ -1,7 +1,7 @@ use crate::dynamics::MassProperties; #[cfg(feature = "dim3")] use crate::geometry::Capsule; -use crate::math::{Point, PrincipalAngularInertia, Vector}; +use crate::math::{Point, PrincipalAngularInertia, Rotation, Vector}; impl MassProperties { fn cylinder_y_volume_unit_inertia( @@ -57,4 +57,16 @@ impl MassProperties { ) } } + + #[cfg(feature = "dim3")] + pub(crate) fn from_cylinder(density: f32, half_height: f32, radius: f32) -> Self { + let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius); + + Self::with_principal_inertia_frame( + Point::origin(), + cyl_vol * density, + cyl_unit_i * density, + Rotation::identity(), + ) + } } -- cgit From 8ee3c703d666785207c7db47e3881f2ca9723105 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 13 Oct 2020 18:39:45 +0200 Subject: Fix cylinder inertia tensor computation. --- src/dynamics/mass_properties_capsule.rs | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'src/dynamics/mass_properties_capsule.rs') diff --git a/src/dynamics/mass_properties_capsule.rs b/src/dynamics/mass_properties_capsule.rs index 77ba96d..647cfc7 100644 --- a/src/dynamics/mass_properties_capsule.rs +++ b/src/dynamics/mass_properties_capsule.rs @@ -4,27 +4,6 @@ use crate::geometry::Capsule; use crate::math::{Point, PrincipalAngularInertia, Rotation, Vector}; impl MassProperties { - fn cylinder_y_volume_unit_inertia( - half_height: f32, - radius: f32, - ) -> (f32, PrincipalAngularInertia) { - #[cfg(feature = "dim2")] - { - Self::cuboid_volume_unit_inertia(Vector::new(radius, half_height)) - } - - #[cfg(feature = "dim3")] - { - let volume = half_height * radius * radius * std::f32::consts::PI * 2.0; - let sq_radius = radius * radius; - let sq_height = half_height * half_height * 4.0; - let off_principal = (sq_radius * 3.0 + sq_height) / 12.0; - - let inertia = Vector::new(off_principal, sq_radius / 2.0, off_principal); - (volume, inertia) - } - } - pub(crate) fn from_capsule(density: f32, a: Point, b: Point, radius: f32) -> Self { let half_height = (b - a).norm() / 2.0; let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius); @@ -57,16 +36,4 @@ impl MassProperties { ) } } - - #[cfg(feature = "dim3")] - pub(crate) fn from_cylinder(density: f32, half_height: f32, radius: f32) -> Self { - let (cyl_vol, cyl_unit_i) = Self::cylinder_y_volume_unit_inertia(half_height, radius); - - Self::with_principal_inertia_frame( - Point::origin(), - cyl_vol * density, - cyl_unit_i * density, - Rotation::identity(), - ) - } } -- cgit From 865ce8a8e5301b23ca474adaaffe8b43e725803e Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 20 Oct 2020 11:55:33 +0200 Subject: Collider shape: use a trait-object instead of an enum. --- src/dynamics/mass_properties_capsule.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/dynamics/mass_properties_capsule.rs') diff --git a/src/dynamics/mass_properties_capsule.rs b/src/dynamics/mass_properties_capsule.rs index 647cfc7..c4e039c 100644 --- a/src/dynamics/mass_properties_capsule.rs +++ b/src/dynamics/mass_properties_capsule.rs @@ -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, b: Point, 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(), ) } } -- cgit From 949e3f5384a366c3bff5415c5db4635e811a580e Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 20 Oct 2020 16:22:53 +0200 Subject: Fix many warnings. --- src/dynamics/mass_properties_capsule.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dynamics/mass_properties_capsule.rs') diff --git a/src/dynamics/mass_properties_capsule.rs b/src/dynamics/mass_properties_capsule.rs index c4e039c..cfd4345 100644 --- a/src/dynamics/mass_properties_capsule.rs +++ b/src/dynamics/mass_properties_capsule.rs @@ -1,7 +1,7 @@ use crate::dynamics::MassProperties; +use crate::math::Point; #[cfg(feature = "dim3")] -use crate::geometry::Capsule; -use crate::math::{Point, PrincipalAngularInertia, Rotation, Vector}; +use crate::math::Rotation; impl MassProperties { pub(crate) fn from_capsule(density: f32, half_height: f32, radius: f32) -> Self { -- cgit From 2b628f9580a826722346983ef42672d4e8dd8053 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 26 Oct 2020 15:58:30 +0100 Subject: Redefine capsules as a segment with a radius, allowing us to reuse the pfm_pfm_contact generator for it. --- src/dynamics/mass_properties_capsule.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/dynamics/mass_properties_capsule.rs') diff --git a/src/dynamics/mass_properties_capsule.rs b/src/dynamics/mass_properties_capsule.rs index cfd4345..dae6cfb 100644 --- a/src/dynamics/mass_properties_capsule.rs +++ b/src/dynamics/mass_properties_capsule.rs @@ -1,22 +1,24 @@ use crate::dynamics::MassProperties; use crate::math::Point; #[cfg(feature = "dim3")] -use crate::math::Rotation; +use crate::{geometry::Capsule, math::Rotation}; impl MassProperties { - pub(crate) fn from_capsule(density: f32, half_height: f32, radius: f32) -> Self { + pub(crate) fn from_capsule(density: f32, a: Point, b: Point, radius: f32) -> Self { + let half_height = (b - a).norm() / 2.0; 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(Point::origin(), cap_mass, cap_unit_i * cap_mass) + Self::new(local_com, cap_mass, cap_unit_i * cap_mass) } #[cfg(feature = "dim3")] @@ -25,11 +27,12 @@ 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( - Point::origin(), + local_com, cap_mass, cap_unit_i * cap_mass, - Rotation::identity(), + local_frame, ) } } -- cgit From 08930b1238c90bec16db84c50ac4ea7c9a1e0a5b Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 26 Oct 2020 16:36:07 +0100 Subject: Fix multiple warnings. --- src/dynamics/mass_properties_capsule.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dynamics/mass_properties_capsule.rs') diff --git a/src/dynamics/mass_properties_capsule.rs b/src/dynamics/mass_properties_capsule.rs index dae6cfb..3b1b214 100644 --- a/src/dynamics/mass_properties_capsule.rs +++ b/src/dynamics/mass_properties_capsule.rs @@ -1,7 +1,7 @@ use crate::dynamics::MassProperties; -use crate::math::Point; #[cfg(feature = "dim3")] -use crate::{geometry::Capsule, math::Rotation}; +use crate::geometry::Capsule; +use crate::math::Point; impl MassProperties { pub(crate) fn from_capsule(density: f32, a: Point, b: Point, radius: f32) -> Self { -- cgit