Compare commits

...

34 Commits

Author SHA1 Message Date
baf7ee8f88 fixed include 2025-04-16 20:35:17 +03:00
9fde11733f Merge pull request #37 from orange-cpp/u/engine_rotation_mats
U/engine rotation mats
2025-04-16 23:21:58 +03:00
0069b8bd96 improved openg gl rotation matrix, added tests 2025-04-16 19:11:02 +03:00
127bae0b78 added tests for source 2025-04-16 18:53:31 +03:00
bed204a663 added unit tests 2025-04-16 18:35:50 +03:00
3f6ea010dc fixed formating 2025-04-16 17:52:57 +03:00
592a98f38c removed method from Mat added method for unity 2025-04-16 17:52:19 +03:00
7873047550 added func
added rotation matrix for opengl

updated unit tests
2025-04-16 17:40:00 +03:00
1601f3cbc8 added func
added rotation matrix for opengl
2025-04-16 17:40:00 +03:00
2180f8ab97 removed whitespaces 2025-04-16 12:21:10 +03:00
b613ff9ef1 added missing header 2025-04-13 23:15:27 +03:00
145eadfffa Merge pull request #36 from orange-cpp/u/orange-cpp/small-refactoring
U/orange cpp/small refactoring
2025-04-12 13:34:28 +03:00
14acebad5f fixed tests 2025-04-12 00:04:07 +03:00
4a7a631932 added const method to mat 2025-04-11 23:57:56 +03:00
e08c22f604 added new build option 2025-04-11 23:54:56 +03:00
1b47f45af9 improved naming 2025-04-11 23:30:07 +03:00
466d8f7bec improvement 2025-04-11 23:20:16 +03:00
3631c5d698 replaced with STL relization 2025-04-11 23:10:02 +03:00
b58956efe3 added missing header 2025-04-11 22:59:56 +03:00
fc1e0c62b8 disabled tests 2025-04-05 20:03:39 +03:00
Orange
8e861b8a85 updated read me 2025-04-05 13:28:28 +03:00
Orange
55085604fd added include 2025-04-05 13:20:18 +03:00
Orange
7b712ed960 fixed for clang 2025-04-05 13:00:00 +03:00
138c996393 oops 2025-03-29 22:03:30 +03:00
0f2a858306 fixed in some cases confilcting with win api 2025-03-29 21:57:35 +03:00
ea6c1cc929 fix 2025-03-29 18:20:17 +03:00
eeb6e40909 Merge pull request #35 from orange-cpp/u/orange-cpp/imrpoved-color
U/orange cpp/imrpoved color
2025-03-29 17:43:36 +03:00
d72ad663cd added new methods 2025-03-29 05:41:55 +03:00
3e75d32f59 fixed style 2025-03-29 04:00:35 +03:00
a8ce5cbaa0 added vcpkg imgui package auto link 2025-03-29 01:56:09 +03:00
79f76a0755 added new option 2025-03-29 01:53:04 +03:00
5773cc7798 improved imgui handling 2025-03-24 21:48:51 +03:00
b6b0184523 fixed for clang 2025-03-24 06:48:51 +03:00
a797dd134a Update README.md 2025-03-24 06:46:02 +03:00
28 changed files with 479 additions and 166 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/cmake-build/ /cmake-build/
/.idea /.idea
/out /out
*.DS_Store

View File

@@ -11,23 +11,47 @@ option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON) option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF) option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF) option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF)
option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF)
option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build to improve general performance" ON)
if (OMATH_BUILD_AS_SHARED_LIBRARY) if (OMATH_BUILD_AS_SHARED_LIBRARY)
add_library(omath SHARED source/Matrix.cpp) add_library(omath SHARED source/matrix.cpp)
else() else()
add_library(omath STATIC source/Matrix.cpp) add_library(omath STATIC source/matrix.cpp
source/matrix.cpp)
endif() endif()
message(STATUS "Building on ${CMAKE_HOST_SYSTEM_NAME}")
add_library(omath::omath ALIAS omath) add_library(omath::omath ALIAS omath)
if (OMATH_IMGUI_INTEGRATION) if (OMATH_IMGUI_INTEGRATION)
target_compile_definitions(omath PUBLIC OMATH_IMGUI_INTEGRATION) target_compile_definitions(omath PUBLIC OMATH_IMGUI_INTEGRATION)
# IMGUI is being linked as submodule
if(TARGET imgui)
target_link_libraries(omath PUBLIC imgui)
install(TARGETS imgui
EXPORT omathTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
else()
# Assume that IMGUI linked via VCPKG.
find_package(imgui CONFIG REQUIRED)
target_link_libraries(omath PUBLIC imgui::imgui)
endif()
endif() endif()
if (OMATH_USE_AVX2) if (OMATH_USE_AVX2)
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2) target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
endif() endif()
if (OMATH_SUPRESS_SAFETY_CHECKS)
target_compile_definitions(omath PUBLIC OMATH_SUPRESS_SAFETY_CHECKS)
endif()
set_target_properties(omath PROPERTIES set_target_properties(omath PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
@@ -36,6 +60,12 @@ set_target_properties(omath PROPERTIES
CXX_STANDARD 23 CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON) CXX_STANDARD_REQUIRED ON)
if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
set_target_properties(omath PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(omath PRIVATE -mavx2 -mfma) target_compile_options(omath PRIVATE -mavx2 -mfma)
endif() endif()

View File

@@ -64,6 +64,38 @@
"cacheVariables": { "cacheVariables": {
"CMAKE_BUILD_TYPE": "Release" "CMAKE_BUILD_TYPE": "Release"
} }
},
{
"name": "darwin-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/cmake-build/build/${presetName}",
"installDir": "${sourceDir}/cmake-build/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "darwin-debug",
"displayName": "Darwin Debug",
"inherits": "darwin-base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "darwin-release",
"displayName": "Darwin Release",
"inherits": "darwin-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
} }
] ]
} }

