use super::*;

#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct Axis3Angle {
  /// Should be normalized.
  pub axis: Vec3,
  /// In radians.
  pub angle: f32,
}

impl From<Axis3Angle> for Mat4 {
  #[rustfmt::skip]
  fn from(axis_angle: Axis3Angle) -> Mat4 {
    let sin = axis_angle.angle.sin();
    let cos = axis_angle.angle.cos();
    let omc = 1. - cos;
    let rx = axis_angle.axis.x;
    let ry = axis_angle.axis.y;
    let rz = axis_angle.axis.z;
    make_mat4!(
      [cos+rx*rx*omc,      rx*ry*omc-rz*sin,   rx*rz*omc+ry*sin,   0.],
      [ry*rx*omc+rz*sin,   cos+ry*ry*omc,      ry*rz*omc-rx*sin,   0.],
      [rz*rx*omc-ry*sin,   rz*ry*omc+rx*sin,   cos+rz*rz*omc,      0.],
      [0.,                 0.,                 0.,                 1.],
    )
  }
}
