From 175c71637b6bea6dcdd0faf3d614339983809bb1 Mon Sep 17 00:00:00 2001 From: vimene Date: Thu, 15 Jan 2026 05:15:59 +0100 Subject: rewrote entirely the triangle clipping algorithm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is still a lot of work needed to refactor it properly. - use the Sutherland–Hodgman algorithm, with some minor changes - made clipping more general, allowing clipping of any coordinate, before and after division by w - compute the z coordinate only at the fragment stage instead of each time clipping creates / moves a vertex, in addition to the fragment stage - added VectorCoords to choose at compile-time different coordinates based on a template argument - added transpose struct to allow shuffling of vectors coordinates - added math::utils::lerp which interpolate linearly a float - added Vector{2,3,4}::map() which maps a vector from one range to another - added template parameter to DerivedVertex (and therefore TriangleDerived) to allow choosing which dimension to use --- src/o3d/deriv_vertex.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/o3d/deriv_vertex.hpp') diff --git a/src/o3d/deriv_vertex.hpp b/src/o3d/deriv_vertex.hpp index 5e8dc22..48e5912 100644 --- a/src/o3d/deriv_vertex.hpp +++ b/src/o3d/deriv_vertex.hpp @@ -5,12 +5,27 @@ namespace engine::o3d { +template struct DerivedVertex { + VectorType vertex; + float b0, b1; + + constexpr DerivedVertex() {} + + constexpr DerivedVertex(const VectorType& vertex, float b0, float b1) : vertex { vertex }, b0 { b0 }, b1 { b1 } {} +}; + +template<> +struct DerivedVertex { engine::math::Vector4 vertex; float b0, b1; - constexpr DerivedVertex div_by_w() const & { - return {vertex.div_by_w(), b0, b1}; + constexpr DerivedVertex() {} + + constexpr DerivedVertex(const engine::math::Vector4& vertex, float b0, float b1) : vertex { vertex }, b0 { b0 }, b1 { b1 } {} + + constexpr DerivedVertex div_by_w() const & { + return { vertex.div_by_w(), b0, b1 }; } }; -- cgit v1.2.3