View File

@@ -20,6 +20,23 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces. - **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution - **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
- **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types! - **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types!
## Supported Render Pipelines
| ENGINE | SUPPORT |
|----------|---------|
| Source | ✅YES |
| Unity | ✅YES |
| IWEngine | ✅YES |
| Unreal | ❌NO |
## Supported Operating Systems
| OS | SUPPORT |
|----------------|---------|
| Windows 10/11 | ✅YES |
| Linux | ✅YES |
| Darwin (MacOS) | ✅YES |
## ⏬ Getting Started ## ⏬ Getting Started
### Prerequisites ### Prerequisites
- C++ Compiler - C++ Compiler
@@ -65,9 +82,9 @@ TEST(UnitTestProjection, IsPointOnScreen)
EXPECT_TRUE(proj.has_value()); EXPECT_TRUE(proj.has_value());
} }
``` ```
## Showcase
<details> <details>
<summary>OMATH for making cheats</summary> <summary>OMATH for making cheats (click to open)</summary>
With `omath/projection` module you can achieve simple ESP hack for powered by Source/Unreal/Unity engine games, like [Apex Legends](https://store.steampowered.com/app/1172470/Apex_Legends/). With `omath/projection` module you can achieve simple ESP hack for powered by Source/Unreal/Unity engine games, like [Apex Legends](https://store.steampowered.com/app/1172470/Apex_Legends/).

View File

@@ -3,8 +3,10 @@
// //
#pragma once #pragma once
#include "omath/angles.hpp"
#include <algorithm> #include <algorithm>
#include <utility>
#include "omath/angles.hpp"
namespace omath namespace omath
{ {
@@ -15,7 +17,7 @@ namespace omath
}; };
template<class Type = float, Type min = Type(0), Type max = Type(360), AngleFlags flags = AngleFlags::Normalized> template<class Type = float, Type min = Type(0), Type max = Type(360), AngleFlags flags = AngleFlags::Normalized>
requires std::is_arithmetic_v<Type> requires std::is_arithmetic_v<Type>
class Angle class Angle
{ {
Type m_angle; Type m_angle;
@@ -32,6 +34,7 @@ namespace omath
std::unreachable(); std::unreachable();
} }
} }
public: public:
[[nodiscard]] [[nodiscard]]
constexpr static Angle FromDegrees(const Type& degrees) constexpr static Angle FromDegrees(const Type& degrees)
@@ -40,7 +43,6 @@ namespace omath
} }
constexpr Angle() : m_angle(0) constexpr Angle() : m_angle(0)
{ {
} }
[[nodiscard]] [[nodiscard]]
constexpr static Angle FromRadians(const Type& degrees) constexpr static Angle FromRadians(const Type& degrees)
@@ -147,4 +149,4 @@ namespace omath
return Angle{-m_angle}; return Angle{-m_angle};
} }
}; };
} } // namespace omath

View File

