diff options
| author | Sébastien Crozet <developer@crozet.re> | 2020-09-06 12:16:09 +0200 |
|---|---|---|
| committer | Sébastien Crozet <developer@crozet.re> | 2020-09-06 12:16:22 +0200 |
| commit | ff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b (patch) | |
| tree | 76578c4a2ff16592b98eea9cbd9c9b07646240a4 /src | |
| parent | 3080c6e7d2e7bad0ac55095ccc24b1ac8bd5449a (diff) | |
| download | rapier-ff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b.tar.gz rapier-ff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b.tar.bz2 rapier-ff2da7fb27f0ea7a15b1dc6b6daf763fe7faf13b.zip | |
Move benchmark demos into their own directory.
Diffstat (limited to 'src')
| -rw-r--r-- | src/geometry/collider.rs | 16 |
1 files changed, 12 insertions, 4 deletions
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<f32>, /// 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, |
