pub struct Posture<T: Scalar> { /* private fields */ }
Expand description
Collection of bones transformations that represent a skelly posture.
It’s primary usecase is to be used instead
of transformations contained in the Skelly
.
Multiple postures to be processed for the same Skelly
.
Allowing running animations, IK algorithms etc,
and then blend them to get final posture.
Implementations§
Source§impl<T> Posture<T>where
T: Scalar,
impl<T> Posture<T>where
T: Scalar,
Sourcepub fn new<D>(skelly: &Skelly<T, D>) -> Selfwhere
T: RealField,
pub fn new<D>(skelly: &Skelly<T, D>) -> Selfwhere
T: RealField,
Returns new Posture
instance for skelly
.
Copies current skelly
transformations.
§Example
let mut skelly = Skelly::<f32>::new();
let root = skelly.add_root(Point3::origin());
let bone = skelly.attach(Vector3::x(), root);
let mut posture = Posture::new(&skelly);
pub fn is_compatible<D>(&self, skelly: &Skelly<T, D>) -> bool
Sourcepub fn append_rotation(&mut self, bone: usize, rotation: UnitQuaternion<T>)where
T: RealField,
pub fn append_rotation(&mut self, bone: usize, rotation: UnitQuaternion<T>)where
T: RealField,
Rotates bone with specified id.
Does not affect relative position to the parent and global position for root bones. Affects global position of all descendant bones.
§Example
let mut skelly = Skelly::<f32>::new();
let root = skelly.add_root(Point3::origin());
let bone = skelly.attach(Vector3::x(), root);
let mut posture = Posture::new(&skelly);
let mut globals = [Isometry3::identity(); 2];
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_old = globals[bone];
// Ensure that bone is placed correctly in global space at (1, 0, 0).
assert!((bone_global_old.translation.vector - Vector3::x()).magnitude() < EPSILON);
// Rotate root bone. It is still at origin.
// Yet global position of the `bone` attached to `root` has changed accordingly.
posture.append_rotation(root, UnitQuaternion::from_euler_angles(0.0, 0.0, PI / 2.0));
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_new = globals[bone];
// Ensure that bone is placed correctly in global space after root rotation at (0, 1, 0).
assert!((bone_global_new.translation.vector - Vector3::y()).magnitude() < EPSILON);
§Panics
This method panics if bone
index is out of bounds.
Sourcepub fn prepend_rotation(&mut self, bone: usize, rotation: UnitQuaternion<T>)where
T: RealField,
pub fn prepend_rotation(&mut self, bone: usize, rotation: UnitQuaternion<T>)where
T: RealField,
Rotates bone with specified id.
Does not affect relative position to the parent and global position for root bones. Affects global position of all descendant bones.
§Example
let mut skelly = Skelly::<f32>::new();
let root = skelly.add_root(Point3::origin());
let bone = skelly.attach(Vector3::x(), root);
let mut posture = Posture::new(&skelly);
let mut globals = [Isometry3::identity(); 2];
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_old = globals[bone];
// Ensure that bone is placed correctly in global space at (1, 0, 0).
assert!((bone_global_old.translation.vector - Vector3::x()).magnitude() < EPSILON);
// Rotate the bone. It is still at origin.
// Yet global position of the `bone` attached to `root` has changed accordingly.
posture.prepend_rotation(bone, UnitQuaternion::from_euler_angles(0.0, 0.0, PI / 2.0));
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_new = globals[bone];
// Ensure that bone is placed correctly in global space after root rotation at (0, 1, 0).
assert!((bone_global_new.translation.vector - Vector3::y()).magnitude() < EPSILON);
§Panics
This method panics if bone
index is out of bounds.
Sourcepub fn append_translation(&mut self, bone: usize, translation: Translation3<T>)where
T: RealField,
pub fn append_translation(&mut self, bone: usize, translation: Translation3<T>)where
T: RealField,
Translates bone with specified id.
Affects relative position to the parent and global position for root bones. Affects global position of all descendant bones.
§Example
let mut skelly = Skelly::<f32>::new();
let root = skelly.add_root(Point3::origin());
let bone = skelly.attach(Vector3::x(), root);
let mut posture = Posture::new(&skelly);
let mut globals = [Isometry3::identity(); 2];
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_old = globals[bone];
// Ensure that bone is placed correctly in global space at (1, 0, 0).
assert!((bone_global_old.translation.vector - Vector3::x()).magnitude() < EPSILON);
// Translate root bone.
// Global position of the `bone` attached to `root` has changed accordingly.
posture.append_translation(root, Vector3::z().into());
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_new = globals[bone];
// Ensure that bone is placed correctly in global space after root translation at (1, 0, 1).
assert!((bone_global_new.translation.vector - (Vector3::x() + Vector3::z())).magnitude() < EPSILON);
§Panics
This method panics if bone
index is out of bounds.
Sourcepub fn set_position(&mut self, bone: usize, position: Vector3<T>)
pub fn set_position(&mut self, bone: usize, position: Vector3<T>)
Sets relative position for bone with specified id. Affects global position of all descendant bones.
This method ignores current relative position of the bone.
To apply translation to current relative poistion see Skelly::append_translation
.
§Example
let mut skelly = Skelly::<f32>::new();
let root = skelly.add_root(Point3::origin());
let bone = skelly.attach(Vector3::x(), root);
let mut posture = Posture::new(&skelly);
let mut globals = [Isometry3::identity(); 2];
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_old = globals[bone];
// Ensure that bone is placed correctly in global space at (1, 0, 0).
assert!((bone_global_old.translation.vector - Vector3::x()).magnitude() < EPSILON);
// Set new relative position for the `bone`.
posture.set_position(bone, Vector3::z());
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_new = globals[bone];
// Ensure that bone is placed correctly in global space at new position (0, 0, 1).
assert!((bone_global_new.translation.vector - Vector3::z()).magnitude() < EPSILON);
§Panics
This method panics if bone
index is out of bounds.
Sourcepub fn get_position(&mut self, bone: usize) -> Vector3<T>where
T: RealField,
pub fn get_position(&mut self, bone: usize) -> Vector3<T>where
T: RealField,
Returns current bone position relative to parent.
Sourcepub fn set_orientation(&mut self, bone: usize, orientation: UnitQuaternion<T>)
pub fn set_orientation(&mut self, bone: usize, orientation: UnitQuaternion<T>)
Sets relative orientation for bone with specified id. Affects global position of all descendant bones.
This method ignores current relative position of the bone.
To apply translation to current relative poistion see Skelly::append_translation
.
§Example
let mut skelly = Skelly::<f32>::new();
let root = skelly.add_root(Point3::origin());
let bone = skelly.attach(Vector3::x(), root);
let mut posture = Posture::new(&skelly);
let mut globals = [Isometry3::identity(); 2];
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_old = globals[bone];
// Ensure that bone is placed correctly in global space at (1, 0, 0).
assert!((bone_global_old.translation.vector - Vector3::x()).magnitude() < EPSILON);
// Set new relative orientation for the `bone`.
posture.set_orientation(root, UnitQuaternion::from_euler_angles(0.0, 0.0, PI / 2.0));
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
let bone_global_new = globals[bone];
// Ensure that bone is placed correctly in global space at new position (0, 0, 1).
assert!((bone_global_new.translation.vector - Vector3::y()).magnitude() < EPSILON);
§Panics
This method panics if bone
index is out of bounds.
Sourcepub fn get_orientation(&mut self, bone: usize) -> UnitQuaternion<T>where
T: RealField,
pub fn get_orientation(&mut self, bone: usize) -> UnitQuaternion<T>where
T: RealField,
Returns current bone orientation relative to parent.
Sourcepub fn get_isometry(&mut self, bone: usize) -> Isometry3<T>where
T: RealField,
pub fn get_isometry(&mut self, bone: usize) -> Isometry3<T>where
T: RealField,
Returns current bone isometry relative to parent.
Sourcepub fn write_globals<D>(
&self,
skelly: &Skelly<T, D>,
skelly_global: &Isometry3<T>,
globals: &mut [Isometry3<T>],
)where
T: RealField,
pub fn write_globals<D>(
&self,
skelly: &Skelly<T, D>,
skelly_global: &Isometry3<T>,
globals: &mut [Isometry3<T>],
)where
T: RealField,
Fills slice of Isometry3
with global isometries
for each bone of the skelly
in this posture.
§Example
let mut skelly = Skelly::<f32>::new();
let root = skelly.add_root(Point3::origin());
let bone = skelly.attach(Vector3::x(), root);
let mut posture = Posture::new(&skelly);
// Animate the skelly by modifying posture iteratively.
let mut globals = [Isometry3::identity(); 2];
posture.write_globals(&skelly, &Isometry3::identity(), &mut globals);
§Panics
Panics if this posture is not compatible with the skelly
.
To check for compatibility use Posture::is_compatible
.
One may use Posture
with Skelly
used to create that Posture
(see Posture::new
) as it is guaranteed to be compatible
until new bone is added.
Auto Trait Implementations§
impl<T> Freeze for Posture<T>
impl<T> RefUnwindSafe for Posture<T>where
T: RefUnwindSafe,
impl<T> Send for Posture<T>where
T: Send,
impl<T> Sync for Posture<T>where
T: Sync,
impl<T> Unpin for Posture<T>where
T: Unpin,
impl<T> UnwindSafe for Posture<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.