@@ -8,115 +8,166 @@
#include "omath/vector3.hpp" #include "omath/vector3.hpp"
#include "omath/vector4.hpp" #include "omath/vector4.hpp"
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
namespace omath namespace omath
{ {
struct HSV struct HSV
{ {
float m_hue{}; float hue{};
float m_saturation{}; float saturation{};
float m_value{}; float value{};
}; };
class Color final : public Vector4<float> class Color final : public Vector4<float>
{ {
public: public:
constexpr Color(const float r, const float g, const float b, const float a) : Vector4(r,g,b,a) constexpr Color(const float r, const float g, const float b, const float a) : Vector4(r, g, b, a)
{
Clamp(0.f, 1.f);
}
constexpr explicit Color() = default;
[[nodiscard]]
constexpr static Color FromRGBA(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a)
{
return Color{Vector4(r, g, b, a) / 255.f};
}
[[nodiscard]]
constexpr static Color FromHSV(float hue, const float saturation, const float value)
{
float r{}, g{}, b{};
hue = std::clamp(hue, 0.f, 1.f);
const int i = static_cast<int>(hue * 6.f);
const float f = hue * 6 - i;
const float p = value * (1 - saturation);
const float q = value * (1 - f * saturation);
const float t = value * (1 - (1 - f) * saturation);
switch (i % 6)
{ {
Clamp(0.f, 1.f); case 0:
r = value, g = t, b = p;
break;
case 1:
r = q, g = value, b = p;
break;
case 2:
r = p, g = value, b = t;
break;
case 3:
r = p, g = q, b = value;
break;
case 4:
r = t, g = p, b = value;
break;
case 5:
r = value, g = p, b = q;
break;
default:
return {0.f, 0.f, 0.f, 0.f};
} }
constexpr explicit Color() : Vector4() return {r, g, b, 1.f};
{ }
} [[nodiscard]]
[[nodiscard]] constexpr static Color FromHSV(const HSV& hsv)
constexpr static Color FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
{ return FromHSV(hsv.hue, hsv.saturation, hsv.value);
return Color{Vector4(r, g, b, a) / 255.f}; }
}
[[nodiscard]] [[nodiscard]]
constexpr static Color FromHSV(float hue, float saturation, float value) constexpr HSV ToHSV() const
{ {
float r{}, g{}, b{}; HSV hsvData;
hue = std::clamp(hue, 0.f, 1.f); const float& red = x;
const float& green = y;
const float& blue = z;
const int i = static_cast<int>(hue * 6.f); const float max = std::max({red, green, blue});
const float f = hue * 6 - i; const float min = std::min({red, green, blue});
const float p = value * (1 - saturation); const float delta = max - min;
const float q = value * (1 - f * saturation);
const float t = value * (1 - (1 - f) * saturation);
switch (i % 6)
{
case 0: r = value, g = t, b = p; break;
case 1: r = q, g = value, b = p; break;
case 2: r = p, g = value, b = t; break;
case 3: r = p, g = q, b = value; break;
case 4: r = t, g = p, b = value; break;
case 5: r = value, g = p, b = q; break;
default: return {0.f, 0.f, 0.f, 0.f};
}
return {r, g, b, 1.f};
}
[[nodiscard]]
constexpr HSV ToHSV() const
{
HSV hsvData;
const float& red = x;
const float& green = y;
const float& blue = z;
const float max = std::max({red, green, blue});
const float min = std::min({red, green, blue});
const float delta = max - min;
if (delta == 0.f) if (delta == 0.f)
hsvData.m_hue = 0.f; hsvData.hue = 0.f;
else if (max == red) else if (max == red)
hsvData.m_hue = 60.f * (std::fmodf(((green - blue) / delta), 6.f)); hsvData.hue = 60.f * (std::fmodf(((green - blue) / delta), 6.f));
else if (max == green) else if (max == green)
hsvData.m_hue = 60.f * (((blue - red) / delta) + 2.f); hsvData.hue = 60.f * (((blue - red) / delta) + 2.f);
else if (max == blue) else if (max == blue)
hsvData.m_hue = 60.f * (((red - green) / delta) + 4.f); hsvData.hue = 60.f * (((red - green) / delta) + 4.f);
if (hsvData.m_hue < 0.f) if (hsvData.hue < 0.f)
hsvData.m_hue += 360.f; hsvData.hue += 360.f;
hsvData.m_hue /= 360.f; hsvData.hue /= 360.f;
hsvData.m_saturation = max == 0.f ? 0.f : delta / max; hsvData.saturation = max == 0.f ? 0.f : delta / max;
hsvData.m_value = max; hsvData.value = max;
return hsvData; return hsvData;
} }
constexpr explicit Color(const Vector4& vec) : Vector4(vec) constexpr explicit Color(const Vector4& vec) : Vector4(vec)
{ {
Clamp(0.f, 1.f); Clamp(0.f, 1.f);
} }
constexpr void SetHue(const float hue)
{
auto hsv = ToHSV();
hsv.hue = hue;
[[nodiscard]] *this = FromHSV(hsv);
constexpr Color Blend(const Color& other, float ratio) const }
{
return Color( (*this * (1.f - ratio)) + (other * ratio) );
}
[[nodiscard]] static constexpr Color Red() {return {1.f, 0.f, 0.f, 1.f};} constexpr void SetSaturation(const float saturation)
[[nodiscard]] static constexpr Color Green() {return {0.f, 1.f, 0.f, 1.f};} {
[[nodiscard]] static constexpr Color Blue() {return {0.f, 0.f, 1.f, 1.f};} auto hsv = ToHSV();
hsv.saturation = saturation;
*this = FromHSV(hsv);
}
constexpr void SetValue(const float value)
{
auto hsv = ToHSV();
hsv.value = value;
*this = FromHSV(hsv);
}
[[nodiscard]]
constexpr Color Blend(const Color& other, float ratio) const
{
ratio = std::clamp(ratio, 0.f, 1.f);
return Color(*this * (1.f - ratio) + other * ratio);
}
[[nodiscard]] static constexpr Color Red()
{
return {1.f, 0.f, 0.f, 1.f};
}
[[nodiscard]] static constexpr Color Green()
{
return {0.f, 1.f, 0.f, 1.f};
}
[[nodiscard]] static constexpr Color Blue()
{
return {0.f, 0.f, 1.f, 1.f};
}
}; };
} // namespace omath
[[nodiscard]]
constexpr Color Blend(const Color& first, const Color& second, float ratio)
{
return Color{first * (1.f - std::clamp(ratio, 0.f, 1.f)) + second * ratio};
}
}

View File

@@ -16,8 +16,10 @@ namespace omath::iw_engine
[[nodiscard]] [[nodiscard]]
Vector3<float> UpVector(const ViewAngles& angles); Vector3<float> UpVector(const ViewAngles& angles);
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin); [[nodiscard]]
Mat4x4 RotationMatrix(const ViewAngles& angles);
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
[[nodiscard]] [[nodiscard]]
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);

