diff --git a/src/lol/math/half.h b/src/lol/math/half.h index 886a1f9b..d47158aa 100644 --- a/src/lol/math/half.h +++ b/src/lol/math/half.h @@ -120,6 +120,8 @@ public: static inline half min(half a, half b) { return a < b ? a : b; } static inline half max(half a, half b) { return a > b ? a : b; } +static inline half fmod(half a, half b) { return (half)fmod((float)a, (float)b); } +static inline half abs(half a) { return half::makebits(a.bits & 0x7fffu); } static inline half clamp(half x, half a, half b) { diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index e6d3647b..93cb9e4e 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1065,9 +1065,9 @@ extern Quat slerp(Quat const &qa, Quat const &qb, T f); } /* - * vec min(vec, vec) (also max) - * vec min(vec, scalar) (also max) - * vec min(scalar, vec) (also max) + * vec min(vec, vec) (also max, fmod) + * vec min(vec, scalar) (also max, fmod) + * vec min(scalar, vec) (also max, fmod) */ #define DECLARE_VECTOR_MINMAX_OP(tname, op, tprefix, type) \ tprefix \ @@ -1104,6 +1104,7 @@ extern Quat slerp(Quat const &qa, Quat const &qb, T f); * vec clamp(vec, vec, vec) * vec clamp(vec, vec, scalar) * vec clamp(vec, scalar, vec) + * vec clamp(vec, scalar, scalar) */ #define DECLARE_VECTOR_CLAMP_OP(tname, tprefix, type) \ tprefix \ @@ -1125,6 +1126,13 @@ extern Quat slerp(Quat const &qa, Quat const &qb, T f); tname const &a, type const &b) \ { \ return max(min(x, b), a); \ + } \ + \ + tprefix \ + inline tname clamp(tname const &x, \ + type const &a, type const &b) \ + { \ + return max(min(x, b), a); \ } /* @@ -1210,10 +1218,20 @@ extern Quat slerp(Quat const &qa, Quat const &qb, T f); } \ \ tprefix \ - inline tname normalize(tname const &val) \ + inline tname normalize(tname const &a) \ { \ - type norm = (type)length(val); \ - return norm ? val / norm : val * (type)0; \ + type norm = (type)length(a); \ + return norm ? a / norm : a * (type)0; \ + } \ + \ + tprefix \ + inline tname abs(tname const &a) \ + { \ + using std::abs; \ + tname ret; \ + for (size_t n = 0; n < sizeof(a) / sizeof(type); n++) \ + ret[n] = abs(a[n]); \ + return ret; \ } #define DECLARE_BINARY_NONVECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \ @@ -1270,6 +1288,7 @@ extern Quat slerp(Quat const &qa, Quat const &qb, T f); \ DECLARE_VECTOR_MINMAX_OP(tname, min, tprefix, type) \ DECLARE_VECTOR_MINMAX_OP(tname, max, tprefix, type) \ + DECLARE_VECTOR_MINMAX_OP(tname, fmod, tprefix, type) \ DECLARE_VECTOR_CLAMP_OP(tname, tprefix, type) #define DECLARE_VECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \