Allow a rigid-body to be initialized asleep.
This commit is contained in:
@@ -388,6 +388,7 @@ pub struct RigidBodyBuilder {
|
|||||||
body_status: BodyStatus,
|
body_status: BodyStatus,
|
||||||
mass_properties: MassProperties,
|
mass_properties: MassProperties,
|
||||||
can_sleep: bool,
|
can_sleep: bool,
|
||||||
|
sleeping: bool,
|
||||||
user_data: u128,
|
user_data: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,6 +404,7 @@ impl RigidBodyBuilder {
|
|||||||
body_status,
|
body_status,
|
||||||
mass_properties: MassProperties::zero(),
|
mass_properties: MassProperties::zero(),
|
||||||
can_sleep: true,
|
can_sleep: true,
|
||||||
|
sleeping: false,
|
||||||
user_data: 0,
|
user_data: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -531,6 +533,12 @@ impl RigidBodyBuilder {
|
|||||||
self
|
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.
|
/// Build a new rigid-body with the parameters configured with this builder.
|
||||||
pub fn build(&self) -> RigidBody {
|
pub fn build(&self) -> RigidBody {
|
||||||
let mut rb = RigidBody::new();
|
let mut rb = RigidBody::new();
|
||||||
@@ -544,6 +552,10 @@ impl RigidBodyBuilder {
|
|||||||
rb.linear_damping = self.linear_damping;
|
rb.linear_damping = self.linear_damping;
|
||||||
rb.angular_damping = self.angular_damping;
|
rb.angular_damping = self.angular_damping;
|
||||||
|
|
||||||
|
if self.can_sleep && self.sleeping {
|
||||||
|
rb.sleep();
|
||||||
|
}
|
||||||
|
|
||||||
if !self.can_sleep {
|
if !self.can_sleep {
|
||||||
rb.activation.threshold = -1.0;
|
rb.activation.threshold = -1.0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user