View File

@@ -17,9 +17,10 @@ namespace omath::opengl_engine
using Mat4x4 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>; using Mat4x4 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>;
using Mat3x3 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>; using Mat3x3 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>;
using Mat1x3 = Mat<1, 3, float, MatStoreType::COLUMN_MAJOR>; using Mat1x3 = Mat<1, 3, float, MatStoreType::COLUMN_MAJOR>;
using PitchAngle = Angle<float, 0.f, 180.f, AngleFlags::Clamped>; using PitchAngle = Angle<float, -90.f, 90.f, AngleFlags::Clamped>;
using YawAngle = Angle<float, 0.f, 360.f, AngleFlags::Normalized>; using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
using RollAngle = Angle<float, 0.f, 360.f, AngleFlags::Normalized>; using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>; using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>;
} }

View File

@@ -18,6 +18,8 @@ namespace omath::opengl_engine
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin); [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
[[nodiscard]]
Mat4x4 RotationMatrix(const ViewAngles& angles);
[[nodiscard]] [[nodiscard]]
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);

View File

@@ -9,6 +9,9 @@ namespace omath::source_engine
[[nodiscard]] [[nodiscard]]
Vector3<float> ForwardVector(const ViewAngles& angles); Vector3<float> ForwardVector(const ViewAngles& angles);
[[nodiscard]]
Mat4x4 RotationMatrix(const ViewAngles& angles);
[[nodiscard]] [[nodiscard]]
Vector3<float> RightVector(const ViewAngles& angles); Vector3<float> RightVector(const ViewAngles& angles);
@@ -17,7 +20,6 @@ namespace omath::source_engine
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin); [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
[[nodiscard]] [[nodiscard]]
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
} // namespace omath::source } // namespace omath::source

View File

@@ -18,7 +18,7 @@ namespace omath::unity_engine
using Mat4x4 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>; using Mat4x4 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
using Mat3x3 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>; using Mat3x3 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
using Mat1x3 = Mat<1, 3, float, MatStoreType::ROW_MAJOR>; using Mat1x3 = Mat<1, 3, float, MatStoreType::ROW_MAJOR>;
using PitchAngle = Angle<float, -89.f, 89.f, AngleFlags::Clamped>; using PitchAngle = Angle<float, -90.f, 90.f, AngleFlags::Clamped>;
using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>; using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>; using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;

View File

@@ -18,6 +18,8 @@ namespace omath::unity_engine
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin); [[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
[[nodiscard]]
Mat4x4 RotationMatrix(const ViewAngles& angles);
[[nodiscard]] [[nodiscard]]
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far); Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);

View File

