re_types/
rotation3d.rs

1use crate::{components, datatypes};
2
3/// A 3D rotation.
4///
5/// This is *not* a component, but a helper type for populating [`crate::archetypes::Transform3D`] with rotations.
6#[derive(Clone, Debug, Copy, PartialEq)]
7pub enum Rotation3D {
8    /// Rotation defined by a quaternion.
9    Quaternion(components::RotationQuat),
10
11    /// Rotation defined with an axis and an angle.
12    AxisAngle(components::RotationAxisAngle),
13}
14
15impl Rotation3D {
16    /// The identity rotation, expressed as a quaternion
17    pub const IDENTITY: Self = Self::Quaternion(components::RotationQuat::IDENTITY);
18}
19
20impl From<components::RotationQuat> for Rotation3D {
21    #[inline]
22    fn from(quat: components::RotationQuat) -> Self {
23        Self::Quaternion(quat)
24    }
25}
26
27impl From<datatypes::Quaternion> for Rotation3D {
28    #[inline]
29    fn from(quat: datatypes::Quaternion) -> Self {
30        Self::Quaternion(quat.into())
31    }
32}
33
34#[cfg(feature = "glam")]
35impl From<glam::Quat> for Rotation3D {
36    #[inline]
37    fn from(quat: glam::Quat) -> Self {
38        Self::Quaternion(quat.into())
39    }
40}
41
42impl From<components::RotationAxisAngle> for Rotation3D {
43    #[inline]
44    fn from(axis_angle: components::RotationAxisAngle) -> Self {
45        Self::AxisAngle(axis_angle)
46    }
47}
48
49impl From<datatypes::RotationAxisAngle> for Rotation3D {
50    #[inline]
51    fn from(axis_angle: datatypes::RotationAxisAngle) -> Self {
52        Self::AxisAngle(axis_angle.into())
53    }
54}