re_types/components/
rotation_axis_angle_ext.rs

1use crate::datatypes;
2
3use super::RotationAxisAngle;
4
5impl RotationAxisAngle {
6    /// The identity rotation, representing no rotation.
7    pub const IDENTITY: Self = Self(datatypes::RotationAxisAngle::IDENTITY);
8
9    /// Create a new rotation from an axis and an angle.
10    #[inline]
11    pub fn new(axis: impl Into<datatypes::Vec3D>, angle: impl Into<datatypes::Angle>) -> Self {
12        Self(datatypes::RotationAxisAngle::new(axis, angle))
13    }
14}
15
16#[cfg(feature = "glam")]
17impl TryFrom<RotationAxisAngle> for glam::Affine3A {
18    type Error = ();
19
20    #[inline]
21    fn try_from(val: RotationAxisAngle) -> Result<Self, Self::Error> {
22        glam::Vec3::from(val.0.axis)
23            .try_normalize()
24            .map(|normalized| Self::from_axis_angle(normalized, val.0.angle.radians()))
25            .ok_or(())
26    }
27}