@@ -9,6 +9,17 @@
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
#include "omath/vector3.hpp" #include "omath/vector3.hpp"
#include <numeric>
#ifdef near
#undef near
#endif
#ifdef far
#undef far
#endif
namespace omath namespace omath
{ {
@@ -81,6 +92,12 @@ namespace omath
return At(row, col); return At(row, col);
} }
[[nodiscard]]
constexpr Type& operator[](const size_t row, const size_t col) const
{
return At(row, col);
}
constexpr Mat(Mat&& other) noexcept constexpr Mat(Mat&& other) noexcept
{ {
m_data = std::move(other.m_data); m_data = std::move(other.m_data);
@@ -107,9 +124,10 @@ namespace omath
[[nodiscard]] [[nodiscard]]
constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const
{ {
#if !defined(NDEBUG) && defined(OMATH_SUPRESS_SAFETY_CHECKS)
if (rowIndex >= Rows || columnIndex >= Columns) if (rowIndex >= Rows || columnIndex >= Columns)
throw std::out_of_range("Index out of range"); throw std::out_of_range("Index out of range");
#endif
if constexpr (StoreType == MatStoreType::ROW_MAJOR) if constexpr (StoreType == MatStoreType::ROW_MAJOR)
return m_data[rowIndex * Columns + columnIndex]; return m_data[rowIndex * Columns + columnIndex];
@@ -131,12 +149,7 @@ namespace omath
[[nodiscard]] [[nodiscard]]
constexpr Type Sum() const noexcept constexpr Type Sum() const noexcept
{ {
Type sum = 0; return std::accumulate(m_data.begin(), m_data.end(), Type(0));
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Columns; ++j)
sum += At(i, j);
return sum;
} }
constexpr void Clear() noexcept constexpr void Clear() noexcept
@@ -151,6 +164,7 @@ namespace omath
// Operator overloading for multiplication with another Mat // Operator overloading for multiplication with another Mat
template<size_t OtherColumns> template<size_t OtherColumns>
[[nodiscard]]
constexpr Mat<Rows, OtherColumns, Type, StoreType> constexpr Mat<Rows, OtherColumns, Type, StoreType>
operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
{ {
@@ -169,9 +183,7 @@ namespace omath
constexpr Mat& operator*=(const Type& f) noexcept constexpr Mat& operator*=(const Type& f) noexcept
{ {
for (size_t i = 0; i < Rows; ++i) std::ranges::for_each(m_data, [&f](auto& val) {val *= f;});
for (size_t j = 0; j < Columns; ++j)
At(i, j) *= f;
return *this; return *this;
} }
@@ -183,47 +195,39 @@ namespace omath
} }
[[nodiscard]] [[nodiscard]]
constexpr Mat operator*(const Type& f) const noexcept constexpr Mat operator*(const Type& value) const noexcept
{ {
Mat result(*this); Mat result(*this);
result *= f; result *= value;
return result; return result;
} }
constexpr Mat& operator/=(const Type& f) noexcept constexpr Mat& operator/=(const Type& value) noexcept
{ {
for (size_t i = 0; i < Rows; ++i) std::ranges::for_each(m_data, [&value](auto& val) {val /= value;});
for (size_t j = 0; j < Columns; ++j)
At(i, j) /= f;
return *this; return *this;
} }
[[nodiscard]] [[nodiscard]]
constexpr Mat operator/(const Type& f) const noexcept constexpr Mat operator/(const Type& value) const noexcept
{ {
Mat result(*this); Mat result(*this);
result /= f; result /= value;
return result; return result;
} }
constexpr Mat& operator=(const Mat& other) noexcept constexpr Mat& operator=(const Mat& other) noexcept
{ {
if (this == &other) if (this != &other)
return *this; m_data = other.m_data;
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Columns; ++j)
At(i, j) = other.At(i, j);
return *this; return *this;
} }
constexpr Mat& operator=(Mat&& other) noexcept constexpr Mat& operator=(Mat&& other) noexcept
{ {
if (this == &other) if (this != &other)
return *this; m_data = std::move(other.m_data);
for (size_t i = 0; i < Rows; ++i)
for (size_t j = 0; j < Columns; ++j)
At(i, j) = other.At(i, j);
return *this; return *this;
} }
@@ -247,7 +251,7 @@ namespace omath
if constexpr (Rows == 1) if constexpr (Rows == 1)
return At(0, 0); return At(0, 0);
else if constexpr (Rows == 2) if constexpr (Rows == 2)
return At(0, 0) * At(1, 1) - At(0, 1) * At(1, 0); return At(0, 0) * At(1, 1) - At(0, 1) * At(1, 0);
else else
{ {
@@ -424,13 +428,6 @@ namespace omath
} * MatTranslation<Type, St>(-cameraOrigin); } * MatTranslation<Type, St>(-cameraOrigin);
} }
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles>
[[nodiscard]]
Mat<4, 4, Type, St> MatRotation(const ViewAngles& angles) noexcept
{
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
}
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR> template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
[[nodiscard]] [[nodiscard]]
Mat<4, 4, Type, St> MatPerspectiveLeftHanded(const float fieldOfView, const float aspectRatio, const float near, Mat<4, 4, Type, St> MatPerspectiveLeftHanded(const float fieldOfView, const float aspectRatio, const float near,

View File

@@ -124,9 +124,9 @@ namespace omath
} }
#ifndef _MSC_VER #ifndef _MSC_VER
[[nodiscard]] constexpr Type& Length() const [[nodiscard]] constexpr Type Length() const
{ {
return std::hypot(x, y); return std::hypot(this->x, this->y);
} }
[[nodiscard]] constexpr Vector2 Normalized() const [[nodiscard]] constexpr Vector2 Normalized() const

View File

@@ -121,12 +121,12 @@ namespace omath
#ifndef _MSC_VER #ifndef _MSC_VER
[[nodiscard]] constexpr Type Length() const [[nodiscard]] constexpr Type Length() const
{ {
return std::hypot(x, y, z); return std::hypot(this->x, this->y, z);
} }
[[nodiscard]] constexpr Type Length2D() const [[nodiscard]] constexpr Type Length2D() const
{ {
return Vector2::Length(); return Vector2<Type>::Length();
} }
[[nodiscard]] Type DistTo(const Vector3& vOther) const [[nodiscard]] Type DistTo(const Vector3& vOther) const
{ {

View File

@@ -2,7 +2,7 @@
// Created by vlad on 2/4/24. // Created by vlad on 2/4/24.
// //
#include "omath/Color.hpp" #include "omath/color.hpp"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>

View File

@@ -9,23 +9,27 @@ namespace omath::iw_engine
Vector3<float> ForwardVector(const ViewAngles& angles) Vector3<float> ForwardVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsForward);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Vector3<float> RightVector(const ViewAngles& angles) Vector3<float> RightVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsRight);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Vector3<float> UpVector(const ViewAngles& angles) Vector3<float> UpVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsUp);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Mat4x4 RotationMatrix(const ViewAngles& angles)
{
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
}
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin) Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
{ {

View File

@@ -9,19 +9,19 @@ namespace omath::opengl_engine
Vector3<float> ForwardVector(const ViewAngles& angles) Vector3<float> ForwardVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); const auto vec = RotationMatrix(angles) * MatColumnFromVector<float, MatStoreType::COLUMN_MAJOR>(kAbsForward);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Vector3<float> RightVector(const ViewAngles& angles) Vector3<float> RightVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); const auto vec = RotationMatrix(angles) * MatColumnFromVector<float, MatStoreType::COLUMN_MAJOR>(kAbsRight);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Vector3<float> UpVector(const ViewAngles& angles) Vector3<float> UpVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); const auto vec = RotationMatrix(angles) * MatColumnFromVector<float, MatStoreType::COLUMN_MAJOR>(kAbsUp);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
@@ -30,6 +30,12 @@ namespace omath::opengl_engine
return MatCameraView<float, MatStoreType::COLUMN_MAJOR>(-ForwardVector(angles), RightVector(angles), return MatCameraView<float, MatStoreType::COLUMN_MAJOR>(-ForwardVector(angles), RightVector(angles),
UpVector(angles), cam_origin); UpVector(angles), cam_origin);
} }
Mat4x4 RotationMatrix(const ViewAngles& angles)
{
return MatRotationAxisZ<float, MatStoreType::COLUMN_MAJOR>(angles.roll) *
MatRotationAxisY<float, MatStoreType::COLUMN_MAJOR>(-angles.yaw) *
MatRotationAxisX<float, MatStoreType::COLUMN_MAJOR>(-angles.pitch);
}
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
const float far) const float far)
{ {

View File

@@ -8,20 +8,25 @@ namespace omath::source_engine
{ {
Vector3<float> ForwardVector(const ViewAngles& angles) Vector3<float> ForwardVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsForward);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Mat4x4 RotationMatrix(const ViewAngles& angles)
{
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
}
Vector3<float> RightVector(const ViewAngles& angles) Vector3<float> RightVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsRight);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Vector3<float> UpVector(const ViewAngles& angles) Vector3<float> UpVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsUp);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }

