From 80938cd913d0e3da6e635a91803eb7fb84beab5c Mon Sep 17 00:00:00 2001 From: Orange Date: Thu, 28 Aug 2025 23:18:36 +0300 Subject: [PATCH 1/3] Adds plane primitive generation Implements a function to generate a plane primitive from two vertices, a direction vector, and a size, returning an array of two triangles. --- include/omath/3d_primitives/plane.hpp | 16 ++++++++++++++++ source/3d_primitives/plane.cpp | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 include/omath/3d_primitives/plane.hpp create mode 100644 source/3d_primitives/plane.cpp diff --git a/include/omath/3d_primitives/plane.hpp b/include/omath/3d_primitives/plane.hpp new file mode 100644 index 0000000..62ff993 --- /dev/null +++ b/include/omath/3d_primitives/plane.hpp @@ -0,0 +1,16 @@ +// +// Created by Vlad on 8/28/2025. +// + +#pragma once +#include "omath/triangle.hpp" +#include "omath/vector3.hpp" +#include + +namespace omath::primitives +{ + [[nodiscard]] + std::array>, 2> create_plane(const Vector3& vertex_a, + const Vector3& vertex_b, + const Vector3& direction, float size) noexcept; +} diff --git a/source/3d_primitives/plane.cpp b/source/3d_primitives/plane.cpp new file mode 100644 index 0000000..dffbe42 --- /dev/null +++ b/source/3d_primitives/plane.cpp @@ -0,0 +1,21 @@ +// +// Created by Vlad on 8/28/2025. +// +#include "omath/3d_primitives/plane.hpp" + +namespace omath::primitives +{ + std::array>, 2> create_plane(const Vector3& vertex_a, + const Vector3& vertex_b, + const Vector3& direction, const float size) noexcept + { + Triangle> triangles; + const auto second_vertex_a = vertex_a + direction * size; + const auto second_vertex_b = vertex_b + direction * size; + return std::array + { + Triangle{second_vertex_a, vertex_a, vertex_b}, + Triangle{second_vertex_b, vertex_b, vertex_a} + }; + } +} // namespace omath::primitives \ No newline at end of file From d7e497b6170d3fcbf73a80a49aa8f1bf19355767 Mon Sep 17 00:00:00 2001 From: Orange Date: Thu, 28 Aug 2025 23:57:22 +0300 Subject: [PATCH 2/3] Simplifies plane creation logic Refactors the plane creation function to directly compute the triangle vertices, removing unnecessary intermediate variables. This results in more concise and readable code. --- source/3d_primitives/plane.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/source/3d_primitives/plane.cpp b/source/3d_primitives/plane.cpp index dffbe42..938393a 100644 --- a/source/3d_primitives/plane.cpp +++ b/source/3d_primitives/plane.cpp @@ -9,13 +9,10 @@ namespace omath::primitives const Vector3& vertex_b, const Vector3& direction, const float size) noexcept { - Triangle> triangles; - const auto second_vertex_a = vertex_a + direction * size; - const auto second_vertex_b = vertex_b + direction * size; return std::array { - Triangle{second_vertex_a, vertex_a, vertex_b}, - Triangle{second_vertex_b, vertex_b, vertex_a} + Triangle{vertex_a + direction * size, vertex_a, vertex_b}, + Triangle{vertex_b + direction * size, vertex_b, vertex_a} }; } } // namespace omath::primitives \ No newline at end of file From a54dd4b52a8da13196b8e824509bf1eca86d8b10 Mon Sep 17 00:00:00 2001 From: Orange Date: Fri, 29 Aug 2025 00:11:31 +0300 Subject: [PATCH 3/3] Fixes plane triangle generation Corrects the order of vertices when constructing triangles for the plane primitive, addressing a potential winding order issue that could lead to incorrect surface normals and rendering. --- source/3d_primitives/plane.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/3d_primitives/plane.cpp b/source/3d_primitives/plane.cpp index 938393a..c541810 100644 --- a/source/3d_primitives/plane.cpp +++ b/source/3d_primitives/plane.cpp @@ -9,10 +9,11 @@ namespace omath::primitives const Vector3& vertex_b, const Vector3& direction, const float size) noexcept { + const auto second_vertex_a = vertex_a + direction * size; return std::array { - Triangle{vertex_a + direction * size, vertex_a, vertex_b}, - Triangle{vertex_b + direction * size, vertex_b, vertex_a} + Triangle{second_vertex_a, vertex_a, vertex_b}, + Triangle{second_vertex_a, vertex_b + direction * size, vertex_b} }; } } // namespace omath::primitives \ No newline at end of file