update macos/ios to Filament v1.51.2
This commit is contained in:
@@ -58,7 +58,8 @@ public:
|
||||
|
||||
/* compound assignment products by a scalar
|
||||
*/
|
||||
constexpr QUATERNION<T>& operator*=(T v) {
|
||||
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
|
||||
constexpr QUATERNION<T>& operator*=(U v) {
|
||||
QUATERNION<T>& lhs = static_cast<QUATERNION<T>&>(*this);
|
||||
for (size_t i = 0; i < QUATERNION<T>::size(); i++) {
|
||||
lhs[i] *= v;
|
||||
@@ -66,7 +67,8 @@ public:
|
||||
return lhs;
|
||||
}
|
||||
|
||||
constexpr QUATERNION<T>& operator/=(T v) {
|
||||
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
|
||||
constexpr QUATERNION<T>& operator/=(U v) {
|
||||
QUATERNION<T>& lhs = static_cast<QUATERNION<T>&>(*this);
|
||||
for (size_t i = 0; i < QUATERNION<T>::size(); i++) {
|
||||
lhs[i] /= v;
|
||||
@@ -85,28 +87,29 @@ public:
|
||||
/* The operators below handle operation between quaternions of the same size
|
||||
* but of a different element type.
|
||||
*/
|
||||
template<typename RT>
|
||||
friend inline
|
||||
constexpr QUATERNION<T> MATH_PURE operator*(const QUATERNION<T>& q, const QUATERNION<RT>& r) {
|
||||
template<typename U>
|
||||
friend inline constexpr
|
||||
QUATERNION<arithmetic_result_t<T, U>> MATH_PURE operator*(
|
||||
const QUATERNION<T>& q, const QUATERNION<U>& r) {
|
||||
// could be written as:
|
||||
// return QUATERNION<T>(
|
||||
// q.w*r.w - dot(q.xyz, r.xyz),
|
||||
// q.w*r.xyz + r.w*q.xyz + cross(q.xyz, r.xyz));
|
||||
|
||||
return QUATERNION<T>(
|
||||
return {
|
||||
q.w * r.w - q.x * r.x - q.y * r.y - q.z * r.z,
|
||||
q.w * r.x + q.x * r.w + q.y * r.z - q.z * r.y,
|
||||
q.w * r.y - q.x * r.z + q.y * r.w + q.z * r.x,
|
||||
q.w * r.z + q.x * r.y - q.y * r.x + q.z * r.w);
|
||||
q.w * r.z + q.x * r.y - q.y * r.x + q.z * r.w
|
||||
};
|
||||
}
|
||||
|
||||
template<typename RT>
|
||||
friend inline
|
||||
constexpr TVec3<T> MATH_PURE operator*(const QUATERNION<T>& q, const TVec3<RT>& v) {
|
||||
template<typename U>
|
||||
friend inline constexpr
|
||||
TVec3<arithmetic_result_t<T, U>> MATH_PURE operator*(const QUATERNION<T>& q, const TVec3<U>& v) {
|
||||
// note: if q is known to be a unit quaternion, then this simplifies to:
|
||||
// TVec3<T> t = 2 * cross(q.xyz, v)
|
||||
// return v + (q.w * t) + cross(q.xyz, t)
|
||||
return imaginary(q * QUATERNION<T>(v, 0) * inverse(q));
|
||||
return imaginary(q * QUATERNION<U>(v, 0) * inverse(q));
|
||||
}
|
||||
|
||||
|
||||
@@ -122,22 +125,25 @@ public:
|
||||
* q.w*r.z + q.x*r.y - q.y*r.x + q.z*r.w);
|
||||
*
|
||||
*/
|
||||
friend inline
|
||||
constexpr QUATERNION<T> MATH_PURE operator*(QUATERNION<T> q, T scalar) {
|
||||
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
|
||||
friend inline constexpr
|
||||
QUATERNION<arithmetic_result_t<T, U>> MATH_PURE operator*(QUATERNION<T> q, U scalar) {
|
||||
// don't pass q by reference because we need a copy anyway
|
||||
return q *= scalar;
|
||||
return QUATERNION<arithmetic_result_t<T, U>>(q *= scalar);
|
||||
}
|
||||
|
||||
friend inline
|
||||
constexpr QUATERNION<T> MATH_PURE operator*(T scalar, QUATERNION<T> q) {
|
||||
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
|
||||
friend inline constexpr
|
||||
QUATERNION<arithmetic_result_t<T, U>> MATH_PURE operator*(U scalar, QUATERNION<T> q) {
|
||||
// don't pass q by reference because we need a copy anyway
|
||||
return q *= scalar;
|
||||
return QUATERNION<arithmetic_result_t<T, U>>(q *= scalar);
|
||||
}
|
||||
|
||||
friend inline
|
||||
constexpr QUATERNION<T> MATH_PURE operator/(QUATERNION<T> q, T scalar) {
|
||||
template<typename U, typename = std::enable_if_t<std::is_arithmetic_v<U>>>
|
||||
friend inline constexpr
|
||||
QUATERNION<arithmetic_result_t<T, U>> MATH_PURE operator/(QUATERNION<T> q, U scalar) {
|
||||
// don't pass q by reference because we need a copy anyway
|
||||
return q /= scalar;
|
||||
return QUATERNION<arithmetic_result_t<T, U>>(q /= scalar);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,9 +166,10 @@ public:
|
||||
* (the first one, BASE<T> being known).
|
||||
*/
|
||||
|
||||
template<typename RT>
|
||||
friend inline
|
||||
constexpr T MATH_PURE dot(const QUATERNION<T>& p, const QUATERNION<RT>& q) {
|
||||
template<typename U>
|
||||
friend inline constexpr
|
||||
arithmetic_result_t<T, U> MATH_PURE dot(
|
||||
const QUATERNION<T>& p, const QUATERNION<U>& q) {
|
||||
return p.x * q.x +
|
||||
p.y * q.y +
|
||||
p.z * q.z +
|
||||
@@ -196,7 +203,7 @@ public:
|
||||
|
||||
friend inline
|
||||
constexpr QUATERNION<T> MATH_PURE inverse(const QUATERNION<T>& q) {
|
||||
return conj(q) * (1 / dot(q, q));
|
||||
return conj(q) * (T(1) / dot(q, q));
|
||||
}
|
||||
|
||||
friend inline
|
||||
@@ -214,8 +221,10 @@ public:
|
||||
return QUATERNION<T>(q.xyz, 0);
|
||||
}
|
||||
|
||||
friend inline
|
||||
constexpr QUATERNION<T> MATH_PURE cross(const QUATERNION<T>& p, const QUATERNION<T>& q) {
|
||||
template<typename U>
|
||||
friend inline constexpr
|
||||
QUATERNION<arithmetic_result_t<T, U>> MATH_PURE cross(
|
||||
const QUATERNION<T>& p, const QUATERNION<U>& q) {
|
||||
return unreal(p * q);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,15 +17,21 @@
|
||||
#ifndef TNT_MATH_MAT3_H
|
||||
#define TNT_MATH_MAT3_H
|
||||
|
||||
#include <math/TMatHelpers.h>
|
||||
#include <math/compiler.h>
|
||||
#include <math/quat.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/TMatHelpers.h>
|
||||
#include <math/TVecHelpers.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace filament {
|
||||
namespace math {
|
||||
// -------------------------------------------------------------------------------------
|
||||
@@ -289,6 +295,14 @@ public:
|
||||
return matrix::cof(m);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a matrix representing the pose of a virtual camera looking towards -Z in its
|
||||
* local Y-up coordinate system. "up" defines where the Y axis of the camera's local coordinate
|
||||
* system is.
|
||||
*/
|
||||
template<typename A, typename B>
|
||||
static TMat33 lookTo(const TVec3<A>& direction, const TVec3<B>& up) noexcept;
|
||||
|
||||
/**
|
||||
* Packs the tangent frame represented by the specified matrix into a quaternion.
|
||||
* Reflection is preserved by encoding it as the sign of the w component in the
|
||||
@@ -406,6 +420,29 @@ constexpr TMat33<T>::TMat33(const TQuaternion<U>& q) noexcept : m_value{} {
|
||||
m_value[2] = col_type(xz + yw, yz - xw, 1 - xx - yy); // NOLINT
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T dot_tolerance() noexcept;
|
||||
|
||||
template<>
|
||||
constexpr float dot_tolerance<float>() noexcept { return 0.999f; }
|
||||
|
||||
template<>
|
||||
constexpr double dot_tolerance<double>() noexcept { return 0.9999; }
|
||||
|
||||
template<typename T>
|
||||
template<typename A, typename B>
|
||||
TMat33<T> TMat33<T>::lookTo(const TVec3<A>& direction, const TVec3<B>& up) noexcept {
|
||||
auto const z_axis = direction;
|
||||
auto norm_up = up;
|
||||
if (std::abs(dot(z_axis, norm_up)) > dot_tolerance< arithmetic_result_t<A, B> >()) {
|
||||
// Fix up vector if we're degenerate (looking straight up, basically)
|
||||
norm_up = { norm_up.z, norm_up.x, norm_up.y };
|
||||
}
|
||||
auto const x_axis = normalize(cross(z_axis, norm_up));
|
||||
auto const y_axis = cross(x_axis, z_axis);
|
||||
return { x_axis, y_axis, -z_axis };
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
constexpr TQuaternion<T> TMat33<T>::packTangentFrame(const TMat33<T>& m, size_t storageSize) noexcept {
|
||||
|
||||
@@ -285,6 +285,9 @@ public:
|
||||
template<typename A, typename B, typename C>
|
||||
static TMat44 lookAt(const TVec3<A>& eye, const TVec3<B>& center, const TVec3<C>& up) noexcept;
|
||||
|
||||
template<typename A, typename B, typename C>
|
||||
static TMat44 lookTo(const TVec3<A>& direction, const TVec3<B>& position, const TVec3<C>& up) noexcept;
|
||||
|
||||
template<typename A>
|
||||
static constexpr TVec3<A> project(const TMat44& projectionMatrix, TVec3<A> vertice) noexcept{
|
||||
TVec4<A> r = projectionMatrix * TVec4<A>{ vertice, 1 };
|
||||
@@ -517,19 +520,19 @@ template<typename T>
|
||||
template<typename A, typename B, typename C>
|
||||
TMat44<T> TMat44<T>::lookAt(const TVec3<A>& eye, const TVec3<B>& center,
|
||||
const TVec3<C>& up) noexcept {
|
||||
TVec3<T> z_axis(normalize(center - eye));
|
||||
TVec3<T> norm_up(normalize(up));
|
||||
if (std::abs(dot(z_axis, norm_up)) > T(0.999)) {
|
||||
// Fix up vector if we're degenerate (looking straight up, basically)
|
||||
norm_up = { norm_up.z, norm_up.x, norm_up.y };
|
||||
}
|
||||
TVec3<T> x_axis(normalize(cross(z_axis, norm_up)));
|
||||
TVec3<T> y_axis(cross(x_axis, z_axis));
|
||||
return TMat44<T>(
|
||||
TVec4<T>(x_axis, 0),
|
||||
TVec4<T>(y_axis, 0),
|
||||
TVec4<T>(-z_axis, 0),
|
||||
TVec4<T>(eye, 1));
|
||||
return lookTo(normalize(center - eye), eye, normalize(up));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename A, typename B, typename C>
|
||||
TMat44<T> TMat44<T>::lookTo(const TVec3<A>& direction, const TVec3<B>& position,
|
||||
const TVec3<C>& up) noexcept {
|
||||
auto r = TMat33<T>::lookTo(direction, up);
|
||||
return TMat44<T>{
|
||||
TVec4<T>{ r[0], 0 },
|
||||
TVec4<T>{ r[1], 0 },
|
||||
TVec4<T>{ r[2], 0 },
|
||||
TVec4<T>{ position, 1 } };
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
@@ -171,27 +171,29 @@ typedef details::TQuaternion<double> quat;
|
||||
typedef details::TQuaternion<float> quatf;
|
||||
typedef details::TQuaternion<half> quath;
|
||||
|
||||
constexpr inline quat operator "" _i(long double v) {
|
||||
// note: don't put a space between "" and _{i,j,k}, this is deprecated
|
||||
|
||||
constexpr inline quat operator ""_i(long double v) {
|
||||
return { 0.0, double(v), 0.0, 0.0 };
|
||||
}
|
||||
|
||||
constexpr inline quat operator "" _j(long double v) {
|
||||
constexpr inline quat operator ""_j(long double v) {
|
||||
return { 0.0, 0.0, double(v), 0.0 };
|
||||
}
|
||||
|
||||
constexpr inline quat operator "" _k(long double v) {
|
||||
constexpr inline quat operator ""_k(long double v) {
|
||||
return { 0.0, 0.0, 0.0, double(v) };
|
||||
}
|
||||
|
||||
constexpr inline quat operator "" _i(unsigned long long v) {
|
||||
constexpr inline quat operator ""_i(unsigned long long v) {
|
||||
return { 0.0, double(v), 0.0, 0.0 };
|
||||
}
|
||||
|
||||
constexpr inline quat operator "" _j(unsigned long long v) {
|
||||
constexpr inline quat operator ""_j(unsigned long long v) {
|
||||
return { 0.0, 0.0, double(v), 0.0 };
|
||||
}
|
||||
|
||||
constexpr inline quat operator "" _k(unsigned long long v) {
|
||||
constexpr inline quat operator ""_k(unsigned long long v) {
|
||||
return { 0.0, 0.0, 0.0, double(v) };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user