upgrade to Filament 1.21.0

This commit is contained in:
Nick Fisher
2022-04-14 01:54:33 +08:00
parent f4f7d28388
commit 53ab72bcff
139 changed files with 4410 additions and 20097 deletions

View File

@@ -21,7 +21,7 @@
#include <math/quat.h>
#include <math/TVecHelpers.h>
#include <algorithm> // for std::swap
#include <algorithm> // for std::swap and std::min
#include <cmath> // for std:: namespace
#include <math.h>

View File

@@ -21,14 +21,10 @@
#include <cmath> // for std:: namespace
#include <math.h>
#include <stdint.h>
#include <sys/types.h>
namespace filament {
namespace math {
namespace details {
// -------------------------------------------------------------------------------------
namespace filament::math::details {
template<typename U>
inline constexpr U min(U a, U b) noexcept {
@@ -281,8 +277,6 @@ private:
template<typename U>
friend inline constexpr
bool MATH_PURE operator==(const VECTOR<T>& lv, const VECTOR<U>& rv) {
// w/ inlining we end-up with many branches that will pollute the BPU cache
MATH_NOUNROLL
for (size_t i = 0; i < lv.size(); i++) {
if (lv[i] != rv[i]) {
return false;
@@ -624,9 +618,6 @@ private:
}
};
// -------------------------------------------------------------------------------------
} // namespace details
} // namespace math
} // namespace filament
} // namespace filament::math::details
#endif // TNT_MATH_TVECHELPERS_H

View File

@@ -126,6 +126,44 @@ public:
constexpr static TQuaternion MATH_PURE fromAxisAngle(const TVec3<A>& axis, B angle) {
return TQuaternion(std::sin(angle * 0.5) * normalize(axis), std::cos(angle * 0.5));
}
// constructs a quaternion from orig to dest.
// it returns the shortest arc and `from` and `to` must be normalized.
template<typename A, typename B, typename = enable_if_arithmetic_t<A, B>>
constexpr static TQuaternion MATH_PURE fromDirectedRotation(const TVec3<A>& from, const TVec3<B>& to) {
// see the implementation of glm/gtx/quaternion.hpp
T cosTheta = dot(from, to);
TVec3<T> rotationAxis;
if (cosTheta >= T(1) - std::numeric_limits<T>::epsilon()) {
// orig and dest point in the same direction
return TQuaternion(1, 0, 0, 0);
}
if (cosTheta < T(-1) + std::numeric_limits<T>::epsilon()) {
// special case when vectors in opposite directions :
// there is no "ideal" rotation axis
// So guess one; any will do as long as it's perpendicular to start
// This implementation favors a rotation around the Up axis (Y),
// since it's often what you want to do.
rotationAxis = cross(TVec3<T>(0, 0, 1), from);
if (length2(rotationAxis) < std::numeric_limits<T>::epsilon()) {
// bad luck, they were parallel, try again!
rotationAxis = cross(TVec3<T>(1, 0, 0), from);
}
rotationAxis = normalize(rotationAxis);
return fromAxisAngle(rotationAxis, F_PI);
}
// implementation from Stan Melax's Game Programming Gems 1 article
rotationAxis = cross(from, to);
const T s = std::sqrt((T(1) + cosTheta) * T(2));
return TQuaternion(s * T(0.5),
rotationAxis.x / s, rotationAxis.y / s, rotationAxis.z / s);
}
};
} // namespace details