View File

@@ -7,21 +7,21 @@
namespace omath::unity_engine namespace omath::unity_engine
{ {
Vector3<float> unity_engine::ForwardVector(const ViewAngles& angles) Vector3<float> ForwardVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsForward);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Vector3<float> RightVector(const ViewAngles& angles) Vector3<float> RightVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsRight);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
Vector3<float> UpVector(const ViewAngles& angles) Vector3<float> UpVector(const ViewAngles& angles)
{ {
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp); const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsUp);
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)}; return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
} }
@@ -30,6 +30,12 @@ namespace omath::unity_engine
return MatCameraView<float, MatStoreType::ROW_MAJOR>(ForwardVector(angles), -RightVector(angles), return MatCameraView<float, MatStoreType::ROW_MAJOR>(ForwardVector(angles), -RightVector(angles),
UpVector(angles), cam_origin); UpVector(angles), cam_origin);
} }
Mat4x4 RotationMatrix(const ViewAngles& angles)
{
return MatRotationAxisZ(angles.roll) *
MatRotationAxisY(angles.yaw) *
MatRotationAxisX(angles.pitch);
}
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near, Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
const float far) const float far)
{ {

View File

@@ -1,6 +1,6 @@
#include "omath/Matrix.hpp" #include "omath/matrix.hpp"
#include "omath/Angles.hpp" #include "omath/angles.hpp"
#include "omath/Vector3.hpp" #include "omath/vector3.hpp"
#include <complex> #include <complex>

View File

@@ -2,7 +2,14 @@
// Created by Vlad on 2/23/2025. // Created by Vlad on 2/23/2025.
// //
#include "omath/projectile_prediction/proj_pred_engine_avx2.hpp" #include "omath/projectile_prediction/proj_pred_engine_avx2.hpp"
#include "source_location" #include <source_location>
#include <stdexcept>
#if defined(OMATH_USE_AVX2) && defined(__i386__) && defined(__x86_64__)
#include <immintrin.h>
#else
#include <format>
#endif
namespace omath::projectile_prediction namespace omath::projectile_prediction
{ {
@@ -10,7 +17,7 @@ namespace omath::projectile_prediction
ProjPredEngineAVX2::MaybeCalculateAimPoint([[maybe_unused]] const Projectile& projectile, ProjPredEngineAVX2::MaybeCalculateAimPoint([[maybe_unused]] const Projectile& projectile,
[[maybe_unused]] const Target& target) const [[maybe_unused]] const Target& target) const
{ {
#ifdef OMATH_USE_AVX2 #if defined(OMATH_USE_AVX2) && defined(__i386__) && defined(__x86_64__)
const float bulletGravity = m_gravityConstant * projectile.m_gravityScale; const float bulletGravity = m_gravityConstant * projectile.m_gravityScale;
const float v0 = projectile.m_launchSpeed; const float v0 = projectile.m_launchSpeed;
const float v0Sqr = v0 * v0; const float v0Sqr = v0 * v0;

View File

@@ -27,6 +27,42 @@ TEST(UnitTestIwEngine, UpVector)
EXPECT_EQ(up, omath::iw_engine::kAbsUp); EXPECT_EQ(up, omath::iw_engine::kAbsUp);
} }
TEST(UnitTestIwEngine, ForwardVectorRotationYaw)
{
omath::iw_engine::ViewAngles angles;
angles.yaw = omath::iw_engine::YawAngle::FromDegrees(-90.f);
const auto forward = omath::iw_engine::ForwardVector(angles);
EXPECT_NEAR(forward.x, omath::iw_engine::kAbsRight.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::iw_engine::kAbsRight.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::iw_engine::kAbsRight.z, 0.00001f);
}
TEST(UnitTestIwEngine, ForwardVectorRotationPitch)
{
omath::iw_engine::ViewAngles angles;
angles.pitch = omath::iw_engine::PitchAngle::FromDegrees(-89.f);
const auto forward = omath::iw_engine::ForwardVector(angles);
EXPECT_NEAR(forward.x, omath::iw_engine::kAbsUp.x, 0.02f);
EXPECT_NEAR(forward.y, omath::iw_engine::kAbsUp.y, 0.01f);
EXPECT_NEAR(forward.z, omath::iw_engine::kAbsUp.z, 0.01f);
}
TEST(UnitTestIwEngine, ForwardVectorRotationRoll)
{
omath::iw_engine::ViewAngles angles;
angles.roll = omath::iw_engine::RollAngle::FromDegrees(90.f);
const auto forward = omath::iw_engine::UpVector(angles);
EXPECT_NEAR(forward.x, omath::iw_engine::kAbsRight.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::iw_engine::kAbsRight.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::iw_engine::kAbsRight.z, 0.00001f);
}
TEST(UnitTestIwEngine, ProjectTargetMovedFromCamera) TEST(UnitTestIwEngine, ProjectTargetMovedFromCamera)
{ {
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f); constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);

View File

@@ -10,14 +10,12 @@
TEST(UnitTestOpenGL, ForwardVector) TEST(UnitTestOpenGL, ForwardVector)
{ {
const auto forward = omath::opengl_engine::ForwardVector({}); const auto forward = omath::opengl_engine::ForwardVector({});
EXPECT_EQ(forward, omath::opengl_engine::kAbsForward); EXPECT_EQ(forward, omath::opengl_engine::kAbsForward);
} }
TEST(UnitTestOpenGL, RightVector) TEST(UnitTestOpenGL, RightVector)
{ {
const auto right = omath::opengl_engine::RightVector({}); const auto right = omath::opengl_engine::RightVector({});
EXPECT_EQ(right, omath::opengl_engine::kAbsRight); EXPECT_EQ(right, omath::opengl_engine::kAbsRight);
} }
@@ -27,6 +25,44 @@ TEST(UnitTestOpenGL, UpVector)
EXPECT_EQ(up, omath::opengl_engine::kAbsUp); EXPECT_EQ(up, omath::opengl_engine::kAbsUp);
} }
TEST(UnitTestOpenGL, ForwardVectorRotationYaw)
{
omath::opengl_engine::ViewAngles angles;
angles.yaw = omath::opengl_engine::YawAngle::FromDegrees(90.f);
const auto forward = omath::opengl_engine::ForwardVector(angles);
EXPECT_NEAR(forward.x, omath::opengl_engine::kAbsRight.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::opengl_engine::kAbsRight.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::opengl_engine::kAbsRight.z, 0.00001f);
}
TEST(UnitTestOpenGL, ForwardVectorRotationPitch)
{
omath::opengl_engine::ViewAngles angles;
angles.pitch = omath::opengl_engine::PitchAngle::FromDegrees(-90.f);
const auto forward = omath::opengl_engine::ForwardVector(angles);
EXPECT_NEAR(forward.x, omath::opengl_engine::kAbsUp.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::opengl_engine::kAbsUp.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::opengl_engine::kAbsUp.z, 0.00001f);
}
TEST(UnitTestOpenGL, ForwardVectorRotationRoll)
{
omath::opengl_engine::ViewAngles angles;
angles.roll = omath::opengl_engine::RollAngle::FromDegrees(-90.f);
const auto forward = omath::opengl_engine::UpVector(angles);
EXPECT_NEAR(forward.x, omath::opengl_engine::kAbsRight.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::opengl_engine::kAbsRight.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::opengl_engine::kAbsRight.z, 0.00001f);
}
TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera) TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera)
{ {
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f); constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);

