aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Crozet <sebcrozet@dimforge.com>2024-04-21 19:40:39 +0200
committerSébastien Crozet <sebastien@crozet.re>2024-04-30 23:10:46 +0200
commit33dd38016ccf3c4ad8e874d75e51fbc20dd060da (patch)
tree6b4fbf2a3cda2b82d05a96cb0acb1713e4cd087f
parentf58b4f7c195ab7acf0778ea65c46ebf37ac8188c (diff)
downloadrapier-33dd38016ccf3c4ad8e874d75e51fbc20dd060da.tar.gz
rapier-33dd38016ccf3c4ad8e874d75e51fbc20dd060da.tar.bz2
rapier-33dd38016ccf3c4ad8e874d75e51fbc20dd060da.zip
feat: add a capsule collider constructor from endpoints.
-rw-r--r--examples2d/s2d_confined.rs16
-rw-r--r--src/geometry/collider.rs11
2 files changed, 20 insertions, 7 deletions
diff --git a/examples2d/s2d_confined.rs b/examples2d/s2d_confined.rs
index 46cae86..8b75a3d 100644
--- a/examples2d/s2d_confined.rs
+++ b/examples2d/s2d_confined.rs
@@ -19,16 +19,20 @@ pub fn init_world(testbed: &mut Testbed) {
* Ground
*/
let collider =
- ColliderBuilder::capsule(point![-10.5, 0.0], point![10.5, 0.0], radius).friction(friction);
+ ColliderBuilder::capsule_from_endpoints(point![-10.5, 0.0], point![10.5, 0.0], radius)
+ .friction(friction);
colliders.insert(collider);
- let collider = ColliderBuilder::capsule(point![-10.5, 0.0], point![-10.5, 20.5], radius)
- .friction(friction);
+ let collider =
+ ColliderBuilder::capsule_from_endpoints(point![-10.5, 0.0], point![-10.5, 20.5], radius)
+ .friction(friction);
colliders.insert(collider);
let collider =
- ColliderBuilder::capsule(point![10.5, 0.0], point![10.5, 20.5], radius).friction(friction);
+ ColliderBuilder::capsule_from_endpoints(point![10.5, 0.0], point![10.5, 20.5], radius)
+ .friction(friction);
colliders.insert(collider);
- let collider = ColliderBuilder::capsule(point![-10.5, 20.5], point![10.5, 20.5], radius)
- .friction(friction);
+ let collider =
+ ColliderBuilder::capsule_from_endpoints(point![-10.5, 20.5], point![10.5, 20.5], radius)
+ .friction(friction);
colliders.insert(collider);
/*
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs
index 4ddd44e..c83535e 100644
--- a/src/geometry/collider.rs
+++ b/src/geometry/collider.rs
@@ -583,6 +583,15 @@ impl ColliderBuilder {
Self::new(SharedShape::round_cuboid(hx, hy, border_radius))
}
+ /// Initialize a new collider builder with a capsule defined from its endpoints.
+ ///
+ /// See also [`ColliderBuilder::capsule_x`], [`ColliderBuilder::capsule_y`], and
+ /// [`ColliderBuilder::capsule_z`], for a simpler way to build capsules with common
+ /// orientations.
+ pub fn capsule_from_endpoints(a: Point<Real>, b: Point<Real>, radius: Real) -> Self {
+ Self::new(SharedShape::capsule(a, b, radius))
+ }
+
/// Initialize a new collider builder with a capsule shape aligned with the `x` axis.
pub fn capsule_x(half_height: Real, radius: Real) -> Self {
Self::new(SharedShape::capsule_x(half_height, radius))
@@ -781,7 +790,7 @@ impl ColliderBuilder {
/// The default density used by the collider builder.
pub fn default_density() -> Real {
- 1.0
+ 100.0
}
/// Sets an arbitrary user-defined 128-bit integer associated to the colliders built by this builder.