| 1 | use craterust-analyzer cargo glam 0.16.0 crate/::corerust-analyzer cargo glam 0.16.0 core/::{ |
| 2 | storagerust-analyzer cargo glam 0.16.0 core/storage/::XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ#, |
| 3 | traitsrust-analyzer cargo glam 0.16.0 core/traits/::{ |
| 4 | scalarrust-analyzer cargo glam 0.16.0 core/traits/scalar/::{FloatExrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatEx#, NumExrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumEx#}, |
| 5 | vectorrust-analyzer cargo glam 0.16.0 core/traits/vector/::*, |
| 6 | }, |
| 7 | }; |
| 8 | |
| 9 | pub trait Quaternionrust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#<T: FloatExrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatEx#>: FloatVector4rust-analyzer cargo glam 0.16.0 core/traits/vector/FloatVector4#<T> { |
| 10 | type SIMDVector3rust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#SIMDVector3#; |
| 11 | |
| 12 | #[inline] |
| 13 | fn from_axis_anglerust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#from_axis_angle().(axis: XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ#<T>, angle: T) -> Self { |
| 14 | glam_assertrust-analyzer cargo glam 0.16.0 macros/glam_assert!!(FloatVector3::is_normalized(axis)); |
| 15 | let (s, c) = (angle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().T::HALFrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#HALF.).sin_cosrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sin_cos().(); |
| 16 | let v = axis.mul_scalarrust-analyzer cargo glam 0.16.0 core/scalar/vector/impl#[`XYZ<T>`][`Vector<T>`]mul_scalar().(s); |
| 17 | Self::newrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#new().(v.xrust-analyzer cargo glam 0.16.0 core/storage/XYZ#x., v.yrust-analyzer cargo glam 0.16.0 core/storage/XYZ#y., v.zrust-analyzer cargo glam 0.16.0 core/storage/XYZ#z., c) |
| 18 | } |
| 19 | |
| 20 | #[inline] |
| 21 | fn from_rotation_xrust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#from_rotation_x().(angle: T) -> Self { |
| 22 | let (s, c) = (angle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().T::HALFrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#HALF.).sin_cosrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sin_cos().(); |
| 23 | Self::newrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#new().(s, T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO., T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO., c) |
| 24 | } |
| 25 | |
| 26 | #[inline] |
| 27 | fn from_rotation_yrust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#from_rotation_y().(angle: T) -> Self { |
| 28 | let (s, c) = (angle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().T::HALFrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#HALF.).sin_cosrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sin_cos().(); |
| 29 | Self::newrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#new().(T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO., s, T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO., c) |
| 30 | } |
| 31 | |
| 32 | #[inline] |
| 33 | fn from_rotation_zrust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#from_rotation_z().(angle: T) -> Self { |
| 34 | let (s, c) = (angle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().T::HALFrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#HALF.).sin_cosrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sin_cos().(); |
| 35 | Self::newrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#new().(T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO., T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO., s, c) |
| 36 | } |
| 37 | |
| 38 | /// From the columns of a 3x3 rotation matrix. |
| 39 | #[inline] |
| 40 | fn from_rotation_axesrust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#from_rotation_axes().(x_axis: XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ#<T>, y_axis: XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ#<T>, z_axis: XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ#<T>) -> Self { |
| 41 | // Based on https://github.com/microsoft/DirectXMath `XM$quaternionRotationMatrix` |
| 42 | // TODO: sse2 version |
| 43 | let (m00, m01, m02) = x_axis.into_tuplerust-analyzer cargo glam 0.16.0 core/traits/vector/Vector3#into_tuple().(); |
| 44 | let (m10, m11, m12) = y_axis.into_tuplerust-analyzer cargo glam 0.16.0 core/traits/vector/Vector3#into_tuple().(); |
| 45 | let (m20, m21, m22) = z_axis.into_tuplerust-analyzer cargo glam 0.16.0 core/traits/vector/Vector3#into_tuple().(); |
| 46 | if m22 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO. { |
| 47 | // x^2 + y^2 >= z^2 + w^2 |
| 48 | let dif10 = m11 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().m00; |
| 49 | let omm22 = T::ONErust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ONE. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().m22; |
| 50 | if dif10 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO. { |
| 51 | // x^2 >= y^2 |
| 52 | let four_xsq = omm22 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().dif10; |
| 53 | let inv4x = T::HALFrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#HALF. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().four_xsq.sqrtrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sqrt().(); |
| 54 | Self::newrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#new().( |
| 55 | four_xsq rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4x, |
| 56 | (m01 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().m10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4x, |
| 57 | (m02 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().m20) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4x, |
| 58 | (m12 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().m21) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4x, |
| 59 | ) |
| 60 | } else { |
| 61 | // y^2 >= x^2 |
| 62 | let four_ysq = omm22 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().dif10; |
| 63 | let inv4y = T::HALFrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#HALF. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().four_ysq.sqrtrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sqrt().(); |
| 64 | Self::newrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#new().( |
| 65 | (m01 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().m10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4y, |
| 66 | four_ysq rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4y, |
| 67 | (m12 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().m21) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4y, |
| 68 | (m20 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().m02) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4y, |
| 69 | ) |
| 70 | } |
| 71 | } else { |
| 72 | // z^2 + w^2 >= x^2 + y^2 |
| 73 | let sum10 = m11 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().m00; |
| 74 | let opm22 = T::ONErust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ONE. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().m22; |
| 75 | if sum10 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO. { |
| 76 | // z^2 >= w^2 |
| 77 | let four_zsq = opm22 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().sum10; |
| 78 | let inv4z = T::HALFrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#HALF. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().four_zsq.sqrtrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sqrt().(); |
| 79 | Self::newrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#new().( |
| 80 | (m02 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().m20) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4z, |
| 81 | (m12 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().m21) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4z, |
| 82 | four_zsq rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4z, |
| 83 | (m01 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().m10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4z, |
| 84 | ) |
| 85 | } else { |
| 86 | // w^2 >= z^2 |
| 87 | let four_wsq = opm22 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().sum10; |
| 88 | let inv4w = T::HALFrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#HALF. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().four_wsq.sqrtrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sqrt().(); |
| 89 | Self::newrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#new().( |
| 90 | (m12 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().m21) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4w, |
| 91 | (m20 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().m02) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4w, |
| 92 | (m01 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().m10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4w, |
| 93 | four_wsq rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().inv4w, |
| 94 | ) |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | fn to_axis_anglerust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#to_axis_angle().(self) -> (XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ#<T>, T) { |
| 100 | // const EPSILON: f32 = 1.0e-8; |
| 101 | // const EPSILON_SQUARED: f32 = EPSILON * EPSILON; |
| 102 | let (x, y, z, w) = Vector4rust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#::into_tuplerust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#into_tuple().(self); |
| 103 | let angle = w.acos_approxrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatEx#acos_approx().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().T::TWOrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#TWO.; |
| 104 | let scale_sq = NumExrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumEx#::maxrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumEx#max().(T::ONErust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ONE. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().w rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().w, T::ZEROrust-analyzer cargo glam 0.16.0 core/traits/scalar/NumConstEx#ZERO.); |
| 105 | // TODO: constants for epslions? |
| 106 | if scale_sq rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#ge().T::from_f32rust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatEx#from_f32().(1.0e-8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().1.0e-8) { |
| 107 | (XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ# { xrust-analyzer cargo glam 0.16.0 core/storage/XYZ#x., yrust-analyzer cargo glam 0.16.0 core/storage/XYZ#y., zrust-analyzer cargo glam 0.16.0 core/storage/XYZ#z. }.mul_scalarrust-analyzer cargo glam 0.16.0 core/scalar/vector/impl#[`XYZ<T>`][`Vector<T>`]mul_scalar().(scale_sq.sqrtrust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#sqrt().().reciprust-analyzer cargo glam 0.16.0 core/traits/scalar/Float#recip().()), angle) |
| 108 | } else { |
| 109 | (Vector3Construst-analyzer cargo glam 0.16.0 core/traits/vector/Vector3Const#::Xrust-analyzer cargo glam 0.16.0 core/scalar/vector/impl#[`XYZ<T>`][Vector3Const]X., angle) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | #[inline] |
| 114 | fn is_near_identityrust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#is_near_identity().(self) -> bool { |
| 115 | // Based on https://github.com/nfrechette/rtm `rtm::quat_near_identity` |
| 116 | let threshold_angle = T::from_f64rust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatEx#from_f64().(0.002_847_144_6); |
| 117 | // Because of floating point precision, we cannot represent very small rotations. |
| 118 | // The closest f32 to 1.0 that is not 1.0 itself yields: |
| 119 | // 0.99999994.acos() * 2.0 = 0.000690533954 rad |
| 120 | // |
| 121 | // An error threshold of 1.e-6 is used by default. |
| 122 | // (1.0 - 1.e-6).acos() * 2.0 = 0.00284714461 rad |
| 123 | // (1.0 - 1.e-7).acos() * 2.0 = 0.00097656250 rad |
| 124 | // |
| 125 | // We don't really care about the angle value itself, only if it's close to 0. |
| 126 | // This will happen whenever quat.w is close to 1.0. |
| 127 | // If the quat.w is close to -1.0, the angle will be near 2*PI which is close to |
| 128 | // a negative 0 rotation. By forcing quat.w to be positive, we'll end up with |
| 129 | // the shortest path. |
| 130 | let positive_w_angle = self.as_ref_xyzwrust-analyzer cargo glam 0.16.0 core/traits/vector/Vector4#as_ref_xyzw().().wrust-analyzer cargo glam 0.16.0 core/storage/XYZW#w..absrust-analyzer cargo glam 0.16.0 core/traits/scalar/Signed#abs().().acos_approxrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatEx#acos_approx().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().T::TWOrust-analyzer cargo glam 0.16.0 core/traits/scalar/FloatConstEx#TWO.; |
| 131 | positive_w_angle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().threshold_angle |
| 132 | } |
| 133 | |
| 134 | fn conjugaterust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#conjugate().(self) -> Self; |
| 135 | fn lerprust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#lerp().(self, end: Self, s: T) -> Self; |
| 136 | fn slerprust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#slerp().(self, end: Self, s: T) -> Self; |
| 137 | fn mul_quaternionrust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#mul_quaternion().(self, other: Self) -> Self; |
| 138 | fn mul_vector3rust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#mul_vector3().(self, other: XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ#<T>) -> XYZrust-analyzer cargo glam 0.16.0 core/storage/XYZ#<T>; |
| 139 | fn mul_float4_as_vector3rust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#mul_float4_as_vector3().(self, other: Self::SIMDVector3rust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#SIMDVector3#) -> Self::SIMDVector3rust-analyzer cargo glam 0.16.0 core/traits/quaternion/Quaternion#SIMDVector3#; |
| 140 | } |