diff options
| author | vimene <vincent.menegaux@gmail.com> | 2026-01-15 05:15:59 +0100 |
|---|---|---|
| committer | vimene <vincent.menegaux@gmail.com> | 2026-01-15 05:15:59 +0100 |
| commit | 175c71637b6bea6dcdd0faf3d614339983809bb1 (patch) | |
| tree | 9edfb88bb427b7c601ad9e9016a9d9d262c0b105 /src/o3d/tri_deriv.hpp | |
| parent | db41d43345ea73cf7c1bbb29448e52ffb822e3e0 (diff) | |
| download | engine-175c71637b6bea6dcdd0faf3d614339983809bb1.tar.gz | |
rewrote entirely the triangle clipping algorithm
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
Diffstat (limited to 'src/o3d/tri_deriv.hpp')
| -rw-r--r-- | src/o3d/tri_deriv.hpp | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/o3d/tri_deriv.hpp b/src/o3d/tri_deriv.hpp index 65713ed..64369fc 100644 --- a/src/o3d/tri_deriv.hpp +++ b/src/o3d/tri_deriv.hpp @@ -1,23 +1,16 @@ #ifndef O3D_TRI_VERTEX_HPP #define O3D_TRI_VERTEX_HPP -#include <vector> #include "o3d/vertex.hpp" #include "o3d/deriv_vertex.hpp" namespace engine::o3d { +template<engine::math::VectorTypeConcept VectorType> struct TriangleDerived { - DerivedVertex derived_vertex1; - DerivedVertex derived_vertex2; - DerivedVertex derived_vertex3; - - std::vector<TriangleDerived> perspective_crop_xy_out(float x1, float x2, float y1, float y2) const; - std::vector<TriangleDerived> crop_z_out(float z1, float z2) const; - - constexpr TriangleDerived div_by_w() const & { - return {derived_vertex1.div_by_w(), derived_vertex2.div_by_w(), derived_vertex3.div_by_w()}; - } + DerivedVertex<VectorType> derived_vertex1; + DerivedVertex<VectorType> derived_vertex2; + DerivedVertex<VectorType> derived_vertex3; }; } |
