mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
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.
This commit is contained in:
16
include/omath/3d_primitives/plane.hpp
Normal file
16
include/omath/3d_primitives/plane.hpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 8/28/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "omath/triangle.hpp"
|
||||||
|
#include "omath/vector3.hpp"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
namespace omath::primitives
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
std::array<Triangle<Vector3<float>>, 2> create_plane(const Vector3<float>& vertex_a,
|
||||||
|
const Vector3<float>& vertex_b,
|
||||||
|
const Vector3<float>& direction, float size) noexcept;
|
||||||
|
}
|
||||||
21
source/3d_primitives/plane.cpp
Normal file
21
source/3d_primitives/plane.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 8/28/2025.
|
||||||
|
//
|
||||||
|
#include "omath/3d_primitives/plane.hpp"
|
||||||
|
|
||||||
|
namespace omath::primitives
|
||||||
|
{
|
||||||
|
std::array<Triangle<Vector3<float>>, 2> create_plane(const Vector3<float>& vertex_a,
|
||||||
|
const Vector3<float>& vertex_b,
|
||||||
|
const Vector3<float>& direction, const float size) noexcept
|
||||||
|
{
|
||||||
|
Triangle<Vector3<float>> 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
|
||||||
Reference in New Issue
Block a user