From b6af53eeffc6c518248b269ee1839fcc3e9bdf22 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 28 Dec 2022 23:59:46 +0000 Subject: Add helper to apply perspective division Returns vec3 by default, but dimensions can be specified --- lib/maths.h | 7 +++++++ 1 file changed, 7 insertions(+) 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(v.x, v.y); } +template +inline constexpr glm::vec +perspective_divide(glm::vec<4, T, Q> v) +{ + return v / v.w; +} + constexpr inline glm::vec2 operator!(const glm::vec3 & v) { -- cgit v1.2.3