From 49fd861083a0b6055ac8b9ea7aa69b9207b2c030 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Thu, 19 Nov 2020 11:10:03 +0100 Subject: Allow a rigid-body to be initialized asleep. --- src/dynamics/rigid_body.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/dynamics') diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 303d1a0..6704c51 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -388,6 +388,7 @@ pub struct RigidBodyBuilder { body_status: BodyStatus, mass_properties: MassProperties, can_sleep: bool, + sleeping: bool, user_data: u128, } @@ -403,6 +404,7 @@ impl RigidBodyBuilder { body_status, mass_properties: MassProperties::zero(), can_sleep: true, + sleeping: false, user_data: 0, } } @@ -531,6 +533,12 @@ impl RigidBodyBuilder { self } + /// Sets whether or not the rigid-body is to be created asleep. + pub fn sleeping(mut self, sleeping: bool) -> Self { + self.sleeping = sleeping; + self + } + /// Build a new rigid-body with the parameters configured with this builder. pub fn build(&self) -> RigidBody { let mut rb = RigidBody::new(); @@ -544,6 +552,10 @@ impl RigidBodyBuilder { rb.linear_damping = self.linear_damping; rb.angular_damping = self.angular_damping; + if self.can_sleep && self.sleeping { + rb.sleep(); + } + if !self.can_sleep { rb.activation.threshold = -1.0; } -- cgit