X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmath%2Fglm.hpp;h=0d344e6e7879bbb4786aecb64266060854154f7a;hb=d921cba26f21e4a75b22f5e9d9be988707bf6a8f;hp=46843db4ca2850603d4ca9001dab12b1cc302bae;hpb=5b2ab168a9b3c05082bd9cd924f548bc90fc8efa;p=blobs.git diff --git a/src/math/glm.hpp b/src/math/glm.hpp index 46843db..0d344e6 100644 --- a/src/math/glm.hpp +++ b/src/math/glm.hpp @@ -16,10 +16,14 @@ #if GLM_VERSION < 96 namespace glm { - using tvec1 = detail::tvec1; - using tvec2 = detail::tvec2; - using tvec3 = detail::tvec3; - using tvec4 = detail::tvec4; + template + using tvec1 = detail::tvec1; + template + using tvec2 = detail::tvec2; + template + using tvec3 = detail::tvec3; + template + using tvec4 = detail::tvec4; } #endif @@ -36,6 +40,17 @@ inline bool anynan(const T &v) noexcept { return glm::any(glm::isnan(v)); } +template +inline Vec limit(const Vec &v, typename Vec::value_type max) noexcept { + typename Vec::value_type len2 = glm::length2(v); + typename Vec::value_type max2 = max * max; + if (len2 > max2) { + return glm::normalize(v) * max; + } else { + return v; + } +} + template inline T rgb2hsl(const T &rgb) { using Vec4 = glm::tvec4; @@ -55,8 +70,8 @@ template inline T hsl2rgb(const T &hsl) { using Vec3 = glm::tvec3; using Vec4 = glm::tvec4; - const Vec4 K(0.0, -1.0/3.0, 2.0/3.0, -1.0); - const Vec3 p(glm::abs(glm::fract(Vec3(hsl.h) + Vec3(K)) * 6.0 - Vec3(K.w))); + const Vec4 K(1.0, 2.0/3.0, 1.0/3.0, 3.0); + const Vec3 p(glm::abs(glm::fract(Vec3(hsl.x) + Vec3(K)) * 6.0 - Vec3(K.w))); T rgb = hsl.z * glm::mix(Vec3(K.x), glm::clamp(p - Vec3(K.x), 0.0, 1.0), hsl.y); return rgb; }