View File

@@ -27,6 +27,42 @@ TEST(UnitTestSourceEngine, UpVector)
EXPECT_EQ(up, omath::source_engine::kAbsUp); EXPECT_EQ(up, omath::source_engine::kAbsUp);
} }
TEST(UnitTestSourceEngine, ForwardVectorRotationYaw)
{
omath::source_engine::ViewAngles angles;
angles.yaw = omath::source_engine::YawAngle::FromDegrees(-90.f);
const auto forward = omath::source_engine::ForwardVector(angles);
EXPECT_NEAR(forward.x, omath::source_engine::kAbsRight.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::source_engine::kAbsRight.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::source_engine::kAbsRight.z, 0.00001f);
}
TEST(UnitTestSourceEngine, ForwardVectorRotationPitch)
{
omath::source_engine::ViewAngles angles;
angles.pitch = omath::source_engine::PitchAngle::FromDegrees(-89.f);
const auto forward = omath::source_engine::ForwardVector(angles);
EXPECT_NEAR(forward.x, omath::source_engine::kAbsUp.x, 0.02f);
EXPECT_NEAR(forward.y, omath::source_engine::kAbsUp.y, 0.01f);
EXPECT_NEAR(forward.z, omath::source_engine::kAbsUp.z, 0.01f);
}
TEST(UnitTestSourceEngine, ForwardVectorRotationRoll)
{
omath::source_engine::ViewAngles angles;
angles.roll = omath::source_engine::RollAngle::FromDegrees(90.f);
const auto forward = omath::source_engine::UpVector(angles);
EXPECT_NEAR(forward.x, omath::source_engine::kAbsRight.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::source_engine::kAbsRight.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::source_engine::kAbsRight.z, 0.00001f);
}
TEST(UnitTestSourceEngine, ProjectTargetMovedFromCamera) TEST(UnitTestSourceEngine, ProjectTargetMovedFromCamera)
{ {
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f); constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);

