From ff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 6 Sep 2020 12:16:09 +0200 Subject: Move benchmark demos into their own directory. --- src/geometry/collider.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index aed76c8..2d55857 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -212,7 +212,7 @@ pub struct ColliderBuilder { /// The shape of the collider to be built. pub shape: Shape, /// The density of the collider to be built. - pub density: f32, + density: Option, /// The friction coefficient of the collider to be built. pub friction: f32, /// The restitution coefficient of the collider to be built. @@ -228,7 +228,7 @@ impl ColliderBuilder { pub fn new(shape: Shape) -> Self { Self { shape, - density: 1.0, + density: None, friction: Self::default_friction(), restitution: 0.0, delta: Isometry::identity(), @@ -236,6 +236,12 @@ impl ColliderBuilder { } } + /// The density of the collider being built. + pub fn get_density(&self) -> f32 { + let default_density = if self.is_sensor { 0.0 } else { 1.0 }; + self.density.unwrap_or(default_density) + } + /// Initialize a new collider builder with a ball shape defined by its radius. pub fn ball(radius: f32) -> Self { Self::new(Shape::Ball(Ball::new(radius))) @@ -349,7 +355,7 @@ impl ColliderBuilder { /// Sets the density of the collider this builder will build. pub fn density(mut self, density: f32) -> Self { - self.density = density; + self.density = Some(density); self } @@ -395,9 +401,11 @@ impl ColliderBuilder { /// Buildes a new collider attached to the given rigid-body. pub fn build(&self) -> Collider { + let density = self.get_density(); + Collider { shape: self.shape.clone(), - density: self.density, + density, friction: self.friction, restitution: self.restitution, delta: self.delta, -- cgit