aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2020-09-28 10:58:35 +0200
committerGitHub <noreply@github.com>2020-09-28 10:58:35 +0200
commit90dffc59ed45e5b95c2a40699cb91d285a206e0e (patch)
treefa25c9c94bf4cd18a84f1a8c2bea327cd875af5f /src
parent3080c6e7d2e7bad0ac55095ccc24b1ac8bd5449a (diff)
parente7466e2f6923d24e987a34f8ebaf839346af8d4e (diff)
downloadrapier-90dffc59ed45e5b95c2a40699cb91d285a206e0e.tar.gz
rapier-90dffc59ed45e5b95c2a40699cb91d285a206e0e.tar.bz2
rapier-90dffc59ed45e5b95c2a40699cb91d285a206e0e.zip
Merge pull request #20 from dimforge/benchbot
Split benchmarks from examples
Diffstat (limited to 'src')
-rw-r--r--src/geometry/collider.rs16
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,