View File

@@ -14,6 +14,42 @@ TEST(UnitTestUnityEngine, ForwardVector)
EXPECT_EQ(forward, omath::unity_engine::kAbsForward); EXPECT_EQ(forward, omath::unity_engine::kAbsForward);
} }
TEST(UnitTestUnityEngine, ForwardVectorRotationYaw)
{
omath::unity_engine::ViewAngles angles;
angles.yaw = omath::unity_engine::YawAngle::FromDegrees(90.f);
const auto forward = omath::unity_engine::ForwardVector(angles);
EXPECT_NEAR(forward.x, omath::unity_engine::kAbsRight.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::unity_engine::kAbsRight.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::unity_engine::kAbsRight.z, 0.00001f);
}
TEST(UnitTestUnityEngine, ForwardVectorRotationPitch)
{
omath::unity_engine::ViewAngles angles;
angles.pitch = omath::unity_engine::PitchAngle::FromDegrees(-90.f);
const auto forward = omath::unity_engine::ForwardVector(angles);
EXPECT_NEAR(forward.x, omath::unity_engine::kAbsUp.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::unity_engine::kAbsUp.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::unity_engine::kAbsUp.z, 0.00001f);
}
TEST(UnitTestUnityEngine, ForwardVectorRotationRoll)
{
omath::unity_engine::ViewAngles angles;
angles.roll = omath::unity_engine::RollAngle::FromDegrees(-90.f);
const auto forward = omath::unity_engine::UpVector(angles);
EXPECT_NEAR(forward.x, omath::unity_engine::kAbsRight.x, 0.00001f);
EXPECT_NEAR(forward.y, omath::unity_engine::kAbsRight.y, 0.00001f);
EXPECT_NEAR(forward.z, omath::unity_engine::kAbsRight.z, 0.00001f);
}
TEST(UnitTestUnityEngine, RightVector) TEST(UnitTestUnityEngine, RightVector)
{ {
const auto right = omath::unity_engine::RightVector({}); const auto right = omath::unity_engine::RightVector({});

View File

@@ -63,9 +63,9 @@ TEST_F(UnitTestColor, FromHSV)
TEST_F(UnitTestColor, ToHSV) TEST_F(UnitTestColor, ToHSV)
{ {
HSV hsv = color1.ToHSV(); // Red color HSV hsv = color1.ToHSV(); // Red color
EXPECT_FLOAT_EQ(hsv.m_hue, 0.0f); EXPECT_FLOAT_EQ(hsv.hue, 0.0f);
EXPECT_FLOAT_EQ(hsv.m_saturation, 1.0f); EXPECT_FLOAT_EQ(hsv.saturation, 1.0f);
EXPECT_FLOAT_EQ(hsv.m_value, 1.0f); EXPECT_FLOAT_EQ(hsv.value, 1.0f);
} }
// Test color blending // Test color blending
@@ -106,7 +106,7 @@ TEST_F(UnitTestColor, BlendVector3)
{ {
constexpr Color v1(1.0f, 0.0f, 0.0f, 1.f); // Red constexpr Color v1(1.0f, 0.0f, 0.0f, 1.f); // Red
constexpr Color v2(0.0f, 1.0f, 0.0f, 1.f); // Green constexpr Color v2(0.0f, 1.0f, 0.0f, 1.f); // Green
constexpr Color blended = Blend(v1, v2, 0.5f); constexpr Color blended = v1.Blend(v2, 0.5f);
EXPECT_FLOAT_EQ(blended.x, 0.5f); EXPECT_FLOAT_EQ(blended.x, 0.5f);
EXPECT_FLOAT_EQ(blended.y, 0.5f); EXPECT_FLOAT_EQ(blended.y, 0.5f);
EXPECT_FLOAT_EQ(blended.z, 0.0f); EXPECT_FLOAT_EQ(blended.z, 0.0f);

View File

@@ -166,8 +166,10 @@ TEST_F(UnitTestMat, StaticMethod_ToScreenMat)
// Test exception handling in At() method // Test exception handling in At() method
TEST_F(UnitTestMat, Method_At_OutOfRange) TEST_F(UnitTestMat, Method_At_OutOfRange)
{ {
#if !defined(NDEBUG) && defined(OMATH_SUPRESS_SAFETY_CHECKS)
EXPECT_THROW(std::ignore = m2.At(2, 0), std::out_of_range); EXPECT_THROW(std::ignore = m2.At(2, 0), std::out_of_range);
EXPECT_THROW(std::ignore = m2.At(0, 2), std::out_of_range); EXPECT_THROW(std::ignore = m2.At(0, 2), std::out_of_range);
#endif
} }
// Test Determinant for 3x3 matrix // Test Determinant for 3x3 matrix