update quaternion implementation
This commit is contained in:
parent
d9edd85e60
commit
bf14b7c5c8
1 changed files with 10 additions and 9 deletions
|
@ -53,8 +53,8 @@ template <std::floating_point Scalar> struct quaternion final {
|
||||||
return std::forward<decltype(self)>(self).q_.w();
|
return std::forward<decltype(self)>(self).q_.w();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto
|
constexpr auto operator*(const quaternion& rhs) const noexcept
|
||||||
operator*(const quaternion& rhs) const noexcept -> quaternion {
|
-> quaternion {
|
||||||
return {rhs.w() * x() + rhs.x() * w() + rhs.y() * z() - rhs.z() * y(),
|
return {rhs.w() * x() + rhs.x() * w() + rhs.y() * z() - rhs.z() * y(),
|
||||||
rhs.w() * y() - rhs.x() * z() + rhs.y() * w() + rhs.z() * x(),
|
rhs.w() * y() - rhs.x() * z() + rhs.y() * w() + rhs.z() * x(),
|
||||||
rhs.w() * z() + rhs.x() * y() - rhs.y() * x() + rhs.z() * w(),
|
rhs.w() * z() + rhs.x() * y() - rhs.y() * x() + rhs.z() * w(),
|
||||||
|
@ -130,9 +130,10 @@ template <std::floating_point Scalar> struct quaternion final {
|
||||||
/**
|
/**
|
||||||
* @note: a and b need to be normalized
|
* @note: a and b need to be normalized
|
||||||
*/
|
*/
|
||||||
static constexpr auto
|
static constexpr auto slerp(const quaternion& a, const quaternion& b,
|
||||||
slerp(const quaternion& a, const quaternion& b, const Scalar& t,
|
const Scalar& t,
|
||||||
const Scalar& eps = Scalar{0.001}) -> quaternion {
|
const Scalar& eps = Scalar{0.001})
|
||||||
|
-> quaternion {
|
||||||
|
|
||||||
// Calculate angle between them.
|
// Calculate angle between them.
|
||||||
const Scalar cos_half_theta{a.dot(b)};
|
const Scalar cos_half_theta{a.dot(b)};
|
||||||
|
@ -166,8 +167,8 @@ template <std::floating_point Scalar> struct quaternion final {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr auto
|
static constexpr auto from_axisangle(const axisangle<Scalar>& aa)
|
||||||
from_axisangle(const axisangle<Scalar>& aa) -> quaternion {
|
-> quaternion {
|
||||||
|
|
||||||
const auto sin_half_angle{std::sin(aa.angle / Scalar{2})};
|
const auto sin_half_angle{std::sin(aa.angle / Scalar{2})};
|
||||||
|
|
||||||
|
@ -179,8 +180,8 @@ template <std::floating_point Scalar> struct quaternion final {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr static auto
|
constexpr static auto from_matrix(const matrix<Scalar, 3, 3>& m)
|
||||||
from_matrix(const matrix<Scalar, 3, 3>& m) -> quaternion {
|
-> quaternion {
|
||||||
const auto wtemp =
|
const auto wtemp =
|
||||||
std::sqrt(Scalar{1} + m[0][0] + m[1][1] + m[2][2]) / Scalar{2};
|
std::sqrt(Scalar{1} + m[0][0] + m[1][1] + m[2][2]) / Scalar{2};
|
||||||
const auto w4 = Scalar{4} * wtemp;
|
const auto w4 = Scalar{4} * wtemp;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue