1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::{components, datatypes};

/// A 3D rotation.
///
/// This is *not* a component, but a helper type for populating [`crate::archetypes::Transform3D`] with rotations.
#[derive(Clone, Debug, Copy, PartialEq)]
pub enum Rotation3D {
    /// Rotation defined by a quaternion.
    Quaternion(components::RotationQuat),

    /// Rotation defined with an axis and an angle.
    AxisAngle(components::RotationAxisAngle),
}

impl Rotation3D {
    /// The identity rotation, expressed as a quaternion
    pub const IDENTITY: Self = Self::Quaternion(components::RotationQuat::IDENTITY);
}

impl From<components::RotationQuat> for Rotation3D {
    #[inline]
    fn from(quat: components::RotationQuat) -> Self {
        Self::Quaternion(quat)
    }
}

impl From<datatypes::Quaternion> for Rotation3D {
    #[inline]
    fn from(quat: datatypes::Quaternion) -> Self {
        Self::Quaternion(quat.into())
    }
}

#[cfg(feature = "glam")]
impl From<glam::Quat> for Rotation3D {
    #[inline]
    fn from(quat: glam::Quat) -> Self {
        Self::Quaternion(quat.into())
    }
}

impl From<components::RotationAxisAngle> for Rotation3D {
    #[inline]
    fn from(axis_angle: components::RotationAxisAngle) -> Self {
        Self::AxisAngle(axis_angle)
    }
}

impl From<datatypes::RotationAxisAngle> for Rotation3D {
    #[inline]
    fn from(axis_angle: datatypes::RotationAxisAngle) -> Self {
        Self::AxisAngle(axis_angle.into())
    }
}