Skip to content

Commit

Permalink
Support extracting euler angles from matrix types.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitshifter committed Jun 25, 2024
1 parent 901902e commit 3b3dbff
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 0 deletions.
7 changes: 7 additions & 0 deletions codegen/templates/mat.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ impl {{ self_t }} {
Self::from_euler_angles(order, a, b, c)
}

/// Extract Euler angles with the given Euler rotation order.
#[inline]
#[must_use]
pub fn to_euler(&self, order: EulerRot) -> ({{ scalar_t }}, {{ scalar_t }}, {{ scalar_t }}) {
self.to_euler_angles(order)
}

/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
#[inline]
#[must_use]
Expand Down
16 changes: 16 additions & 0 deletions src/euler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,20 @@ macro_rules! impl_mat3_to_euler {
};
}

macro_rules! impl_mat4_to_euler {
($scalar:ident, $mat4:ident, $mat3:ident) => {
impl ToEuler for $mat4 {
type Scalar = $scalar;
fn to_euler_angles(
self,
order: EulerRot,
) -> (Self::Scalar, Self::Scalar, Self::Scalar) {
$mat3::from_mat4(self).to_euler_angles(order)
}
}
};
}

macro_rules! impl_quat_to_euler {
($scalar:ident, $quat:ident, $mat3:ident) => {
impl ToEuler for $quat {
Expand All @@ -398,11 +412,13 @@ impl_euler_to_mat3!(f32, Mat3, Vec3);
impl_mat3_to_euler!(f32, Mat3A, Vec3A);
impl_euler_to_mat3!(f32, Mat3A, Vec3A);
impl_euler_to_mat4!(f32, Mat4, Mat3);
impl_mat4_to_euler!(f32, Mat4, Mat3);
impl_quat_to_euler!(f32, Quat, Mat3);
impl_euler_to_quat!(f32, Quat, Vec3);

impl_mat3_to_euler!(f64, DMat3, DVec3);
impl_euler_to_mat3!(f64, DMat3, DVec3);
impl_mat4_to_euler!(f64, DMat4, DMat3);
impl_euler_to_mat4!(f64, DMat4, DMat3);
impl_quat_to_euler!(f64, DQuat, DMat3);
impl_euler_to_quat!(f64, DQuat, DVec3);
7 changes: 7 additions & 0 deletions src/f32/coresimd/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ impl Mat3A {
Self::from_euler_angles(order, a, b, c)
}

/// Extract Euler angles with the given Euler rotation order.
#[inline]
#[must_use]
pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
self.to_euler_angles(order)
}

/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/mat3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ impl Mat3 {
Self::from_euler_angles(order, a, b, c)
}

/// Extract Euler angles with the given Euler rotation order.
#[inline]
#[must_use]
pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
self.to_euler_angles(order)
}

/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/neon/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ impl Mat3A {
Self::from_euler_angles(order, a, b, c)
}

/// Extract Euler angles with the given Euler rotation order.
#[inline]
#[must_use]
pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
self.to_euler_angles(order)
}

/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/scalar/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ impl Mat3A {
Self::from_euler_angles(order, a, b, c)
}

/// Extract Euler angles with the given Euler rotation order.
#[inline]
#[must_use]
pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
self.to_euler_angles(order)
}

/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/sse2/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ impl Mat3A {
Self::from_euler_angles(order, a, b, c)
}

/// Extract Euler angles with the given Euler rotation order.
#[inline]
#[must_use]
pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
self.to_euler_angles(order)
}

/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f32/wasm32/mat3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ impl Mat3A {
Self::from_euler_angles(order, a, b, c)
}

/// Extract Euler angles with the given Euler rotation order.
#[inline]
#[must_use]
pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32) {
self.to_euler_angles(order)
}

/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
#[inline]
#[must_use]
Expand Down
7 changes: 7 additions & 0 deletions src/f64/dmat3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ impl DMat3 {
Self::from_euler_angles(order, a, b, c)
}

/// Extract Euler angles with the given Euler rotation order.
#[inline]
#[must_use]
pub fn to_euler(&self, order: EulerRot) -> (f64, f64, f64) {
self.to_euler_angles(order)
}

/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis.
#[inline]
#[must_use]
Expand Down

0 comments on commit 3b3dbff

Please sign in to comment.