aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2021-07-05 16:06:03 +0200
committerSébastien Crozet <sebastien@crozet.re>2021-07-12 10:10:59 +0200
commit8e0aa2ac79938c1c76c4fd315b3e739c8899fc19 (patch)
tree641121446a9baa1c90310b63981c7c48e670069a /src
parent77a6cd3f26525ce6b02b63b34cb68d3a8a444ee2 (diff)
downloadrapier-8e0aa2ac79938c1c76c4fd315b3e739c8899fc19.tar.gz
rapier-8e0aa2ac79938c1c76c4fd315b3e739c8899fc19.tar.bz2
rapier-8e0aa2ac79938c1c76c4fd315b3e739c8899fc19.zip
Add methods to set the translation or rotation wrt. a collider and its parent.
Diffstat (limited to 'src')
-rw-r--r--src/geometry/collider.rs28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs
index 1b9853c..9f2cd2b 100644
--- a/src/geometry/collider.rs
+++ b/src/geometry/collider.rs
@@ -174,16 +174,30 @@ impl Collider {
self.co_parent.as_ref().map(|p| &p.pos_wrt_parent)
}
+ /// Sets the translational part of this collider's translation relative to its parent rigid-body.
+ pub fn set_translation_wrt_parent(&mut self, translation: Vector<Real>) {
+ if let Some(co_parent) = self.co_parent.as_mut() {
+ self.co_changes.insert(ColliderChanges::PARENT);
+ co_parent.pos_wrt_parent.translation.vector = translation;
+ }
+ }
+
+ /// Sets the rotational part of this collider's rotaiton relative to its parent rigid-body.
+ pub fn set_rotation_wrt_parent(&mut self, rotation: AngVector<Real>) {
+ if let Some(co_parent) = self.co_parent.as_mut() {
+ self.co_changes.insert(ColliderChanges::PARENT);
+ co_parent.pos_wrt_parent.rotation = Rotation::new(rotation);
+ }
+ }
+
/// Sets the position of this collider wrt. its parent rigid-body.
///
- /// Panics if the collider is not attached to a rigid-body.
+ /// Does nothing if the collider is not attached to a rigid-body.
pub fn set_position_wrt_parent(&mut self, pos_wrt_parent: Isometry<Real>) {
- self.co_changes.insert(ColliderChanges::PARENT);
- let co_parent = self
- .co_parent
- .as_mut()
- .expect("This collider has no parent.");
- co_parent.pos_wrt_parent = pos_wrt_parent;
+ if let Some(co_parent) = self.co_parent.as_mut() {
+ self.co_changes.insert(ColliderChanges::PARENT);
+ co_parent.pos_wrt_parent = pos_wrt_parent;
+ }
}
/// The collision groups used by this collider.