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();
|
||||
}
|
||||
|
||||
constexpr auto
|
||||
operator*(const quaternion& rhs) const noexcept -> quaternion {
|
||||
constexpr auto operator*(const quaternion& rhs) const noexcept
|
||||
-> quaternion {
|
||||
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() * 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
|
||||
*/
|
||||
static constexpr auto
|
||||
slerp(const quaternion& a, const quaternion& b, const Scalar& t,
|
||||
const Scalar& eps = Scalar{0.001}) -> quaternion {
|
||||
static constexpr auto slerp(const quaternion& a, const quaternion& b,
|
||||
const Scalar& t,
|
||||
const Scalar& eps = Scalar{0.001})
|
||||
-> quaternion {
|
||||
|
||||
// Calculate angle between them.
|
||||
const Scalar cos_half_theta{a.dot(b)};
|
||||
|
@ -166,8 +167,8 @@ template <std::floating_point Scalar> struct quaternion final {
|
|||
};
|
||||
}
|
||||
|
||||
static constexpr auto
|
||||
from_axisangle(const axisangle<Scalar>& aa) -> quaternion {
|
||||
static constexpr auto from_axisangle(const axisangle<Scalar>& aa)
|
||||
-> quaternion {
|
||||
|
||||
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
|
||||
from_matrix(const matrix<Scalar, 3, 3>& m) -> quaternion {
|
||||
constexpr static auto from_matrix(const matrix<Scalar, 3, 3>& m)
|
||||
-> quaternion {
|
||||
const auto wtemp =
|
||||
std::sqrt(Scalar{1} + m[0][0] + m[1][1] + m[2][2]) / Scalar{2};
|
||||
const auto w4 = Scalar{4} * wtemp;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue