1
0
Fork 0

Add reflect function to linalg

This commit is contained in:
Pabloader 2025-06-09 07:13:18 +00:00
parent 726fe9d12d
commit a88299277a
2 changed files with 5 additions and 3 deletions

View File

@ -495,6 +495,7 @@ namespace linalg
template<class T, int M> T uangle (const vec<T,M> & a, const vec<T,M> & b) { T d=dot(a,b); return d > 1 ? 0 : std::acos(d < -1 ? -1 : d); }
template<class T, int M> T angle (const vec<T,M> & a, const vec<T,M> & b) { return uangle(normalize(a), normalize(b)); }
template<class T> vec<T,2> rot (T a, const vec<T,2> & v) { const T s = std::sin(a), c = std::cos(a); return {v.x*c - v.y*s, v.x*s + v.y*c}; }
template<class T, int M> constexpr vec<T,M> reflect (const vec<T,M> & i, const vec<T,M> & n) { return i-2*dot(n, i)*n; }
template<class T, int M> vec<T,M> nlerp (const vec<T,M> & a, const vec<T,M> & b, T t) { return normalize(lerp(a,b,t)); }
template<class T, int M> vec<T,M> slerp (const vec<T,M> & a, const vec<T,M> & b, T t) { T th=uangle(a,b); return th == 0 ? a : a*(std::sin(th*(1-t))/std::sin(th)) + b*(std::sin(th*t)/std::sin(th)); }

View File

@ -4,8 +4,9 @@
using namespace linalg::aliases;
EXPORT(main) auto init() {
double2 dir = {0, -1};
double2 rot = linalg::rot(3.14 / 2, dir);
static constexpr double2 vel = {-1, -1};
static constexpr double2 left = {1, 0};
static constexpr double2 refl = linalg::reflect(vel, left);
return linalg::angle(rot, {0, 1});
return refl.y;
}