mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
rebranding moment
This commit is contained in:
@@ -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)
|
||||
target_include_directories(omath PUBLIC include)
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace uml
|
||||
namespace omath
|
||||
{
|
||||
class Vector3 {
|
||||
public:
|
||||
@@ -57,12 +57,18 @@ namespace uml
|
||||
{
|
||||
return *reinterpret_cast<type*>(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;
|
||||
};
|
||||
@@ -3,9 +3,9 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <uml/Vector3.h>
|
||||
#include <omath/Vector3.h>
|
||||
|
||||
namespace uml
|
||||
namespace omath
|
||||
{
|
||||
class Vector4 : public Vector3
|
||||
{
|
||||
11
include/omath/angles.h
Normal file
11
include/omath/angles.h
Normal file
@@ -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);
|
||||
}
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "uml/Vector3.h"
|
||||
#include "omath/Vector3.h"
|
||||
#include <cstdint>
|
||||
#include "uml/Vector4.h"
|
||||
#include "omath/Vector4.h"
|
||||
|
||||
|
||||
namespace uml::color
|
||||
namespace omath::color
|
||||
{
|
||||
struct HSV
|
||||
{
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace uml
|
||||
namespace omath
|
||||
{
|
||||
class Vector3;
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#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
|
||||
{
|
||||
@@ -3,10 +3,10 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "uml/Vector3.h"
|
||||
#include "omath/Vector3.h"
|
||||
|
||||
|
||||
namespace uml::prediction
|
||||
namespace omath::prediction
|
||||
{
|
||||
class Projectile final
|
||||
{
|
||||
@@ -3,10 +3,10 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "uml/Vector3.h"
|
||||
#include "omath/Vector3.h"
|
||||
|
||||
|
||||
namespace uml::prediction
|
||||
namespace omath::prediction
|
||||
{
|
||||
class Target final
|
||||
{
|
||||
@@ -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);
|
||||
}
|
||||
16
readme.md
16
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<uml::Vector3> WorldToScreen(uml::Vector3 worldPosition, float width, float height)
|
||||
std::optional<omath::Vector3> 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,
|
||||
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),
|
||||
auto final = omath::Vector3(out.at(0, 0),
|
||||
out.at(0, 1),
|
||||
out.at(0,2));
|
||||
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.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
target_sources(uml PRIVATE
|
||||
target_sources(omath PRIVATE
|
||||
Vector3.cpp
|
||||
matrix.cpp
|
||||
angles.cpp
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// Created by vlad on 10/28/23.
|
||||
//
|
||||
|
||||
#include <uml/Vector3.h>
|
||||
#include <omath/Vector3.h>
|
||||
#include <cmath>
|
||||
#include <uml/angles.h>
|
||||
#include <omath/angles.h>
|
||||
|
||||
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 {
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// Vector4.cpp
|
||||
//
|
||||
|
||||
#include "uml/Vector4.h"
|
||||
#include "omath/Vector4.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace uml
|
||||
namespace omath
|
||||
{
|
||||
bool Vector4::operator==(const Vector4& src) const
|
||||
{
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
// Created by vlad on 11/6/23.
|
||||
//
|
||||
|
||||
#include "uml/angles.h"
|
||||
#include "omath/angles.h"
|
||||
#include <numbers>
|
||||
|
||||
|
||||
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>);
|
||||
}
|
||||
|
||||
float DegreesToRadians(const float degrees)
|
||||
constexpr float DegreesToRadians(const float degrees)
|
||||
{
|
||||
return degrees * (std::numbers::pi_v<float> / 180.f);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// Created by vlad on 2/4/24.
|
||||
//
|
||||
|
||||
#include "uml/color.h"
|
||||
#include "omath/color.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace uml::color
|
||||
namespace omath::color
|
||||
{
|
||||
Vector3 Blend(const Vector3 &first, const Vector3 &second, float ratio)
|
||||
{
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
* Created by Alpatov Softworks with love in Russia.
|
||||
*/
|
||||
|
||||
#include "uml/matrix.h"
|
||||
#include "omath/matrix.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
#include "uml/Vector3.h"
|
||||
#include "omath/Vector3.h"
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace uml
|
||||
namespace omath
|
||||
{
|
||||
matrix::matrix(const size_t rows, const size_t columns)
|
||||
{
|
||||
|
||||
@@ -1 +1 @@
|
||||
target_sources(uml PRIVATE Engine.cpp Projectile.cpp Target.cpp)
|
||||
target_sources(omath PRIVATE Engine.cpp Projectile.cpp Target.cpp)
|
||||
@@ -3,15 +3,15 @@
|
||||
//
|
||||
|
||||
|
||||
#include "uml/prediction/Engine.h"
|
||||
#include "omath/prediction/Engine.h"
|
||||
#include <cmath>
|
||||
#include <uml/angles.h>
|
||||
#include <omath/angles.h>
|
||||
|
||||
|
||||
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),
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#include "uml/prediction/Projectile.h"
|
||||
#include "omath/prediction/Projectile.h"
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace uml::prediction
|
||||
namespace omath::prediction
|
||||
{
|
||||
Vector3 Projectile::CalculateVelocity(const float pitch, const float yaw) const
|
||||
{
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#include "uml/prediction/Target.h"
|
||||
#include "omath/prediction/Target.h"
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace uml::prediction
|
||||
namespace omath::prediction
|
||||
{
|
||||
Vector3 Target::PredictPosition(const float time, const float gravity) const
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath)
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <uml/prediction/Engine.h>
|
||||
#include <omath/prediction/Engine.h>
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// Created by vlad on 5/18/2024.
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
#include <uml/matrix.h>
|
||||
#include <omath/matrix.h>
|
||||
#include <print>
|
||||
|
||||
|
||||
TEST(UnitTestMatrix, ToString)
|
||||
{
|
||||
uml::matrix matrix(2, 2);
|
||||
omath::matrix matrix(2, 2);
|
||||
matrix.set(1.1);
|
||||
const auto str = matrix.to_string();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user