From 13e7adc8f680a5c113125c02962ccd6e2c06ca8e Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 9 Jul 2024 19:29:22 +0300 Subject: [PATCH] rebranding moment --- CMakeLists.txt | 6 ++-- include/{uml => omath}/Vector3.h | 8 ++++- include/{uml => omath}/Vector4.h | 4 +-- include/omath/angles.h | 11 ++++++ include/{uml => omath}/color.h | 6 ++-- include/{uml => omath}/matrix.h | 2 +- include/{uml => omath}/prediction/Engine.h | 8 ++--- .../{uml => omath}/prediction/Projectile.h | 4 +-- include/{uml => omath}/prediction/Target.h | 4 +-- include/uml/angles.h | 11 ------ readme.md | 20 +++++------ source/CMakeLists.txt | 2 +- source/Vector3.cpp | 35 +++++++++++++++++-- source/Vector4.cpp | 4 +-- source/angles.cpp | 8 ++--- source/color.cpp | 4 +-- source/matrix.cpp | 6 ++-- source/prediction/CMakeLists.txt | 2 +- source/prediction/Engine.cpp | 8 ++--- source/prediction/Projectile.cpp | 4 +-- source/prediction/Target.cpp | 4 +-- tests/CMakeLists.txt | 2 +- tests/UnitTestColor.cpp | 8 ++--- tests/UnitTestMatrix.cpp | 4 +-- 24 files changed, 105 insertions(+), 70 deletions(-) rename include/{uml => omath}/Vector3.h (88%) rename include/{uml => omath}/Vector4.h (97%) create mode 100644 include/omath/angles.h rename include/{uml => omath}/color.h (92%) rename include/{uml => omath}/matrix.h (99%) rename include/{uml => omath}/prediction/Engine.h (88%) rename include/{uml => omath}/prediction/Projectile.h (87%) rename include/{uml => omath}/prediction/Target.h (83%) delete mode 100644 include/uml/angles.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dfef16..909d358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.26) -project(uml) +project(omath) set(CMAKE_CXX_STANDARD 26) option(BUILD_TESTS "Build test programs" ON) -add_library(uml STATIC source/Vector3.cpp) +add_library(omath STATIC source/Vector3.cpp) add_subdirectory(source) add_subdirectory(extlibs) add_subdirectory(tests) -target_include_directories(uml PUBLIC include) \ No newline at end of file +target_include_directories(omath PUBLIC include) \ No newline at end of file diff --git a/include/uml/Vector3.h b/include/omath/Vector3.h similarity index 88% rename from include/uml/Vector3.h rename to include/omath/Vector3.h index 947bbc8..88d5d56 100644 --- a/include/uml/Vector3.h +++ b/include/omath/Vector3.h @@ -4,7 +4,7 @@ #pragma once -namespace uml +namespace omath { class Vector3 { public: @@ -57,12 +57,18 @@ namespace uml { return *reinterpret_cast(this); } + [[nodiscard]] Vector3 Cross(const Vector3 &v) const; [[nodiscard]] static Vector3 CreateVelocity(float pitch, float yaw, float speed); [[nodiscard]] float Sum() const; [[nodiscard]] float Sum2D() const; [[nodiscard]] Vector3 ViewAngleTo(const Vector3& other) const; + [[nodiscard]] static Vector3 ForwardVector(float pitch, float yaw); + [[nodiscard]] static Vector3 RightVector(float pitch, float yaw, float roll); + [[nodiscard]] static Vector3 UpVector(float pitch, float yaw, float roll); + + [[nodiscard]] Vector3 Normalized() const; }; diff --git a/include/uml/Vector4.h b/include/omath/Vector4.h similarity index 97% rename from include/uml/Vector4.h rename to include/omath/Vector4.h index a09a984..18ca171 100644 --- a/include/uml/Vector4.h +++ b/include/omath/Vector4.h @@ -3,9 +3,9 @@ // #pragma once -#include +#include -namespace uml +namespace omath { class Vector4 : public Vector3 { diff --git a/include/omath/angles.h b/include/omath/angles.h new file mode 100644 index 0000000..0140092 --- /dev/null +++ b/include/omath/angles.h @@ -0,0 +1,11 @@ +// +// Created by vlad on 11/6/23. +// + +#pragma once + +namespace omath::angles +{ + [[nodiscard]] constexpr float RadiansToDegrees(float rads); + [[nodiscard]] constexpr float DegreesToRadians(float degrees); +} \ No newline at end of file diff --git a/include/uml/color.h b/include/omath/color.h similarity index 92% rename from include/uml/color.h rename to include/omath/color.h index f3f3795..856833f 100644 --- a/include/uml/color.h +++ b/include/omath/color.h @@ -4,12 +4,12 @@ #pragma once -#include "uml/Vector3.h" +#include "omath/Vector3.h" #include -#include "uml/Vector4.h" +#include "omath/Vector4.h" -namespace uml::color +namespace omath::color { struct HSV { diff --git a/include/uml/matrix.h b/include/omath/matrix.h similarity index 99% rename from include/uml/matrix.h rename to include/omath/matrix.h index afb09f6..6ac8003 100644 --- a/include/uml/matrix.h +++ b/include/omath/matrix.h @@ -4,7 +4,7 @@ #include -namespace uml +namespace omath { class Vector3; diff --git a/include/uml/prediction/Engine.h b/include/omath/prediction/Engine.h similarity index 88% rename from include/uml/prediction/Engine.h rename to include/omath/prediction/Engine.h index 8a94488..3a32f92 100644 --- a/include/uml/prediction/Engine.h +++ b/include/omath/prediction/Engine.h @@ -5,12 +5,12 @@ #pragma once #include -#include "uml/Vector3.h" -#include "uml/prediction/Projectile.h" -#include "uml/prediction/Target.h" +#include "omath/Vector3.h" +#include "omath/prediction/Projectile.h" +#include "omath/prediction/Target.h" -namespace uml::prediction +namespace omath::prediction { class Engine { diff --git a/include/uml/prediction/Projectile.h b/include/omath/prediction/Projectile.h similarity index 87% rename from include/uml/prediction/Projectile.h rename to include/omath/prediction/Projectile.h index 58603bd..48038f8 100644 --- a/include/uml/prediction/Projectile.h +++ b/include/omath/prediction/Projectile.h @@ -3,10 +3,10 @@ // #pragma once -#include "uml/Vector3.h" +#include "omath/Vector3.h" -namespace uml::prediction +namespace omath::prediction { class Projectile final { diff --git a/include/uml/prediction/Target.h b/include/omath/prediction/Target.h similarity index 83% rename from include/uml/prediction/Target.h rename to include/omath/prediction/Target.h index db5eb46..bb21fb0 100644 --- a/include/uml/prediction/Target.h +++ b/include/omath/prediction/Target.h @@ -3,10 +3,10 @@ // #pragma once -#include "uml/Vector3.h" +#include "omath/Vector3.h" -namespace uml::prediction +namespace omath::prediction { class Target final { diff --git a/include/uml/angles.h b/include/uml/angles.h deleted file mode 100644 index 39b9a07..0000000 --- a/include/uml/angles.h +++ /dev/null @@ -1,11 +0,0 @@ -// -// Created by vlad on 11/6/23. -// - -#pragma once - -namespace uml::angles -{ - [[nodiscard]] float RadiansToDegrees(float rads); - [[nodiscard]] float DegreesToRadians(float degrees); -} \ No newline at end of file diff --git a/readme.md b/readme.md index 8beb299..2e2f2c4 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ -# Universal Math Library (UML) +# Oranges's Math Library (omath) ## Overview -The Universal Math Library (UML) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research. +Oranges's Math Library (omath) is a comprehensive, open-source library aimed at providing efficient, reliable, and versatile mathematical functions and algorithms. Developed primarily in C++, this library is designed to cater to a wide range of mathematical operations essential in scientific computing, engineering, and academic research. ## Features - **Efficiency**: Optimized for performance, ensuring quick computations. @@ -31,25 +31,25 @@ The Universal Math Library (UML) is a comprehensive, open-source library aimed a ## Usage Simple world to screen function ```c++ -std::optional WorldToScreen(uml::Vector3 worldPosition, float width, float height) +std::optional WorldToScreen(omath::Vector3 worldPosition, float width, float height) { auto projected = (GetViewProjectionMatrix() * worldPosition).transpose(); projected /= projected.at(0, 3); - const auto out = projected * uml::matrix::to_screen_matrix(width, - height); + const auto out = projected * omath::matrix::to_screen_matrix(width, + height); - if (out.at(0,2) <= 0.f) + if (out.at(0, 2) <= 0.f) return std::nullopt; - auto final = uml::Vector3(out.at(0,0), - out.at(0, 1), - out.at(0,2)); + auto final = omath::Vector3(out.at(0, 0), + out.at(0, 1), + out.at(0, 3)); return {final}; } ``` ## Contributing -Contributions to UML are welcome! Please read `CONTRIBUTING.md` for details on our code of conduct and the process for submitting pull requests. +Contributions to `omath` are welcome! Please read `CONTRIBUTING.md` for details on our code of conduct and the process for submitting pull requests. ## License This project is licensed under the GPL V3 - see the `LICENSE` file for details. diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index c8faebe..7886760 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(uml PRIVATE +target_sources(omath PRIVATE Vector3.cpp matrix.cpp angles.cpp diff --git a/source/Vector3.cpp b/source/Vector3.cpp index 8f0f842..7644794 100644 --- a/source/Vector3.cpp +++ b/source/Vector3.cpp @@ -2,11 +2,11 @@ // Created by vlad on 10/28/23. // -#include +#include #include -#include +#include -namespace uml +namespace omath { bool Vector3::operator==(const Vector3 &src) const { @@ -211,6 +211,35 @@ namespace uml }; } + Vector3 Vector3::ForwardVector(const float pitch, const float yaw) + { + const auto cosPitch = std::cos(angles::DegreesToRadians(pitch)); + const auto sinPitch = std::sin(angles::DegreesToRadians(pitch)); + + const auto cosYaw = std::cos(angles::DegreesToRadians(yaw)); + const auto sinYaw = std::sin(angles::DegreesToRadians(yaw)); + + + return {cosPitch*cosYaw, cosPitch*sinYaw, sinPitch}; + } + + Vector3 Vector3::RightVector(const float pitch, const float yaw, const float roll) + { + const auto cosPitch = std::cos(angles::DegreesToRadians(pitch)); + const auto sinPitch = std::sin(angles::DegreesToRadians(pitch)); + + const auto cosYaw = std::cos(angles::DegreesToRadians(yaw)); + const auto sinYaw = std::sin(angles::DegreesToRadians(yaw)); + + const auto cosRoll = std::cos(angles::DegreesToRadians(yaw)); + const auto sinRoll = std::sin(angles::DegreesToRadians(yaw)); + + + return {-sinRoll*sinPitch*cosYaw + -cosRoll*-sinYaw, + -sinRoll*sinPitch*sinYaw + -cosRoll*cosYaw, + sinRoll*cosPitch}; + } + Vector3 Vector3::Cross(const Vector3 &v) const { return { diff --git a/source/Vector4.cpp b/source/Vector4.cpp index 62a834b..526a9d1 100644 --- a/source/Vector4.cpp +++ b/source/Vector4.cpp @@ -2,12 +2,12 @@ // Vector4.cpp // -#include "uml/Vector4.h" +#include "omath/Vector4.h" #include #include -namespace uml +namespace omath { bool Vector4::operator==(const Vector4& src) const { diff --git a/source/angles.cpp b/source/angles.cpp index 26b9f0f..14d1722 100644 --- a/source/angles.cpp +++ b/source/angles.cpp @@ -2,18 +2,18 @@ // Created by vlad on 11/6/23. // -#include "uml/angles.h" +#include "omath/angles.h" #include -namespace uml::angles +namespace omath::angles { - float RadiansToDegrees(const float radiands) + constexpr float RadiansToDegrees(const float radiands) { return radiands * (180.f / std::numbers::pi_v); } - float DegreesToRadians(const float degrees) + constexpr float DegreesToRadians(const float degrees) { return degrees * (std::numbers::pi_v / 180.f); } diff --git a/source/color.cpp b/source/color.cpp index 0d09319..880c431 100644 --- a/source/color.cpp +++ b/source/color.cpp @@ -2,12 +2,12 @@ // Created by vlad on 2/4/24. // -#include "uml/color.h" +#include "omath/color.h" #include #include -namespace uml::color +namespace omath::color { Vector3 Blend(const Vector3 &first, const Vector3 &second, float ratio) { diff --git a/source/matrix.cpp b/source/matrix.cpp index b606beb..2298d9b 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -3,17 +3,17 @@ * Created by Alpatov Softworks with love in Russia. */ -#include "uml/matrix.h" +#include "omath/matrix.h" #include -#include "uml/Vector3.h" +#include "omath/Vector3.h" #include #include #include -namespace uml +namespace omath { matrix::matrix(const size_t rows, const size_t columns) { diff --git a/source/prediction/CMakeLists.txt b/source/prediction/CMakeLists.txt index 6964df7..da6b5de 100644 --- a/source/prediction/CMakeLists.txt +++ b/source/prediction/CMakeLists.txt @@ -1 +1 @@ -target_sources(uml PRIVATE Engine.cpp Projectile.cpp Target.cpp) \ No newline at end of file +target_sources(omath PRIVATE Engine.cpp Projectile.cpp Target.cpp) \ No newline at end of file diff --git a/source/prediction/Engine.cpp b/source/prediction/Engine.cpp index 09a5877..80cf447 100644 --- a/source/prediction/Engine.cpp +++ b/source/prediction/Engine.cpp @@ -3,15 +3,15 @@ // -#include "uml/prediction/Engine.h" +#include "omath/prediction/Engine.h" #include -#include +#include -namespace uml::prediction +namespace omath::prediction { Engine::Engine(const float gravityConstant, const float simulationTimeStep, - const float maximumSimulationTime, float distanceTolerance) + const float maximumSimulationTime, const float distanceTolerance) : m_gravityConstant(gravityConstant), m_simulationTimeStep(simulationTimeStep), m_maximumSimulationTime(maximumSimulationTime), diff --git a/source/prediction/Projectile.cpp b/source/prediction/Projectile.cpp index e65144d..3ce5164 100644 --- a/source/prediction/Projectile.cpp +++ b/source/prediction/Projectile.cpp @@ -2,11 +2,11 @@ // Created by Vlad on 6/9/2024. // -#include "uml/prediction/Projectile.h" +#include "omath/prediction/Projectile.h" #include -namespace uml::prediction +namespace omath::prediction { Vector3 Projectile::CalculateVelocity(const float pitch, const float yaw) const { diff --git a/source/prediction/Target.cpp b/source/prediction/Target.cpp index 9783897..64c58a1 100644 --- a/source/prediction/Target.cpp +++ b/source/prediction/Target.cpp @@ -2,11 +2,11 @@ // Created by Vlad on 6/9/2024. // -#include "uml/prediction/Target.h" +#include "omath/prediction/Target.h" #include -namespace uml::prediction +namespace omath::prediction { Vector3 Target::PredictPosition(const float time, const float gravity) const { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 12feaf5..55d4f36 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,4 +6,4 @@ file(GLOB TEST_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) include(GoogleTest) add_executable(unit-tests UnitTestColor.cpp UnitTestMatrix.cpp) -target_link_libraries(unit-tests PRIVATE gtest gtest_main uml) \ No newline at end of file +target_link_libraries(unit-tests PRIVATE gtest gtest_main omath) \ No newline at end of file diff --git a/tests/UnitTestColor.cpp b/tests/UnitTestColor.cpp index 3eb3ea0..5ced212 100644 --- a/tests/UnitTestColor.cpp +++ b/tests/UnitTestColor.cpp @@ -1,11 +1,11 @@ #include -#include +#include TEST(x,x) { - uml::prediction::Target target{.m_origin = {100, 0, 60}, .m_velocity = {0, 0, 0}, .m_isAirborne = false}; - uml::prediction::Projectile proj = {.m_origin = {3,2,1}, .m_launchSpeed = 5000, .m_gravityScale= 0.4}; - auto vel = uml::prediction::Engine(400, 1.f / 1000.f, 50, 5.f).MaybeCalculateAimPoint(proj, target); + omath::prediction::Target target{.m_origin = {100, 0, 60}, .m_velocity = {0, 0, 0}, .m_isAirborne = false}; + omath::prediction::Projectile proj = {.m_origin = {3,2,1}, .m_launchSpeed = 5000, .m_gravityScale= 0.4}; + auto vel = omath::prediction::Engine(400, 1.f / 1000.f, 50, 5.f).MaybeCalculateAimPoint(proj, target); auto pitch = proj.m_origin.ViewAngleTo(vel.value()).x; diff --git a/tests/UnitTestMatrix.cpp b/tests/UnitTestMatrix.cpp index ecf0693..4b98613 100644 --- a/tests/UnitTestMatrix.cpp +++ b/tests/UnitTestMatrix.cpp @@ -2,13 +2,13 @@ // Created by vlad on 5/18/2024. // #include -#include +#include #include TEST(UnitTestMatrix, ToString) { - uml::matrix matrix(2, 2); + omath::matrix matrix(2, 2); matrix.set(1.1); const auto str = matrix.to_string();