added box

This commit is contained in:
2025-04-18 00:43:46 +03:00
parent baf7ee8f88
commit 492ddfd566
7 changed files with 55 additions and 3 deletions

View File

@@ -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}")

View File

@@ -0,0 +1,14 @@
//
// Created by Vlad on 4/18/2025.
//
#pragma once
#include <array>
namespace omath::primitives
{
[[nodiscard]]
std::array<Vector3<float>, 8> CreateBox(const Vector3<float>& top, const Vector3<float>& bottom,
const Vector3<float>& dirForward, const Vector3<float>& dirRight);
}

View File

@@ -0,0 +1 @@
target_sources(omath PRIVATE box.cpp)

View File

@@ -0,0 +1,32 @@
//
// Created by Vlad on 4/18/2025.
//
#include "omath/3d_primitives/box.hpp"
namespace omath::primitives
{
std::array<Vector3<float>, 8> CreateBox(const Vector3<float>& top, const Vector3<float>& bottom,
const Vector3<float>& dirForward,
const Vector3<float>& dirRight)
{
const auto height = top.DistTo(bottom);
const auto sideSize = height / 6.f;
std::array<Vector3<float>, 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;
}
}

View File

@@ -7,4 +7,5 @@ add_subdirectory(projectile_prediction)
add_subdirectory(pathfinding)
add_subdirectory(projection)
add_subdirectory(collision)
add_subdirectory(engines)
add_subdirectory(engines)
add_subdirectory(3d_primitives)

View File

@@ -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

View File

@@ -0,0 +1,4 @@
//
// Created by Vlad on 4/18/2025.
//
#include <omath/3d_primitives/box.hpp>