diff --git a/CMakeLists.txt b/CMakeLists.txt index ade1bb1..d87052c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,7 @@ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build if (OMATH_BUILD_AS_SHARED_LIBRARY) add_library(omath SHARED source/matrix.cpp) else() - add_library(omath STATIC source/matrix.cpp - source/matrix.cpp) + add_library(omath STATIC source/matrix.cpp) endif() message(STATUS "Building on ${CMAKE_HOST_SYSTEM_NAME}") diff --git a/include/omath/3d_primitives/box.hpp b/include/omath/3d_primitives/box.hpp new file mode 100644 index 0000000..a59b235 --- /dev/null +++ b/include/omath/3d_primitives/box.hpp @@ -0,0 +1,14 @@ +// +// Created by Vlad on 4/18/2025. +// + +#pragma once +#include + + +namespace omath::primitives +{ + [[nodiscard]] + std::array, 8> CreateBox(const Vector3& top, const Vector3& bottom, + const Vector3& dirForward, const Vector3& dirRight); +} diff --git a/source/3d_primitives/CMakeLists.txt b/source/3d_primitives/CMakeLists.txt new file mode 100644 index 0000000..ef4e0a4 --- /dev/null +++ b/source/3d_primitives/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(omath PRIVATE box.cpp) \ No newline at end of file diff --git a/source/3d_primitives/box.cpp b/source/3d_primitives/box.cpp new file mode 100644 index 0000000..652cef6 --- /dev/null +++ b/source/3d_primitives/box.cpp @@ -0,0 +1,32 @@ +// +// Created by Vlad on 4/18/2025. +// +#include "omath/3d_primitives/box.hpp" + +namespace omath::primitives +{ + + std::array, 8> CreateBox(const Vector3& top, const Vector3& bottom, + const Vector3& dirForward, + const Vector3& dirRight) + { + const auto height = top.DistTo(bottom); + const auto sideSize = height / 6.f; + + std::array, 8> points; + + points[0] = bottom + (dirForward + dirRight) * sideSize; + points[1] = bottom + (dirForward - dirRight) * sideSize; + + points[2] = bottom + (-dirForward + dirRight) * sideSize; + points[3] = bottom + (-dirForward - dirRight) * sideSize; + + points[4] = top + (dirForward + dirRight) * sideSize; + points[5] = top + (dirForward - dirRight) * sideSize; + + points[6] = top + (-dirForward + dirRight) * sideSize; + points[7] = top + (-dirForward - dirRight) * sideSize; + + return points; + } +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index f690fe3..1053134 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -7,4 +7,5 @@ add_subdirectory(projectile_prediction) add_subdirectory(pathfinding) add_subdirectory(projection) add_subdirectory(collision) -add_subdirectory(engines) \ No newline at end of file +add_subdirectory(engines) +add_subdirectory(3d_primitives) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 244f7bb..5f1c8e0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,6 +18,7 @@ add_executable(unit-tests general/unit_test_view_angles.cpp general/unit_test_angle.cpp general/unit_test_triangle.cpp + general/unit_test_box_primitive.cpp engines/unit_test_open_gl.cpp engines/unit_test_unity_engine.cpp diff --git a/tests/general/unit_test_box_primitive.cpp b/tests/general/unit_test_box_primitive.cpp new file mode 100644 index 0000000..f38e6e1 --- /dev/null +++ b/tests/general/unit_test_box_primitive.cpp @@ -0,0 +1,4 @@ +// +// Created by Vlad on 4/18/2025. +// +#include \ No newline at end of file