| 1 | // Based on Ken Shoemake. 1994. Euler angle conversion. Graphics gems IV. Academic Press |
| 2 | // Professional, Inc., USA, 222–229. |
| 3 | use craterust-analyzer cargo glam 0.30.10 crate/::{DMat3rust-analyzer cargo glam 0.30.10 f64/dmat3/DMat3#, DMat4rust-analyzer cargo glam 0.30.10 f64/dmat4/DMat4#, DQuatrust-analyzer cargo glam 0.30.10 f64/dquat/DQuat#, DVec3rust-analyzer cargo glam 0.30.10 f64/dvec3/DVec3#, Mat3rust-analyzer cargo glam 0.30.10 f32/mat3/Mat3#, Mat3Arust-analyzer cargo glam 0.30.10 f32/sse2/mat3a/Mat3A#, Mat4rust-analyzer cargo glam 0.30.10 f32/sse2/mat4/Mat4#, Quatrust-analyzer cargo glam 0.30.10 f32/sse2/quat/Quat#, Vec3rust-analyzer cargo glam 0.30.10 f32/vec3/Vec3#, Vec3Arust-analyzer cargo glam 0.30.10 f32/sse2/vec3a/Vec3A#, Vec3Swizzlesrust-analyzer cargo glam 0.30.10 swizzles/vec_traits/Vec3Swizzles#}; |
| 4 | |
| 5 | /// Euler rotation sequences. |
| 6 | /// |
| 7 | /// The three elemental rotations may be extrinsic (rotations about the axes xyz of the original |
| 8 | /// coordinate system, which is assumed to remain motionless), or intrinsic (rotations about the |
| 9 | /// axes of the rotating coordinate system XYZ, solidary with the moving body, which changes its |
| 10 | /// orientation after each elemental rotation). |
| 11 | /// |
| 12 | /// ``` |
| 13 | /// # use glam::{EulerRot, Mat3}; |
| 14 | /// # let i = core::f32::consts::FRAC_PI_2; |
| 15 | /// # let j = core::f32::consts::FRAC_PI_4; |
| 16 | /// # let k = core::f32::consts::FRAC_PI_8; |
| 17 | /// let m_intrinsic = Mat3::from_rotation_x(i) * Mat3::from_rotation_y(j) * Mat3::from_rotation_z(k); |
| 18 | /// let n_intrinsic = Mat3::from_euler(EulerRot::XYZ, i, j, k); |
| 19 | /// assert!(m_intrinsic.abs_diff_eq(n_intrinsic, 2e-6)); |
| 20 | /// |
| 21 | /// let m_extrinsic = Mat3::from_rotation_z(k) * Mat3::from_rotation_y(j) * Mat3::from_rotation_x(i); |
| 22 | /// let n_extrinsic = Mat3::from_euler(EulerRot::XYZEx, i, j, k); |
| 23 | /// assert!(m_extrinsic.abs_diff_eq(n_extrinsic, 2e-6)); |
| 24 | /// ``` |
| 25 | /// |
| 26 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 27 | pub enum EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot# { |
| 28 | /// Intrinsic three-axis rotation ZYX |
| 29 | ZYXrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZYX#, |
| 30 | /// Intrinsic three-axis rotation ZXY |
| 31 | ZXYrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZXY#, |
| 32 | /// Intrinsic three-axis rotation YXZ |
| 33 | YXZrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXZ#, |
| 34 | /// Intrinsic three-axis rotation YZX |
| 35 | YZXrust-analyzer cargo glam 0.30.10 euler/EulerRot#YZX#, |
| 36 | /// Intrinsic three-axis rotation XYZ |
| 37 | XYZrust-analyzer cargo glam 0.30.10 euler/EulerRot#XYZ#, |
| 38 | /// Intrinsic three-axis rotation XZY |
| 39 | XZYrust-analyzer cargo glam 0.30.10 euler/EulerRot#XZY#, |
| 40 | |
| 41 | /// Intrinsic two-axis rotation ZYZ |
| 42 | ZYZrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZYZ#, |
| 43 | /// Intrinsic two-axis rotation ZXZ |
| 44 | ZXZrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZXZ#, |
| 45 | /// Intrinsic two-axis rotation YXY |
| 46 | YXYrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXY#, |
| 47 | /// Intrinsic two-axis rotation YZY |
| 48 | YZYrust-analyzer cargo glam 0.30.10 euler/EulerRot#YZY#, |
| 49 | /// Intrinsic two-axis rotation XYX |
| 50 | XYXrust-analyzer cargo glam 0.30.10 euler/EulerRot#XYX#, |
| 51 | /// Intrinsic two-axis rotation XZX |
| 52 | XZXrust-analyzer cargo glam 0.30.10 euler/EulerRot#XZX#, |
| 53 | |
| 54 | /// Extrinsic three-axis rotation ZYX |
| 55 | ZYXExrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZYXEx#, |
| 56 | /// Extrinsic three-axis rotation ZXY |
| 57 | ZXYExrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZXYEx#, |
| 58 | /// Extrinsic three-axis rotation YXZ |
| 59 | YXZExrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXZEx#, |
| 60 | /// Extrinsic three-axis rotation YZX |
| 61 | YZXExrust-analyzer cargo glam 0.30.10 euler/EulerRot#YZXEx#, |
| 62 | /// Extrinsic three-axis rotation XYZ |
| 63 | XYZExrust-analyzer cargo glam 0.30.10 euler/EulerRot#XYZEx#, |
| 64 | /// Extrinsic three-axis rotation XZY |
| 65 | XZYExrust-analyzer cargo glam 0.30.10 euler/EulerRot#XZYEx#, |
| 66 | |
| 67 | /// Extrinsic two-axis rotation ZYZ |
| 68 | ZYZExrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZYZEx#, |
| 69 | /// Extrinsic two-axis rotation ZXZ |
| 70 | ZXZExrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZXZEx#, |
| 71 | /// Extrinsic two-axis rotation YXY |
| 72 | YXYExrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXYEx#, |
| 73 | /// Extrinsic two-axis rotation YZY |
| 74 | YZYExrust-analyzer cargo glam 0.30.10 euler/EulerRot#YZYEx#, |
| 75 | /// Extrinsic two-axis rotation XYX |
| 76 | XYXExrust-analyzer cargo glam 0.30.10 euler/EulerRot#XYXEx#, |
| 77 | /// Extrinsic two-axis rotation XZX |
| 78 | XZXExrust-analyzer cargo glam 0.30.10 euler/EulerRot#XZXEx#, |
| 79 | } |
| 80 | |
| 81 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot# { |
| 82 | /// Default `YXZ` as yaw (y-axis), pitch (x-axis), roll (z-axis). |
| 83 | fn defaultrust-analyzer cargo glam 0.30.10 euler/impl#[EulerRot][Default]default().() -> Selfrust-analyzer cargo glam 0.30.10 euler/impl#[EulerRot][Default] { |
| 84 | Selfrust-analyzer cargo glam 0.30.10 euler/impl#[EulerRot][Default]::YXZrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXZ# |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | pub(craterust-analyzer cargo glam 0.30.10 crate/) trait ToEulerrust-analyzer cargo glam 0.30.10 euler/ToEuler# { |
| 89 | type Scalarrust-analyzer cargo glam 0.30.10 euler/ToEuler#Scalar#; |
| 90 | fn to_euler_anglesrust-analyzer cargo glam 0.30.10 euler/ToEuler#to_euler_angles().(self, order: EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#) -> (Self::Scalarrust-analyzer cargo glam 0.30.10 euler/ToEuler#Scalar#, Self::Scalarrust-analyzer cargo glam 0.30.10 euler/ToEuler#Scalar#, Self::Scalarrust-analyzer cargo glam 0.30.10 euler/ToEuler#Scalar#); |
| 91 | } |
| 92 | |
| 93 | pub(craterust-analyzer cargo glam 0.30.10 crate/) trait FromEulerrust-analyzer cargo glam 0.30.10 euler/FromEuler# { |
| 94 | type Scalarrust-analyzer cargo glam 0.30.10 euler/FromEuler#Scalar#; |
| 95 | fn from_euler_anglesrust-analyzer cargo glam 0.30.10 euler/FromEuler#from_euler_angles().( |
| 96 | order: EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#, |
| 97 | i: Self::Scalarrust-analyzer cargo glam 0.30.10 euler/FromEuler#Scalar#, |
| 98 | j: Self::Scalarrust-analyzer cargo glam 0.30.10 euler/FromEuler#Scalar#, |
| 99 | k: Self::Scalarrust-analyzer cargo glam 0.30.10 euler/FromEuler#Scalar#, |
| 100 | ) -> Self; |
| 101 | } |
| 102 | |
| 103 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 104 | enum Axisrust-analyzer cargo glam 0.30.10 euler/Axis# { |
| 105 | Xrust-analyzer cargo glam 0.30.10 euler/Axis#X# = 0, |
| 106 | Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y# = 1, |
| 107 | Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z# = 2, |
| 108 | } |
| 109 | |
| 110 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 111 | enum Parityrust-analyzer cargo glam 0.30.10 euler/Parity# { |
| 112 | Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd# = 0, |
| 113 | Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even# = 1, |
| 114 | } |
| 115 | |
| 116 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 117 | enum Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated# { |
| 118 | Norust-analyzer cargo glam 0.30.10 euler/Repeated#No# = 0, |
| 119 | Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes# = 1, |
| 120 | } |
| 121 | |
| 122 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 123 | enum Framerust-analyzer cargo glam 0.30.10 euler/Frame# { |
| 124 | Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative# = 0, |
| 125 | Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static# = 1, |
| 126 | } |
| 127 | |
| 128 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 129 | struct Orderrust-analyzer cargo glam 0.30.10 euler/Order# { |
| 130 | initial_axisrust-analyzer cargo glam 0.30.10 euler/Order#initial_axis.: Axisrust-analyzer cargo glam 0.30.10 euler/Axis#, |
| 131 | parity_evenrust-analyzer cargo glam 0.30.10 euler/Order#parity_even.: bool, |
| 132 | initial_repeatedrust-analyzer cargo glam 0.30.10 euler/Order#initial_repeated.: bool, |
| 133 | frame_staticrust-analyzer cargo glam 0.30.10 euler/Order#frame_static.: bool, |
| 134 | } |
| 135 | |
| 136 | impl Orderrust-analyzer cargo glam 0.30.10 euler/Order# { |
| 137 | const fn newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().( |
| 138 | initial_axis: Axisrust-analyzer cargo glam 0.30.10 euler/Axis#, |
| 139 | parity: Parityrust-analyzer cargo glam 0.30.10 euler/Parity#, |
| 140 | initial_repeated: Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#, |
| 141 | frame: Framerust-analyzer cargo glam 0.30.10 euler/Frame#, |
| 142 | ) -> Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order] { |
| 143 | Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order] { |
| 144 | initial_axisrust-analyzer cargo glam 0.30.10 euler/Order#initial_axis., |
| 145 | parity_evenrust-analyzer cargo glam 0.30.10 euler/Order#parity_even.: parity as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even# as u32, |
| 146 | initial_repeatedrust-analyzer cargo glam 0.30.10 euler/Order#initial_repeated.: initial_repeated as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes# as u32, |
| 147 | frame_staticrust-analyzer cargo glam 0.30.10 euler/Order#frame_static.: frame as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static# as u32, |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | const fn from_eulerrust-analyzer cargo glam 0.30.10 euler/impl#[Order]from_euler().(euler: EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#) -> Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order] { |
| 152 | match euler { |
| 153 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::XYZrust-analyzer cargo glam 0.30.10 euler/EulerRot#XYZ# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Xrust-analyzer cargo glam 0.30.10 euler/Axis#X#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 154 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::XYXrust-analyzer cargo glam 0.30.10 euler/EulerRot#XYX# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Xrust-analyzer cargo glam 0.30.10 euler/Axis#X#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 155 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::XZYrust-analyzer cargo glam 0.30.10 euler/EulerRot#XZY# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Xrust-analyzer cargo glam 0.30.10 euler/Axis#X#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 156 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::XZXrust-analyzer cargo glam 0.30.10 euler/EulerRot#XZX# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Xrust-analyzer cargo glam 0.30.10 euler/Axis#X#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 157 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::YZXrust-analyzer cargo glam 0.30.10 euler/EulerRot#YZX# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 158 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::YZYrust-analyzer cargo glam 0.30.10 euler/EulerRot#YZY# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 159 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::YXZrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXZ# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 160 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::YXYrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXY# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 161 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::ZXYrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZXY# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 162 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::ZXZrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZXZ# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 163 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::ZYXrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZYX# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 164 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::ZYZrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZYZ# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Staticrust-analyzer cargo glam 0.30.10 euler/Frame#Static#), |
| 165 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::ZYXExrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZYXEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Xrust-analyzer cargo glam 0.30.10 euler/Axis#X#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 166 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::XYXExrust-analyzer cargo glam 0.30.10 euler/EulerRot#XYXEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Xrust-analyzer cargo glam 0.30.10 euler/Axis#X#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 167 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::YZXExrust-analyzer cargo glam 0.30.10 euler/EulerRot#YZXEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Xrust-analyzer cargo glam 0.30.10 euler/Axis#X#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 168 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::XZXExrust-analyzer cargo glam 0.30.10 euler/EulerRot#XZXEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Xrust-analyzer cargo glam 0.30.10 euler/Axis#X#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 169 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::XZYExrust-analyzer cargo glam 0.30.10 euler/EulerRot#XZYEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 170 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::YZYExrust-analyzer cargo glam 0.30.10 euler/EulerRot#YZYEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 171 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::ZXYExrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZXYEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 172 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::YXYExrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXYEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Yrust-analyzer cargo glam 0.30.10 euler/Axis#Y#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 173 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::YXZExrust-analyzer cargo glam 0.30.10 euler/EulerRot#YXZEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 174 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::ZXZExrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZXZEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Evenrust-analyzer cargo glam 0.30.10 euler/Parity#Even#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 175 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::XYZExrust-analyzer cargo glam 0.30.10 euler/EulerRot#XYZEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Norust-analyzer cargo glam 0.30.10 euler/Repeated#No#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 176 | EulerRotrust-analyzer cargo glam 0.30.10 euler/EulerRot#::ZYZExrust-analyzer cargo glam 0.30.10 euler/EulerRot#ZYZEx# => Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::newrust-analyzer cargo glam 0.30.10 euler/impl#[Order]new().(Axisrust-analyzer cargo glam 0.30.10 euler/Axis#::Zrust-analyzer cargo glam 0.30.10 euler/Axis#Z#, Parityrust-analyzer cargo glam 0.30.10 euler/Parity#::Oddrust-analyzer cargo glam 0.30.10 euler/Parity#Odd#, Repeatedrust-analyzer cargo glam 0.30.10 euler/Repeated#::Yesrust-analyzer cargo glam 0.30.10 euler/Repeated#Yes#, Framerust-analyzer cargo glam 0.30.10 euler/Frame#::Relativerust-analyzer cargo glam 0.30.10 euler/Frame#Relative#), |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | const fn next_axisrust-analyzer cargo glam 0.30.10 euler/impl#[Order]next_axis().(i: usize) -> usize { |
| 181 | (i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().3 |
| 182 | } |
| 183 | |
| 184 | const fn prev_axisrust-analyzer cargo glam 0.30.10 euler/impl#[Order]prev_axis().(i: usize) -> usize { |
| 185 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 186 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1 |
| 187 | } else { |
| 188 | 2 |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | const fn angle_orderrust-analyzer cargo glam 0.30.10 euler/impl#[Order]angle_order().(self) -> (usize, usize, usize) { |
| 193 | let i = self.initial_axisrust-analyzer cargo glam 0.30.10 euler/Order#initial_axis. as usize; |
| 194 | let j = if self.parity_evenrust-analyzer cargo glam 0.30.10 euler/Order#parity_even. { |
| 195 | Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::next_axisrust-analyzer cargo glam 0.30.10 euler/impl#[Order]next_axis().(i) |
| 196 | } else { |
| 197 | Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::prev_axisrust-analyzer cargo glam 0.30.10 euler/impl#[Order]prev_axis().(i) |
| 198 | }; |
| 199 | let k = if self.parity_evenrust-analyzer cargo glam 0.30.10 euler/Order#parity_even. { |
| 200 | Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::prev_axisrust-analyzer cargo glam 0.30.10 euler/impl#[Order]prev_axis().(i) |
| 201 | } else { |
| 202 | Selfrust-analyzer cargo glam 0.30.10 euler/impl#[Order]::next_axisrust-analyzer cargo glam 0.30.10 euler/impl#[Order]next_axis().(i) |
| 203 | }; |
| 204 | (i, j, k) |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | macro_rules! impl_mat3_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat3_from_euler! { |
| 209 | ($scalar:ident, $mat3:ident, $vec3:ident) => { |
| 210 | impl FromEuler for $mat3 { |
| 211 | type Scalar = $scalar; |
| 212 | fn from_euler_angles( |
| 213 | euler: EulerRot, |
| 214 | x: Self::Scalar, |
| 215 | y: Self::Scalar, |
| 216 | z: Self::Scalar, |
| 217 | ) -> Self { |
| 218 | use crate::$scalar::math; |
| 219 | |
| 220 | let order = Order::from_euler(euler); |
| 221 | let (i, j, k) = order.angle_order(); |
| 222 | |
| 223 | let mut angles = if order.frame_static { |
| 224 | $vec3::new(x, y, z) |
| 225 | } else { |
| 226 | $vec3::new(z, y, x) |
| 227 | }; |
| 228 | |
| 229 | // rotation direction is reverse from original paper |
| 230 | if order.parity_even { |
| 231 | angles = -angles; |
| 232 | } |
| 233 | |
| 234 | let (si, ci) = math::sin_cos(angles.x); |
| 235 | let (sj, cj) = math::sin_cos(angles.y); |
| 236 | let (sh, ch) = math::sin_cos(angles.z); |
| 237 | |
| 238 | let cc = ci * ch; |
| 239 | let cs = ci * sh; |
| 240 | let sc = si * ch; |
| 241 | let ss = si * sh; |
| 242 | |
| 243 | let mut m = [[0.0; 3]; 3]; |
| 244 | |
| 245 | if order.initial_repeated { |
| 246 | m[i][i] = cj; |
| 247 | m[i][j] = sj * si; |
| 248 | m[i][k] = sj * ci; |
| 249 | m[j][i] = sj * sh; |
| 250 | m[j][j] = -cj * ss + cc; |
| 251 | m[j][k] = -cj * cs - sc; |
| 252 | m[k][i] = -sj * ch; |
| 253 | m[k][j] = cj * sc + cs; |
| 254 | m[k][k] = cj * cc - ss; |
| 255 | } else { |
| 256 | m[i][i] = cj * ch; |
| 257 | m[i][j] = sj * sc - cs; |
| 258 | m[i][k] = sj * cc + ss; |
| 259 | m[j][i] = cj * sh; |
| 260 | m[j][j] = sj * ss + cc; |
| 261 | m[j][k] = sj * cs - sc; |
| 262 | m[k][i] = -sj; |
| 263 | m[k][j] = cj * si; |
| 264 | m[k][k] = cj * ci; |
| 265 | } |
| 266 | |
| 267 | $mat3::from_cols_array_2d(&m) |
| 268 | } |
| 269 | } |
| 270 | }; |
| 271 | } |
| 272 | |
| 273 | macro_rules! impl_mat4_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat4_from_euler! { |
| 274 | ($scalar:ident, $mat4:ident, $mat3:ident) => { |
| 275 | impl FromEuler for $mat4 { |
| 276 | type Scalar = $scalar; |
| 277 | fn from_euler_angles( |
| 278 | euler: EulerRot, |
| 279 | x: Self::Scalar, |
| 280 | y: Self::Scalar, |
| 281 | z: Self::Scalar, |
| 282 | ) -> Self { |
| 283 | $mat4::from_mat3($mat3::from_euler_angles(euler, x, y, z)) |
| 284 | } |
| 285 | } |
| 286 | }; |
| 287 | } |
| 288 | |
| 289 | macro_rules! impl_quat_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_quat_from_euler! { |
| 290 | ($scalar:ident, $quat:ident, $vec3:ident) => { |
| 291 | impl FromEuler for $quat { |
| 292 | type Scalar = $scalar; |
| 293 | fn from_euler_angles( |
| 294 | euler: EulerRot, |
| 295 | x: Self::Scalar, |
| 296 | y: Self::Scalar, |
| 297 | z: Self::Scalar, |
| 298 | ) -> Self { |
| 299 | use crate::$scalar::math; |
| 300 | |
| 301 | let order = Order::from_euler(euler); |
| 302 | let (i, j, k) = order.angle_order(); |
| 303 | |
| 304 | let mut angles = if order.frame_static { |
| 305 | $vec3::new(x, y, z) |
| 306 | } else { |
| 307 | $vec3::new(z, y, x) |
| 308 | }; |
| 309 | |
| 310 | if order.parity_even { |
| 311 | angles.y = -angles.y; |
| 312 | } |
| 313 | |
| 314 | let ti = angles.x * 0.5; |
| 315 | let tj = angles.y * 0.5; |
| 316 | let th = angles.z * 0.5; |
| 317 | let (si, ci) = math::sin_cos(ti); |
| 318 | let (sj, cj) = math::sin_cos(tj); |
| 319 | let (sh, ch) = math::sin_cos(th); |
| 320 | let cc = ci * ch; |
| 321 | let cs = ci * sh; |
| 322 | let sc = si * ch; |
| 323 | let ss = si * sh; |
| 324 | |
| 325 | let parity = if !order.parity_even { 1.0 } else { -1.0 }; |
| 326 | |
| 327 | let mut a = [0.0; 4]; |
| 328 | |
| 329 | if order.initial_repeated { |
| 330 | a[i] = cj * (cs + sc); |
| 331 | a[j] = sj * (cc + ss) * parity; |
| 332 | a[k] = sj * (cs - sc); |
| 333 | a[3] = cj * (cc - ss); |
| 334 | } else { |
| 335 | a[i] = cj * sc - sj * cs; |
| 336 | a[j] = (cj * ss + sj * cc) * parity; |
| 337 | a[k] = cj * cs - sj * sc; |
| 338 | a[3] = cj * cc + sj * ss; |
| 339 | } |
| 340 | |
| 341 | $quat::from_array(a) |
| 342 | } |
| 343 | } |
| 344 | }; |
| 345 | } |
| 346 | |
| 347 | macro_rules! impl_mat3_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat3_to_euler! { |
| 348 | ($scalar:ident, $mat3:ident, $vec3:ident) => { |
| 349 | impl ToEuler for $mat3 { |
| 350 | type Scalar = $scalar; |
| 351 | fn to_euler_angles( |
| 352 | self, |
| 353 | euler: EulerRot, |
| 354 | ) -> (Self::Scalar, Self::Scalar, Self::Scalar) { |
| 355 | use crate::$scalar::math; |
| 356 | |
| 357 | let order = Order::from_euler(euler); |
| 358 | let (i, j, k) = order.angle_order(); |
| 359 | |
| 360 | let mut ea = $vec3::ZERO; |
| 361 | if order.initial_repeated { |
| 362 | let sy = math::sqrt( |
| 363 | self.col(i)[j] * self.col(i)[j] + self.col(i)[k] * self.col(i)[k], |
| 364 | ); |
| 365 | if (sy > 16.0 * $scalar::EPSILON) { |
| 366 | ea.x = math::atan2(self.col(i)[j], self.col(i)[k]); |
| 367 | ea.y = math::atan2(sy, self.col(i)[i]); |
| 368 | ea.z = math::atan2(self.col(j)[i], -self.col(k)[i]); |
| 369 | } else { |
| 370 | ea.x = math::atan2(-self.col(j)[k], self.col(j)[j]); |
| 371 | ea.y = math::atan2(sy, self.col(i)[i]); |
| 372 | } |
| 373 | } else { |
| 374 | let cy = math::sqrt( |
| 375 | self.col(i)[i] * self.col(i)[i] + self.col(j)[i] * self.col(j)[i], |
| 376 | ); |
| 377 | if (cy > 16.0 * $scalar::EPSILON) { |
| 378 | ea.x = math::atan2(self.col(k)[j], self.col(k)[k]); |
| 379 | ea.y = math::atan2(-self.col(k)[i], cy); |
| 380 | ea.z = math::atan2(self.col(j)[i], self.col(i)[i]); |
| 381 | } else { |
| 382 | ea.x = math::atan2(-self.col(j)[k], self.col(j)[j]); |
| 383 | ea.y = math::atan2(-self.col(k)[i], cy); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | // reverse rotation angle of original code |
| 388 | if order.parity_even { |
| 389 | ea = -ea; |
| 390 | } |
| 391 | |
| 392 | if !order.frame_static { |
| 393 | ea = ea.zyx(); |
| 394 | } |
| 395 | |
| 396 | (ea.x, ea.y, ea.z) |
| 397 | } |
| 398 | } |
| 399 | }; |
| 400 | } |
| 401 | |
| 402 | macro_rules! impl_mat4_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat4_to_euler! { |
| 403 | ($scalar:ident, $mat4:ident, $mat3:ident) => { |
| 404 | impl ToEuler for $mat4 { |
| 405 | type Scalar = $scalar; |
| 406 | fn to_euler_angles( |
| 407 | self, |
| 408 | order: EulerRot, |
| 409 | ) -> (Self::Scalar, Self::Scalar, Self::Scalar) { |
| 410 | $mat3::from_mat4(self).to_euler_angles(order) |
| 411 | } |
| 412 | } |
| 413 | }; |
| 414 | } |
| 415 | |
| 416 | macro_rules! impl_quat_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_quat_to_euler! { |
| 417 | ($scalar:ident, $quat:ident, $mat3:ident) => { |
| 418 | impl ToEuler for $quat { |
| 419 | type Scalar = $scalar; |
| 420 | fn to_euler_angles( |
| 421 | self, |
| 422 | order: EulerRot, |
| 423 | ) -> (Self::Scalar, Self::Scalar, Self::Scalar) { |
| 424 | $mat3::from_quat(self).to_euler_angles(order) |
| 425 | } |
| 426 | } |
| 427 | }; |
| 428 | } |
| 429 | |
| 430 | impl_mat3_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat3_to_euler!!(f32, Mat3rust-analyzer cargo glam 0.30.10 f32/mat3/Mat3#, Vec3rust-analyzer cargo glam 0.30.10 f32/vec3/Vec3#); |
| 431 | impl_mat3_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat3_from_euler!!(f32, Mat3rust-analyzer cargo glam 0.30.10 f32/mat3/Mat3#, Vec3rust-analyzer cargo glam 0.30.10 f32/vec3/Vec3#); |
| 432 | impl_mat3_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat3_to_euler!!(f32, Mat3Arust-analyzer cargo glam 0.30.10 f32/sse2/mat3a/Mat3A#, Vec3Arust-analyzer cargo glam 0.30.10 f32/sse2/vec3a/Vec3A#); |
| 433 | impl_mat3_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat3_from_euler!!(f32, Mat3Arust-analyzer cargo glam 0.30.10 f32/sse2/mat3a/Mat3A#, Vec3Arust-analyzer cargo glam 0.30.10 f32/sse2/vec3a/Vec3A#); |
| 434 | impl_mat4_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat4_from_euler!!(f32, Mat4rust-analyzer cargo glam 0.30.10 f32/sse2/mat4/Mat4#, Mat3rust-analyzer cargo glam 0.30.10 f32/mat3/Mat3#); |
| 435 | impl_mat4_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat4_to_euler!!(f32, Mat4rust-analyzer cargo glam 0.30.10 f32/sse2/mat4/Mat4#, Mat3rust-analyzer cargo glam 0.30.10 f32/mat3/Mat3#); |
| 436 | impl_quat_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_quat_to_euler!!(f32, Quatrust-analyzer cargo glam 0.30.10 f32/sse2/quat/Quat#, Mat3rust-analyzer cargo glam 0.30.10 f32/mat3/Mat3#); |
| 437 | impl_quat_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_quat_from_euler!!(f32, Quatrust-analyzer cargo glam 0.30.10 f32/sse2/quat/Quat#, Vec3rust-analyzer cargo glam 0.30.10 f32/vec3/Vec3#); |
| 438 | |
| 439 | impl_mat3_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat3_to_euler!!(f64, DMat3rust-analyzer cargo glam 0.30.10 f64/dmat3/DMat3#, DVec3rust-analyzer cargo glam 0.30.10 f64/dvec3/DVec3#); |
| 440 | impl_mat3_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat3_from_euler!!(f64, DMat3rust-analyzer cargo glam 0.30.10 f64/dmat3/DMat3#, DVec3rust-analyzer cargo glam 0.30.10 f64/dvec3/DVec3#); |
| 441 | impl_mat4_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat4_to_euler!!(f64, DMat4rust-analyzer cargo glam 0.30.10 f64/dmat4/DMat4#, DMat3rust-analyzer cargo glam 0.30.10 f64/dmat3/DMat3#); |
| 442 | impl_mat4_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_mat4_from_euler!!(f64, DMat4rust-analyzer cargo glam 0.30.10 f64/dmat4/DMat4#, DMat3rust-analyzer cargo glam 0.30.10 f64/dmat3/DMat3#); |
| 443 | impl_quat_to_eulerrust-analyzer cargo glam 0.30.10 euler/impl_quat_to_euler!!(f64, DQuatrust-analyzer cargo glam 0.30.10 f64/dquat/DQuat#, DMat3rust-analyzer cargo glam 0.30.10 f64/dmat3/DMat3#); |
| 444 | impl_quat_from_eulerrust-analyzer cargo glam 0.30.10 euler/impl_quat_from_euler!!(f64, DQuatrust-analyzer cargo glam 0.30.10 f64/dquat/DQuat#, DVec3rust-analyzer cargo glam 0.30.10 f64/dvec3/DVec3#); |