diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-12-28 23:59:46 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-12-28 23:59:46 +0000 |
commit | b6af53eeffc6c518248b269ee1839fcc3e9bdf22 (patch) | |
tree | a0b8a76b9e7717c452e96b661b21da41376a28dc /lib/maths.h | |
parent | Reduce size of shadow map texture (diff) | |
download | ilt-b6af53eeffc6c518248b269ee1839fcc3e9bdf22.tar.bz2 ilt-b6af53eeffc6c518248b269ee1839fcc3e9bdf22.tar.xz ilt-b6af53eeffc6c518248b269ee1839fcc3e9bdf22.zip |
Add helper to apply perspective division
Returns vec3 by default, but dimensions can be specified
Diffstat (limited to 'lib/maths.h')
-rw-r--r-- | lib/maths.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/maths.h b/lib/maths.h index 5bb69d3..c651af5 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -80,6 +80,13 @@ ratio(glm::vec<2, T, Q> v) return ratio<R>(v.x, v.y); } +template<glm::length_t L = 3, typename T, glm::qualifier Q> +inline constexpr glm::vec<L, T, Q> +perspective_divide(glm::vec<4, T, Q> v) +{ + return v / v.w; +} + constexpr inline glm::vec2 operator!(const glm::vec3 & v) { |