mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 23:13:26 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35658b1f6d | |||
| 8f4b61319f | |||
| 832c2ea5ef | |||
| 50c336e044 | |||
|
|
e80e22bd5b | ||
| 27576ed761 | |||
| f85243e892 | |||
| 9b6d0beb03 | |||
| ee9829af22 | |||
| cd452b0397 | |||
| 2fa0c500a7 | |||
| 0740d0778c | |||
| f5c271cfa6 | |||
| 064a31f527 | |||
| e5d0adf247 | |||
| 8fc107ec0f | |||
| 6dd72d2448 | |||
| c76f6e91b0 | |||
| d1d06c24ca | |||
| 169011e238 | |||
| 934ca0da0a | |||
| 4200ef63a6 | |||
| 58e2c3b5b7 | |||
|
|
c3202a3bc3 | ||
|
|
39ab9d065d | ||
|
|
ed372a1c78 |
@@ -5,17 +5,29 @@ project(omath VERSION 1.0.1 LANGUAGES CXX)
|
|||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
|
||||||
option(OMATH_BUILD_TESTS "Build unit tests" ON)
|
option(OMATH_BUILD_TESTS "Build unit tests" OFF)
|
||||||
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
|
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
|
||||||
option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
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_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)
|
||||||
|
|
||||||
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
||||||
add_library(omath SHARED source/Vector3.cpp)
|
add_library(omath SHARED source/Matrix.cpp)
|
||||||
else()
|
else()
|
||||||
add_library(omath STATIC source/Matrix.cpp)
|
add_library(omath STATIC source/Matrix.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_library(omath::omath ALIAS omath)
|
||||||
|
|
||||||
|
if (OMATH_IMGUI_INTEGRATION)
|
||||||
|
target_compile_definitions(omath PUBLIC OMATH_IMGUI_INTEGRATION)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (OMATH_USE_AVX2)
|
||||||
|
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
|
||||||
|
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}"
|
||||||
@@ -24,6 +36,9 @@ set_target_properties(omath PROPERTIES
|
|||||||
CXX_STANDARD 23
|
CXX_STANDARD 23
|
||||||
CXX_STANDARD_REQUIRED ON)
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
|
target_compile_options(omath PRIVATE -mavx2 -mfma)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_compile_features(omath PUBLIC cxx_std_23)
|
target_compile_features(omath PUBLIC cxx_std_23)
|
||||||
|
|
||||||
@@ -35,6 +50,10 @@ if(OMATH_BUILD_TESTS)
|
|||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (OMATH_BUILD_EXAMPLES)
|
||||||
|
add_subdirectory(examples)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
|
||||||
target_compile_options(omath PRIVATE /W4 /WX)
|
target_compile_options(omath PRIVATE /W4 /WX)
|
||||||
elseif(OMATH_THREAT_WARNING_AS_ERROR)
|
elseif(OMATH_THREAT_WARNING_AS_ERROR)
|
||||||
|
|||||||
@@ -12,14 +12,14 @@
|
|||||||
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.
|
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
|
## 👁🗨 Features
|
||||||
- **Efficiency**: Optimized for performance, ensuring quick computations.
|
- **Efficiency**: Optimized for performance, ensuring quick computations using AVX2.
|
||||||
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
- **Versatility**: Includes a wide array of mathematical functions and algorithms.
|
||||||
- **Ease of Use**: Simplified interface for convenient integration into various projects.
|
- **Ease of Use**: Simplified interface for convenient integration into various projects.
|
||||||
- **Projectile Prediction**: Projectile prediction engine with O(N) algo complexity, that can power you projectile aim-bot.
|
- **Projectile Prediction**: Projectile prediction engine with O(N) algo complexity, that can power you projectile aim-bot.
|
||||||
- **3D Projection**: No need to find view-projection matrix anymore you can make your own projection pipeline.
|
- **3D Projection**: No need to find view-projection matrix anymore you can make your own projection pipeline.
|
||||||
- **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!
|
||||||
## ⏬ Getting Started
|
## ⏬ Getting Started
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
- C++ Compiler
|
- C++ Compiler
|
||||||
@@ -72,8 +72,11 @@ TEST(UnitTestProjection, IsPointOnScreen)
|
|||||||
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/).
|
||||||
|
|
||||||

|

|
||||||

|
Or for InfinityWard Engine based games. Like Call of Duty Black Ops 2!
|
||||||
|

|
||||||
|
|
||||||
|
Or even advanced projectile aimbot
|
||||||
|
[Watch Video](https://youtu.be/lM_NJ1yCunw?si=5E87OrQMeypxSJ3E)
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
## 🫵🏻 Contributing
|
## 🫵🏻 Contributing
|
||||||
|
|||||||
4
examples/CMakeLists.txt
Normal file
4
examples/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
project(examples)
|
||||||
|
|
||||||
|
add_executable(ExampleProjectionMatrixBuilder ExampleProjMatBuilder.cpp)
|
||||||
|
target_link_libraries(ExampleProjectionMatrixBuilder PRIVATE omath::omath)
|
||||||
40
examples/ExampleProjMatBuilder.cpp
Normal file
40
examples/ExampleProjMatBuilder.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/19/2025.
|
||||||
|
//
|
||||||
|
#include <iostream>
|
||||||
|
#include <omath/engines/opengl_engine/Camera.hpp>
|
||||||
|
#include <omath/engines/opengl_engine/Formulas.hpp>
|
||||||
|
#include <omath/projection/Camera.hpp>
|
||||||
|
#include <print>
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::println("OMATH Projection Matrix Builder");
|
||||||
|
|
||||||
|
float fov = 0;
|
||||||
|
float near = 0;
|
||||||
|
float far = 0;
|
||||||
|
float viewPortWidth = 0;
|
||||||
|
float viewPortHeight = 0;
|
||||||
|
|
||||||
|
std::print("Enter camera fov: ");
|
||||||
|
std::cin >> fov;
|
||||||
|
|
||||||
|
std::print("Enter camera z near: ");
|
||||||
|
std::cin >> near;
|
||||||
|
|
||||||
|
std::print("Enter camera z far: ");
|
||||||
|
std::cin >> far;
|
||||||
|
|
||||||
|
std::print("Enter camera screen width: ");
|
||||||
|
std::cin >> viewPortWidth;
|
||||||
|
|
||||||
|
std::print("Enter camera screen height: ");
|
||||||
|
std::cin >> viewPortHeight;
|
||||||
|
|
||||||
|
const auto mat =
|
||||||
|
omath::opengl_engine::CalcPerspectiveProjectionMatrix(fov, viewPortWidth / viewPortHeight, near, far);
|
||||||
|
|
||||||
|
std::print("{}", mat.ToString());
|
||||||
|
};
|
||||||
@@ -19,7 +19,7 @@ namespace omath
|
|||||||
class Angle
|
class Angle
|
||||||
{
|
{
|
||||||
Type m_angle;
|
Type m_angle;
|
||||||
constexpr Angle(const Type& degrees)
|
constexpr explicit Angle(const Type& degrees)
|
||||||
{
|
{
|
||||||
if constexpr (flags == AngleFlags::Normalized)
|
if constexpr (flags == AngleFlags::Normalized)
|
||||||
m_angle = angles::WrapAngle(degrees, min, max);
|
m_angle = angles::WrapAngle(degrees, min, max);
|
||||||
@@ -36,7 +36,7 @@ namespace omath
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr static Angle FromDegrees(const Type& degrees)
|
constexpr static Angle FromDegrees(const Type& degrees)
|
||||||
{
|
{
|
||||||
return {degrees};
|
return Angle{degrees};
|
||||||
}
|
}
|
||||||
constexpr Angle() : m_angle(0)
|
constexpr Angle() : m_angle(0)
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,7 @@ namespace omath
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr static Angle FromRadians(const Type& degrees)
|
constexpr static Angle FromRadians(const Type& degrees)
|
||||||
{
|
{
|
||||||
return {angles::RadiansToDegrees<Type>(degrees)};
|
return Angle{angles::RadiansToDegrees<Type>(degrees)};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@@ -96,7 +96,6 @@ namespace omath
|
|||||||
return Cos() / Sin();
|
return Cos() / Sin();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
constexpr Angle& operator+=(const Angle& other)
|
constexpr Angle& operator+=(const Angle& other)
|
||||||
{
|
{
|
||||||
if constexpr (flags == AngleFlags::Normalized)
|
if constexpr (flags == AngleFlags::Normalized)
|
||||||
@@ -116,7 +115,6 @@ namespace omath
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr std::partial_ordering operator<=>(const Angle& other) const = default;
|
constexpr std::partial_ordering operator<=>(const Angle& other) const = default;
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
constexpr Angle& operator-=(const Angle& other)
|
constexpr Angle& operator-=(const Angle& other)
|
||||||
{
|
{
|
||||||
return operator+=(-other);
|
return operator+=(-other);
|
||||||
@@ -146,7 +144,7 @@ namespace omath
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Angle operator-() const
|
constexpr Angle operator-() const
|
||||||
{
|
{
|
||||||
return {-m_angle};
|
return Angle{-m_angle};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "Vector3.hpp"
|
#include "Vector3.hpp"
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -34,11 +35,13 @@ namespace omath
|
|||||||
class Mat final
|
class Mat final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr Mat()
|
constexpr Mat() noexcept
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
constexpr static MatStoreType GetStoreOrdering()
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr static MatStoreType GetStoreOrdering() noexcept
|
||||||
{
|
{
|
||||||
return StoreType;
|
return StoreType;
|
||||||
}
|
}
|
||||||
@@ -72,6 +75,7 @@ namespace omath
|
|||||||
m_data = other.m_data;
|
m_data = other.m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr Type& operator[](const size_t row, const size_t col)
|
constexpr Type& operator[](const size_t row, const size_t col)
|
||||||
{
|
{
|
||||||
return At(row, col);
|
return At(row, col);
|
||||||
@@ -100,7 +104,8 @@ namespace omath
|
|||||||
return {Rows, Columns};
|
return {Rows, Columns};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const
|
[[nodiscard]]
|
||||||
|
constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const
|
||||||
{
|
{
|
||||||
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");
|
||||||
@@ -177,6 +182,7 @@ namespace omath
|
|||||||
return *this = *this * other;
|
return *this = *this * other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr Mat operator*(const Type& f) const noexcept
|
constexpr Mat operator*(const Type& f) const noexcept
|
||||||
{
|
{
|
||||||
Mat result(*this);
|
Mat result(*this);
|
||||||
@@ -192,6 +198,7 @@ namespace omath
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr Mat operator/(const Type& f) const noexcept
|
constexpr Mat operator/(const Type& f) const noexcept
|
||||||
{
|
{
|
||||||
Mat result(*this);
|
Mat result(*this);
|
||||||
@@ -290,15 +297,20 @@ namespace omath
|
|||||||
std::string ToString() const noexcept
|
std::string ToString() const noexcept
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
oss << "[[";
|
||||||
|
|
||||||
for (size_t i = 0; i < Rows; ++i)
|
for (size_t i = 0; i < Rows; ++i)
|
||||||
{
|
{
|
||||||
|
if (i > 0)
|
||||||
|
oss << " [";
|
||||||
|
|
||||||
for (size_t j = 0; j < Columns; ++j)
|
for (size_t j = 0; j < Columns; ++j)
|
||||||
{
|
{
|
||||||
oss << At(i, j);
|
oss << std::setw(9) << std::fixed << std::setprecision(3) << At(i, j);
|
||||||
if (j != Columns - 1)
|
if (j != Columns - 1)
|
||||||
oss << ' ';
|
oss << ", ";
|
||||||
}
|
}
|
||||||
oss << '\n';
|
oss << (i == Rows - 1 ? "]]" : "]\n");
|
||||||
}
|
}
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,16 @@
|
|||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
|\
|
||||||
|
| \
|
||||||
|
a | \ hypot
|
||||||
|
| \
|
||||||
|
-----
|
||||||
|
b
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
template<class Vector>
|
template<class Vector>
|
||||||
class Triangle final
|
class Triangle final
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,13 +3,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <tuple>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
|
#include <imgui.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
|
|
||||||
template<class Type> requires std::is_arithmetic_v<Type>
|
template<class Type>
|
||||||
|
requires std::is_arithmetic_v<Type>
|
||||||
class Vector2
|
class Vector2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -19,7 +25,9 @@ namespace omath
|
|||||||
// Constructors
|
// Constructors
|
||||||
constexpr Vector2() = default;
|
constexpr Vector2() = default;
|
||||||
|
|
||||||
constexpr Vector2(const Type& x, const Type& y) : x(x), y(y) {}
|
constexpr Vector2(const Type& x, const Type& y) : x(x), y(y)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// Equality operators
|
// Equality operators
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@@ -151,17 +159,6 @@ namespace omath
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class type>
|
|
||||||
[[nodiscard]] constexpr const type& As() const
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<const type*>(this);
|
|
||||||
}
|
|
||||||
template<class type>
|
|
||||||
[[nodiscard]] constexpr type& As()
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<type*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr Vector2 operator-() const
|
[[nodiscard]] constexpr Vector2 operator-() const
|
||||||
{
|
{
|
||||||
return {-x, -y};
|
return {-x, -y};
|
||||||
@@ -199,5 +196,13 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return std::make_tuple(x, y);
|
return std::make_tuple(x, y);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
|
[[nodiscard]]
|
||||||
|
ImVec2 ToImVec2() const
|
||||||
|
{
|
||||||
|
return {static_cast<float>(this->x), static_cast<float>(this->y)};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
} // namespace omath
|
||||||
|
|||||||
@@ -4,13 +4,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Vector2.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
|
||||||
#include "omath/Vector2.hpp"
|
|
||||||
#include "omath/Angle.hpp"
|
|
||||||
#include <expected>
|
#include <expected>
|
||||||
#include <immintrin.h>
|
#include <functional>
|
||||||
|
#include "omath/Angle.hpp"
|
||||||
|
#include "omath/Vector2.hpp"
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -110,45 +109,45 @@ namespace omath
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr float DistToSqr(const Vector3& vOther) const
|
[[nodiscard]] constexpr Type DistToSqr(const Vector3& vOther) const
|
||||||
{
|
{
|
||||||
return (*this - vOther).LengthSqr();
|
return (*this - vOther).LengthSqr();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr float Dot(const Vector3& vOther) const
|
[[nodiscard]] constexpr Type Dot(const Vector3& vOther) const
|
||||||
{
|
{
|
||||||
return Vector2<Type>::Dot(vOther) + z * vOther.z;
|
return Vector2<Type>::Dot(vOther) + z * vOther.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
[[nodiscard]] constexpr float Length() const
|
[[nodiscard]] constexpr Type Length() const
|
||||||
{
|
{
|
||||||
return std::hypot(x, y, z);
|
return std::hypot(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr float Length2D() const
|
[[nodiscard]] constexpr Type Length2D() const
|
||||||
{
|
{
|
||||||
return Vector2::Length();
|
return Vector2::Length();
|
||||||
}
|
}
|
||||||
[[nodiscard]] float DistTo(const Vector3& vOther) const
|
[[nodiscard]] Type DistTo(const Vector3& vOther) const
|
||||||
{
|
{
|
||||||
return (*this - vOther).Length();
|
return (*this - vOther).Length();
|
||||||
}
|
}
|
||||||
[[nodiscard]] constexpr Vector3 Normalized() const
|
[[nodiscard]] constexpr Vector3 Normalized() const
|
||||||
{
|
{
|
||||||
const float length = this->Length();
|
const Type length = this->Length();
|
||||||
|
|
||||||
return length != 0 ? *this / length : *this;
|
return length != 0 ? *this / length : *this;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
[[nodiscard]] float Length() const
|
[[nodiscard]] Type Length() const
|
||||||
{
|
{
|
||||||
return std::hypot(this->x, this->y, z);
|
return std::hypot(this->x, this->y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] Vector3 Normalized() const
|
[[nodiscard]] Vector3 Normalized() const
|
||||||
{
|
{
|
||||||
const float length = this->Length();
|
const Type length = this->Length();
|
||||||
|
|
||||||
return length != 0 ? *this / length : *this;
|
return length != 0 ? *this / length : *this;
|
||||||
}
|
}
|
||||||
@@ -158,14 +157,14 @@ namespace omath
|
|||||||
return Vector2<Type>::Length();
|
return Vector2<Type>::Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] float DistTo(const Vector3& vOther) const
|
[[nodiscard]] Type DistTo(const Vector3& vOther) const
|
||||||
{
|
{
|
||||||
return (*this - vOther).Length();
|
return (*this - vOther).Length();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr float LengthSqr() const
|
[[nodiscard]] constexpr Type LengthSqr() const
|
||||||
{
|
{
|
||||||
return Vector2<Type>::LengthSqr() + z * z;
|
return Vector2<Type>::LengthSqr() + z * z;
|
||||||
}
|
}
|
||||||
@@ -214,7 +213,7 @@ namespace omath
|
|||||||
this->x * v.y - this->y * v.x
|
this->x * v.y - this->y * v.x
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
[[nodiscard]] constexpr float Sum() const
|
[[nodiscard]] constexpr Type Sum() const
|
||||||
{
|
{
|
||||||
return Sum2D() + z;
|
return Sum2D() + z;
|
||||||
}
|
}
|
||||||
@@ -238,12 +237,12 @@ namespace omath
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr float Sum2D() const
|
[[nodiscard]] constexpr Type Sum2D() const
|
||||||
{
|
{
|
||||||
return Vector2<Type>::Sum();
|
return Vector2<Type>::Sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr std::tuple<float, float, float> AsTuple() const
|
[[nodiscard]] constexpr std::tuple<Type, Type, Type> AsTuple() const
|
||||||
{
|
{
|
||||||
return std::make_tuple(this->x, this->y, z);
|
return std::make_tuple(this->x, this->y, z);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <omath/Vector3.hpp>
|
#include <omath/Vector3.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
template <class Type>
|
template <class Type>
|
||||||
@@ -81,7 +82,7 @@ namespace omath
|
|||||||
return Vector3<Type>::LengthSqr() + w * w;
|
return Vector3<Type>::LengthSqr() + w * w;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr float Dot(const Vector4& vOther) const
|
[[nodiscard]] constexpr Type Dot(const Vector4& vOther) const
|
||||||
{
|
{
|
||||||
return Vector3<Type>::Dot(vOther) + w * vOther.w;
|
return Vector3<Type>::Dot(vOther) + w * vOther.w;
|
||||||
}
|
}
|
||||||
@@ -98,7 +99,7 @@ namespace omath
|
|||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
constexpr Vector4& Clamp(const float min, const float max)
|
constexpr Vector4& Clamp(const Type& min, const Type& max)
|
||||||
{
|
{
|
||||||
this->x = std::clamp(this->x, min, max);
|
this->x = std::clamp(this->x, min, max);
|
||||||
this->y = std::clamp(this->y, min, max);
|
this->y = std::clamp(this->y, min, max);
|
||||||
@@ -126,7 +127,7 @@ namespace omath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Vector4 operator*(const float scalar) const
|
constexpr Vector4 operator*(const Type& scalar) const
|
||||||
{
|
{
|
||||||
return {this->x * scalar, this->y * scalar, this->z * scalar, w * scalar};
|
return {this->x * scalar, this->y * scalar, this->z * scalar, w * scalar};
|
||||||
}
|
}
|
||||||
@@ -138,7 +139,7 @@ namespace omath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Vector4 operator/(const float scalar) const
|
constexpr Vector4 operator/(const Type& scalar) const
|
||||||
{
|
{
|
||||||
return {this->x / scalar, this->y / scalar, this->z / scalar, w / scalar};
|
return {this->x / scalar, this->y / scalar, this->z / scalar, w / scalar};
|
||||||
}
|
}
|
||||||
@@ -154,5 +155,19 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return Vector3<Type>::Sum() + w;
|
return Vector3<Type>::Sum() + w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
|
[[nodiscard]]
|
||||||
|
ImVec4 ToImVec4() const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
{
|
||||||
|
static_cast<float>(this->x),
|
||||||
|
static_cast<float>(this->y),
|
||||||
|
static_cast<float>(this->z),
|
||||||
|
static_cast<float>(w),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Orange on 12/23/2024.
|
|
||||||
//
|
|
||||||
#pragma once
|
|
||||||
#include "Constants.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace omath::opengl
|
|
||||||
{
|
|
||||||
[[nodiscard]]
|
|
||||||
inline Vector3<float> ForwardVector(const ViewAngles& angles)
|
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
inline Vector3<float> RightVector(const ViewAngles& angles)
|
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
inline Vector3<float> UpVector(const ViewAngles& angles)
|
|
||||||
{
|
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
|
||||||
|
|
||||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
|
||||||
{
|
|
||||||
return MatCameraView<float, MatStoreType::COLUMN_MAJOR>(-ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
inline Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
|
||||||
const float far)
|
|
||||||
{
|
|
||||||
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f);
|
|
||||||
|
|
||||||
return {
|
|
||||||
{1.f / (aspectRatio * fovHalfTan), 0, 0, 0},
|
|
||||||
{0, 1.f / (fovHalfTan), 0, 0},
|
|
||||||
{0, 0, -(far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
|
||||||
{0, 0, -1, 0},
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
21
include/omath/engines/iw_engine/Camera.hpp
Normal file
21
include/omath/engines/iw_engine/Camera.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/17/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "Constants.hpp"
|
||||||
|
#include "omath/projection/Camera.hpp"
|
||||||
|
|
||||||
|
namespace omath::iw_engine
|
||||||
|
{
|
||||||
|
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||||
|
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
||||||
|
void LookAt(const Vector3<float>& target) override;
|
||||||
|
protected:
|
||||||
|
[[nodiscard]] Mat4x4 CalcViewMatrix() const override;
|
||||||
|
[[nodiscard]] Mat4x4 CalcProjectionMatrix() const override;
|
||||||
|
};
|
||||||
|
}
|
||||||
25
include/omath/engines/iw_engine/Constants.hpp
Normal file
25
include/omath/engines/iw_engine/Constants.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/17/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <omath/Vector3.hpp>
|
||||||
|
#include <omath/Mat.hpp>
|
||||||
|
#include <omath/Angle.hpp>
|
||||||
|
#include <omath/ViewAngles.hpp>
|
||||||
|
|
||||||
|
namespace omath::iw_engine
|
||||||
|
{
|
||||||
|
constexpr Vector3<float> kAbsUp = {0, 0, 1};
|
||||||
|
constexpr Vector3<float> kAbsRight = {0, -1, 0};
|
||||||
|
constexpr Vector3<float> kAbsForward = {1, 0, 0};
|
||||||
|
|
||||||
|
using Mat4x4 = 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 PitchAngle = Angle<float, -89.f, 89.f, AngleFlags::Clamped>;
|
||||||
|
using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
|
||||||
|
using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
|
||||||
|
|
||||||
|
using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>;
|
||||||
|
}
|
||||||
24
include/omath/engines/iw_engine/Formulas.hpp
Normal file
24
include/omath/engines/iw_engine/Formulas.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/17/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "Constants.hpp"
|
||||||
|
|
||||||
|
namespace omath::iw_engine
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> ForwardVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> RightVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> UpVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
|
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
|
} // namespace omath::source
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "omath/projection/Camera.hpp"
|
#include "omath/projection/Camera.hpp"
|
||||||
|
|
||||||
namespace omath::opengl
|
namespace omath::opengl_engine
|
||||||
{
|
{
|
||||||
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
||||||
{
|
{
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <omath/Angle.hpp>
|
#include <omath/Angle.hpp>
|
||||||
#include <omath/ViewAngles.hpp>
|
#include <omath/ViewAngles.hpp>
|
||||||
|
|
||||||
namespace omath::opengl
|
namespace omath::opengl_engine
|
||||||
{
|
{
|
||||||
constexpr Vector3<float> kAbsUp = {0, 1, 0};
|
constexpr Vector3<float> kAbsUp = {0, 1, 0};
|
||||||
constexpr Vector3<float> kAbsRight = {1, 0, 0};
|
constexpr Vector3<float> kAbsRight = {1, 0, 0};
|
||||||
24
include/omath/engines/opengl_engine/Formulas.hpp
Normal file
24
include/omath/engines/opengl_engine/Formulas.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//
|
||||||
|
// Created by Orange on 12/23/2024.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "Constants.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace omath::opengl_engine
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> ForwardVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> RightVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> UpVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
|
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
|
} // namespace omath::opengl_engine
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "omath/projection/Camera.hpp"
|
#include "omath/projection/Camera.hpp"
|
||||||
|
|
||||||
namespace omath::source
|
namespace omath::source_engine
|
||||||
{
|
{
|
||||||
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
||||||
{
|
{
|
||||||
@@ -13,6 +13,7 @@ namespace omath::source
|
|||||||
Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||||
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
||||||
void LookAt(const Vector3<float>& target) override;
|
void LookAt(const Vector3<float>& target) override;
|
||||||
|
protected:
|
||||||
[[nodiscard]] Mat4x4 CalcViewMatrix() const override;
|
[[nodiscard]] Mat4x4 CalcViewMatrix() const override;
|
||||||
[[nodiscard]] Mat4x4 CalcProjectionMatrix() const override;
|
[[nodiscard]] Mat4x4 CalcProjectionMatrix() const override;
|
||||||
};
|
};
|
||||||
@@ -7,7 +7,8 @@
|
|||||||
#include <omath/Mat.hpp>
|
#include <omath/Mat.hpp>
|
||||||
#include <omath/Angle.hpp>
|
#include <omath/Angle.hpp>
|
||||||
#include <omath/ViewAngles.hpp>
|
#include <omath/ViewAngles.hpp>
|
||||||
namespace omath::source
|
|
||||||
|
namespace omath::source_engine
|
||||||
{
|
{
|
||||||
constexpr Vector3<float> kAbsUp = {0, 0, 1};
|
constexpr Vector3<float> kAbsUp = {0, 0, 1};
|
||||||
constexpr Vector3<float> kAbsRight = {0, -1, 0};
|
constexpr Vector3<float> kAbsRight = {0, -1, 0};
|
||||||
23
include/omath/engines/source_engine/Formulas.hpp
Normal file
23
include/omath/engines/source_engine/Formulas.hpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// Created by Orange on 12/4/2024.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "Constants.hpp"
|
||||||
|
|
||||||
|
namespace omath::source_engine
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> ForwardVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> RightVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> UpVector(const ViewAngles& angles);
|
||||||
|
|
||||||
|
[[nodiscard]] Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
||||||
|
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Mat4x4 CalcPerspectiveProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
|
} // namespace omath::source
|
||||||
@@ -38,7 +38,7 @@ namespace omath::projection
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
virtual void LookAt(const Vector3<float>& target) = 0;
|
virtual void LookAt(const Vector3<float>& target) = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual Mat4x4Type CalcViewMatrix() const = 0;
|
[[nodiscard]] virtual Mat4x4Type CalcViewMatrix() const = 0;
|
||||||
@@ -49,41 +49,44 @@ namespace omath::projection
|
|||||||
{
|
{
|
||||||
return CalcProjectionMatrix() * CalcViewMatrix();
|
return CalcProjectionMatrix() * CalcViewMatrix();
|
||||||
}
|
}
|
||||||
|
public:
|
||||||
|
|
||||||
|
[[nodiscard]] const Mat4x4Type& GetViewProjectionMatrix() const
|
||||||
|
{
|
||||||
|
if (!m_viewProjectionMatrix.has_value())
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
|
||||||
|
return m_viewProjectionMatrix.value();
|
||||||
|
}
|
||||||
|
|
||||||
void SetFieldOfView(const FieldOfView& fov)
|
void SetFieldOfView(const FieldOfView& fov)
|
||||||
{
|
{
|
||||||
m_fieldOfView = fov;
|
m_fieldOfView = fov;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNearPlane(const float near)
|
void SetNearPlane(const float near)
|
||||||
{
|
{
|
||||||
m_nearPlaneDistance = near;
|
m_nearPlaneDistance = near;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFarPlane(const float far)
|
void SetFarPlane(const float far)
|
||||||
{
|
{
|
||||||
m_farPlaneDistance = far;
|
m_farPlaneDistance = far;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetViewAngles(const ViewAnglesType& viewAngles)
|
void SetViewAngles(const ViewAnglesType& viewAngles)
|
||||||
{
|
{
|
||||||
m_viewAngles = viewAngles;
|
m_viewAngles = viewAngles;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetOrigin(const Vector3<float>& origin)
|
void SetOrigin(const Vector3<float>& origin)
|
||||||
{
|
{
|
||||||
m_origin = origin;
|
m_origin = origin;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetViewPort(const ViewPort& viewPort)
|
void SetViewPort(const ViewPort& viewPort)
|
||||||
{
|
{
|
||||||
m_viewPort = viewPort;
|
m_viewPort = viewPort;
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const FieldOfView& GetFieldOfView() const
|
[[nodiscard]] const FieldOfView& GetFieldOfView() const
|
||||||
@@ -113,10 +116,9 @@ namespace omath::projection
|
|||||||
|
|
||||||
[[nodiscard]] std::expected<Vector3<float>, Error> WorldToScreen(const Vector3<float>& worldPosition) const
|
[[nodiscard]] std::expected<Vector3<float>, Error> WorldToScreen(const Vector3<float>& worldPosition) const
|
||||||
{
|
{
|
||||||
if (!m_viewProjectionMatrix.has_value())
|
const auto& viewProjMatrix = GetViewProjectionMatrix();
|
||||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
|
||||||
|
|
||||||
auto projected = m_viewProjectionMatrix.value() * MatColumnFromVector<float, Mat4x4Type::GetStoreOrdering()>(worldPosition);
|
auto projected = viewProjMatrix * MatColumnFromVector<float, Mat4x4Type::GetStoreOrdering()>(worldPosition);
|
||||||
|
|
||||||
if (projected.At(3, 0) == 0.0f)
|
if (projected.At(3, 0) == 0.0f)
|
||||||
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
add_subdirectory(Source)
|
add_subdirectory(source_engine)
|
||||||
add_subdirectory(OpenGL)
|
add_subdirectory(opengl_engine)
|
||||||
|
add_subdirectory(iw_engine)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
target_sources(omath PRIVATE Camera.cpp)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
target_sources(omath PRIVATE Camera.cpp)
|
|
||||||
1
source/engines/iw_engine/CMakeLists.txt
Normal file
1
source/engines/iw_engine/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target_sources(omath PRIVATE Camera.cpp Formulas.cpp)
|
||||||
34
source/engines/iw_engine/Camera.cpp
Normal file
34
source/engines/iw_engine/Camera.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/17/2025.
|
||||||
|
//
|
||||||
|
#include "omath/engines/iw_engine/Camera.hpp"
|
||||||
|
#include "omath/engines/iw_engine/Formulas.hpp"
|
||||||
|
|
||||||
|
namespace omath::iw_engine
|
||||||
|
{
|
||||||
|
|
||||||
|
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||||
|
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, const float near, const float far) :
|
||||||
|
projection::Camera<Mat4x4, ViewAngles>(position, viewAngles, viewPort, fov, near, far)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void Camera::LookAt([[maybe_unused]] const Vector3<float>& target)
|
||||||
|
{
|
||||||
|
const float distance = m_origin.DistTo(target);
|
||||||
|
const auto delta = target - m_origin;
|
||||||
|
|
||||||
|
|
||||||
|
m_viewAngles.pitch = PitchAngle::FromRadians(std::asin(delta.z / distance));
|
||||||
|
m_viewAngles.yaw = -YawAngle::FromRadians(std::atan2(delta.y, delta.x));
|
||||||
|
m_viewAngles.roll = RollAngle::FromRadians(0.f);
|
||||||
|
}
|
||||||
|
Mat4x4 Camera::CalcViewMatrix() const
|
||||||
|
{
|
||||||
|
return iw_engine::CalcViewMatrix(m_viewAngles, m_origin);
|
||||||
|
}
|
||||||
|
Mat4x4 Camera::CalcProjectionMatrix() const
|
||||||
|
{
|
||||||
|
return CalcPerspectiveProjectionMatrix(m_fieldOfView.AsDegrees(), m_viewPort.AspectRatio(), m_nearPlaneDistance,
|
||||||
|
m_farPlaneDistance);
|
||||||
|
}
|
||||||
|
} // namespace omath::openg
|
||||||
47
source/engines/iw_engine/Formulas.cpp
Normal file
47
source/engines/iw_engine/Formulas.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/19/2025.
|
||||||
|
//
|
||||||
|
#include "omath/engines/iw_engine/Formulas.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace omath::iw_engine
|
||||||
|
{
|
||||||
|
|
||||||
|
Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
||||||
|
|
||||||
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3<float> RightVector(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
||||||
|
|
||||||
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
|
}
|
||||||
|
Vector3<float> UpVector(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
||||||
|
|
||||||
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
|
}
|
||||||
|
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||||
|
{
|
||||||
|
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
||||||
|
}
|
||||||
|
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
|
const float far)
|
||||||
|
{
|
||||||
|
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
|
||||||
|
constexpr auto kMultiplyFactor = 0.75f;
|
||||||
|
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor;
|
||||||
|
|
||||||
|
return {
|
||||||
|
{1.f / (aspectRatio * fovHalfTan), 0, 0, 0},
|
||||||
|
{0, 1.f / fovHalfTan, 0, 0},
|
||||||
|
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||||
|
{0, 0, 1, 0},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace omath::iw_engine
|
||||||
1
source/engines/opengl_engine/CMakeLists.txt
Normal file
1
source/engines/opengl_engine/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target_sources(omath PRIVATE Camera.cpp Formulas.cpp)
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//
|
//
|
||||||
// Created by Orange on 12/23/2024.
|
// Created by Orange on 12/23/2024.
|
||||||
//
|
//
|
||||||
#include "omath/engines/OpenGL/Camera.hpp"
|
#include "omath/engines/opengl_engine/Camera.hpp"
|
||||||
#include "omath/engines/OpenGL/Formulas.hpp"
|
#include "omath/engines/opengl_engine/Formulas.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace omath::opengl
|
namespace omath::opengl_engine
|
||||||
{
|
{
|
||||||
|
|
||||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||||
@@ -25,7 +25,7 @@ namespace omath::opengl
|
|||||||
}
|
}
|
||||||
Mat4x4 Camera::CalcViewMatrix() const
|
Mat4x4 Camera::CalcViewMatrix() const
|
||||||
{
|
{
|
||||||
return opengl::CalcViewMatrix(m_viewAngles, m_origin);
|
return opengl_engine::CalcViewMatrix(m_viewAngles, m_origin);
|
||||||
}
|
}
|
||||||
Mat4x4 Camera::CalcProjectionMatrix() const
|
Mat4x4 Camera::CalcProjectionMatrix() const
|
||||||
{
|
{
|
||||||
46
source/engines/opengl_engine/Formulas.cpp
Normal file
46
source/engines/opengl_engine/Formulas.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/19/2025.
|
||||||
|
//
|
||||||
|
#include "omath/engines/opengl_engine/Formulas.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace omath::opengl_engine
|
||||||
|
{
|
||||||
|
|
||||||
|
Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
||||||
|
|
||||||
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
|
}
|
||||||
|
Vector3<float> RightVector(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
||||||
|
|
||||||
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
|
}
|
||||||
|
Vector3<float> UpVector(const ViewAngles& angles)
|
||||||
|
{
|
||||||
|
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
||||||
|
|
||||||
|
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||||
|
}
|
||||||
|
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||||
|
{
|
||||||
|
return MatCameraView<float, MatStoreType::COLUMN_MAJOR>(-ForwardVector(angles), RightVector(angles),
|
||||||
|
UpVector(angles), cam_origin);
|
||||||
|
}
|
||||||
|
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
|
const float far)
|
||||||
|
{
|
||||||
|
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f);
|
||||||
|
|
||||||
|
return {
|
||||||
|
{1.f / (aspectRatio * fovHalfTan), 0, 0, 0},
|
||||||
|
{0, 1.f / (fovHalfTan), 0, 0},
|
||||||
|
{0, 0, -(far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||||
|
{0, 0, -1, 0},
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace omath::opengl_engine
|
||||||
1
source/engines/source_engine/CMakeLists.txt
Normal file
1
source/engines/source_engine/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target_sources(omath PRIVATE Camera.cpp Formulas.cpp)
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
//
|
//
|
||||||
// Created by Orange on 12/4/2024.
|
// Created by Orange on 12/4/2024.
|
||||||
//
|
//
|
||||||
#include "omath/engines/Source/Camera.hpp"
|
#include "omath/engines/source_engine/Camera.hpp"
|
||||||
#include "omath/engines/Source/Formulas.hpp"
|
#include "omath/engines/source_engine/Formulas.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace omath::source
|
namespace omath::source_engine
|
||||||
{
|
{
|
||||||
|
|
||||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||||
@@ -26,7 +26,7 @@ namespace omath::source
|
|||||||
|
|
||||||
Mat4x4 Camera::CalcViewMatrix() const
|
Mat4x4 Camera::CalcViewMatrix() const
|
||||||
{
|
{
|
||||||
return source::CalcViewMatrix(m_viewAngles, m_origin);
|
return source_engine::CalcViewMatrix(m_viewAngles, m_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4x4 Camera::CalcProjectionMatrix() const
|
Mat4x4 Camera::CalcProjectionMatrix() const
|
||||||
@@ -1,47 +1,39 @@
|
|||||||
//
|
//
|
||||||
// Created by Orange on 12/4/2024.
|
// Created by Vlad on 3/19/2025.
|
||||||
//
|
//
|
||||||
#pragma once
|
#include <omath/engines/source_engine/Formulas.hpp>
|
||||||
#include "Constants.hpp"
|
|
||||||
|
|
||||||
namespace omath::source
|
|
||||||
|
namespace omath::source_engine
|
||||||
{
|
{
|
||||||
[[nodiscard]]
|
Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||||
inline Vector3<float> ForwardVector(const ViewAngles& angles)
|
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
const auto vec = MatRotation(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)};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
Vector3<float> RightVector(const ViewAngles& angles)
|
||||||
inline Vector3<float> RightVector(const ViewAngles& angles)
|
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
const auto vec = MatRotation(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)
|
||||||
[[nodiscard]]
|
|
||||||
inline Vector3<float> UpVector(const ViewAngles& angles)
|
|
||||||
{
|
{
|
||||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsUp);
|
const auto vec = MatRotation(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)};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||||
{
|
{
|
||||||
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
|
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
inline Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
|
||||||
const float far)
|
const float far)
|
||||||
{
|
{
|
||||||
// NOTE: Needed tp make thing draw normal, since source is wierd
|
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
|
||||||
// and use tricky projection matrix formula.
|
|
||||||
constexpr auto kMultiplyFactor = 0.75f;
|
constexpr auto kMultiplyFactor = 0.75f;
|
||||||
|
|
||||||
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor;
|
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor;
|
||||||
@@ -54,4 +46,4 @@ namespace omath::source
|
|||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} // namespace omath::source
|
} // namespace omath::source_engine
|
||||||
@@ -2,13 +2,15 @@
|
|||||||
// Created by Vlad on 2/23/2025.
|
// Created by Vlad on 2/23/2025.
|
||||||
//
|
//
|
||||||
#include "omath/projectile_prediction/ProjPredEngineAVX2.hpp"
|
#include "omath/projectile_prediction/ProjPredEngineAVX2.hpp"
|
||||||
|
#include "source_location"
|
||||||
|
|
||||||
namespace omath::projectile_prediction
|
namespace omath::projectile_prediction
|
||||||
{
|
{
|
||||||
std::optional<Vector3<float>> ProjPredEngineAVX2::MaybeCalculateAimPoint(const Projectile& projectile,
|
std::optional<Vector3<float>>
|
||||||
const Target& target) const
|
ProjPredEngineAVX2::MaybeCalculateAimPoint([[maybe_unused]] const Projectile& projectile,
|
||||||
|
[[maybe_unused]] const Target& target) const
|
||||||
{
|
{
|
||||||
|
#ifdef OMATH_USE_AVX2
|
||||||
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;
|
||||||
@@ -106,12 +108,13 @@ namespace omath::projectile_prediction
|
|||||||
}
|
}
|
||||||
ProjPredEngineAVX2::ProjPredEngineAVX2(const float gravityConstant, const float simulationTimeStep,
|
ProjPredEngineAVX2::ProjPredEngineAVX2(const float gravityConstant, const float simulationTimeStep,
|
||||||
const float maximumSimulationTime) :
|
const float maximumSimulationTime) :
|
||||||
m_gravityConstant(gravityConstant), m_simulationTimeStep(maximumSimulationTime),
|
m_gravityConstant(gravityConstant), m_simulationTimeStep(simulationTimeStep),
|
||||||
m_maximumSimulationTime(simulationTimeStep)
|
m_maximumSimulationTime(maximumSimulationTime)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
std::optional<float> ProjPredEngineAVX2::CalculatePitch(const Vector3<float>& projOrigin, const Vector3<float>& targetPos,
|
std::optional<float> ProjPredEngineAVX2::CalculatePitch(const Vector3<float>& projOrigin,
|
||||||
const float bulletGravity, const float v0, const float time)
|
const Vector3<float>& targetPos, const float bulletGravity,
|
||||||
|
const float v0, const float time)
|
||||||
{
|
{
|
||||||
if (time <= 0.0f)
|
if (time <= 0.0f)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
@@ -134,5 +137,9 @@ namespace omath::projectile_prediction
|
|||||||
const float d = std::sqrt(dSqr);
|
const float d = std::sqrt(dSqr);
|
||||||
const float tanTheta = term / d;
|
const float tanTheta = term / d;
|
||||||
return angles::RadiansToDegrees(std::atan(tanTheta));
|
return angles::RadiansToDegrees(std::atan(tanTheta));
|
||||||
|
#else
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::format("{} AVX2 feature is not enabled!", std::source_location::current().function_name()));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} // namespace omath::projectile_prediction
|
} // namespace omath::projectile_prediction
|
||||||
|
|||||||
@@ -4,15 +4,15 @@
|
|||||||
|
|
||||||
#include "omath/projectile_prediction/Projectile.hpp"
|
#include "omath/projectile_prediction/Projectile.hpp"
|
||||||
|
|
||||||
#include <omath/engines/Source/Formulas.hpp>
|
#include <omath/engines/source_engine/Formulas.hpp>
|
||||||
|
|
||||||
namespace omath::projectile_prediction
|
namespace omath::projectile_prediction
|
||||||
{
|
{
|
||||||
Vector3<float> Projectile::PredictPosition(const float pitch, const float yaw, const float time, const float gravity) const
|
Vector3<float> Projectile::PredictPosition(const float pitch, const float yaw, const float time, const float gravity) const
|
||||||
{
|
{
|
||||||
auto currentPos = m_origin + source::ForwardVector({source::PitchAngle::FromDegrees(-pitch),
|
auto currentPos = m_origin + source_engine::ForwardVector({source_engine::PitchAngle::FromDegrees(-pitch),
|
||||||
source::YawAngle::FromDegrees(yaw),
|
source_engine::YawAngle::FromDegrees(yaw),
|
||||||
source::RollAngle::FromDegrees(0)}) *
|
source_engine::RollAngle::FromDegrees(0)}) *
|
||||||
m_launchSpeed * time;
|
m_launchSpeed * time;
|
||||||
currentPos.z -= (gravity * m_gravityScale) * (time * time) * 0.5f;
|
currentPos.z -= (gravity * m_gravityScale) * (time * time) * 0.5f;
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ add_executable(unit-tests
|
|||||||
engines/UnitTestOpenGL.cpp
|
engines/UnitTestOpenGL.cpp
|
||||||
engines/UnitTestUnityEngine.cpp
|
engines/UnitTestUnityEngine.cpp
|
||||||
engines/UnitTestSourceEngine.cpp
|
engines/UnitTestSourceEngine.cpp
|
||||||
|
engines/UnitTestIwEngine.cpp
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,6 +35,6 @@ set_target_properties(unit-tests PROPERTIES
|
|||||||
CXX_STANDARD_REQUIRED ON)
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath)
|
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath::omath)
|
||||||
|
|
||||||
gtest_discover_tests(unit-tests)
|
gtest_discover_tests(unit-tests)
|
||||||
69
tests/engines/UnitTestIwEngine.cpp
Normal file
69
tests/engines/UnitTestIwEngine.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/17/2025.
|
||||||
|
//
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <omath/engines/iw_engine/Camera.hpp>
|
||||||
|
#include <omath/engines/iw_engine/Constants.hpp>
|
||||||
|
#include <omath/engines/iw_engine/Formulas.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
TEST(UnitTestEwEngine, ForwardVector)
|
||||||
|
{
|
||||||
|
const auto forward = omath::source_engine::ForwardVector({});
|
||||||
|
|
||||||
|
EXPECT_EQ(forward, omath::source_engine::kAbsForward);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestEwEngine, RightVector)
|
||||||
|
{
|
||||||
|
const auto right = omath::source_engine::RightVector({});
|
||||||
|
|
||||||
|
EXPECT_EQ(right, omath::source_engine::kAbsRight);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestEwEngine, UpVector)
|
||||||
|
{
|
||||||
|
const auto up = omath::source_engine::UpVector({});
|
||||||
|
EXPECT_EQ(up, omath::source_engine::kAbsUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestEwEngine, ProjectTargetMovedFromCamera)
|
||||||
|
{
|
||||||
|
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
||||||
|
const auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
|
||||||
|
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
||||||
|
{
|
||||||
|
const auto projected = cam.WorldToScreen({distance, 0, 0});
|
||||||
|
|
||||||
|
EXPECT_TRUE(projected.has_value());
|
||||||
|
|
||||||
|
if (!projected.has_value())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
EXPECT_NEAR(projected->x, 960, 0.00001f);
|
||||||
|
EXPECT_NEAR(projected->y, 540, 0.00001f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestEwEngine, CameraSetAndGetFov)
|
||||||
|
{
|
||||||
|
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
||||||
|
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 90.f);
|
||||||
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 50.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestEwEngine, CameraSetAndGetOrigin)
|
||||||
|
{
|
||||||
|
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetOrigin(), omath::Vector3<float>{});
|
||||||
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 50.f);
|
||||||
|
}
|
||||||
@@ -2,35 +2,35 @@
|
|||||||
// Created by Orange on 11/23/2024.
|
// Created by Orange on 11/23/2024.
|
||||||
//
|
//
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <omath/engines/OpenGL/Camera.hpp>
|
#include <omath/engines/opengl_engine//Camera.hpp>
|
||||||
#include <omath/engines/OpenGL/Constants.hpp>
|
#include <omath/engines/opengl_engine/Constants.hpp>
|
||||||
#include <omath/engines/OpenGL/Formulas.hpp>
|
#include <omath/engines/opengl_engine/Formulas.hpp>
|
||||||
|
|
||||||
|
|
||||||
TEST(UnitTestOpenGL, ForwardVector)
|
TEST(UnitTestOpenGL, ForwardVector)
|
||||||
{
|
{
|
||||||
const auto forward = omath::opengl::ForwardVector({});
|
const auto forward = omath::opengl_engine::ForwardVector({});
|
||||||
|
|
||||||
EXPECT_EQ(forward, omath::opengl::kAbsForward);
|
EXPECT_EQ(forward, omath::opengl_engine::kAbsForward);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnitTestOpenGL, RightVector)
|
TEST(UnitTestOpenGL, RightVector)
|
||||||
{
|
{
|
||||||
const auto right = omath::opengl::RightVector({});
|
const auto right = omath::opengl_engine::RightVector({});
|
||||||
|
|
||||||
EXPECT_EQ(right, omath::opengl::kAbsRight);
|
EXPECT_EQ(right, omath::opengl_engine::kAbsRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnitTestOpenGL, UpVector)
|
TEST(UnitTestOpenGL, UpVector)
|
||||||
{
|
{
|
||||||
const auto up = omath::opengl::UpVector({});
|
const auto up = omath::opengl_engine::UpVector({});
|
||||||
EXPECT_EQ(up, omath::opengl::kAbsUp);
|
EXPECT_EQ(up, omath::opengl_engine::kAbsUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera)
|
TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera)
|
||||||
{
|
{
|
||||||
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
||||||
auto cam = omath::opengl::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
const auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
|
||||||
for (float distance = -10.f; distance > -1000.f; distance -= 0.01f)
|
for (float distance = -10.f; distance > -1000.f; distance -= 0.01f)
|
||||||
@@ -50,7 +50,7 @@ TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera)
|
|||||||
TEST(UnitTestOpenGL, CameraSetAndGetFov)
|
TEST(UnitTestOpenGL, CameraSetAndGetFov)
|
||||||
{
|
{
|
||||||
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
||||||
auto cam = omath::opengl::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 90.f);
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 90.f);
|
||||||
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
@@ -60,7 +60,7 @@ TEST(UnitTestOpenGL, CameraSetAndGetFov)
|
|||||||
|
|
||||||
TEST(UnitTestOpenGL, CameraSetAndGetOrigin)
|
TEST(UnitTestOpenGL, CameraSetAndGetOrigin)
|
||||||
{
|
{
|
||||||
auto cam = omath::opengl::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
auto cam = omath::opengl_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||||
|
|
||||||
EXPECT_EQ(cam.GetOrigin(), omath::Vector3<float>{});
|
EXPECT_EQ(cam.GetOrigin(), omath::Vector3<float>{});
|
||||||
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
|
|||||||
@@ -2,35 +2,35 @@
|
|||||||
// Created by Orange on 11/23/2024.
|
// Created by Orange on 11/23/2024.
|
||||||
//
|
//
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <omath/engines/Source/Camera.hpp>
|
#include <omath/engines/source_engine/Camera.hpp>
|
||||||
#include <omath/engines/Source/Constants.hpp>
|
#include <omath/engines/source_engine/Constants.hpp>
|
||||||
#include <omath/engines/Source/Formulas.hpp>
|
#include <omath/engines/source_engine/Formulas.hpp>
|
||||||
|
|
||||||
|
|
||||||
TEST(UnitTestSourceEngine, ForwardVector)
|
TEST(UnitTestSourceEngine, ForwardVector)
|
||||||
{
|
{
|
||||||
const auto forward = omath::source::ForwardVector({});
|
const auto forward = omath::source_engine::ForwardVector({});
|
||||||
|
|
||||||
EXPECT_EQ(forward, omath::source::kAbsForward);
|
EXPECT_EQ(forward, omath::source_engine::kAbsForward);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnitTestSourceEngine, RightVector)
|
TEST(UnitTestSourceEngine, RightVector)
|
||||||
{
|
{
|
||||||
const auto right = omath::source::RightVector({});
|
const auto right = omath::source_engine::RightVector({});
|
||||||
|
|
||||||
EXPECT_EQ(right, omath::source::kAbsRight);
|
EXPECT_EQ(right, omath::source_engine::kAbsRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnitTestSourceEngine, UpVector)
|
TEST(UnitTestSourceEngine, UpVector)
|
||||||
{
|
{
|
||||||
const auto up = omath::source::UpVector({});
|
const auto up = omath::source_engine::UpVector({});
|
||||||
EXPECT_EQ(up, omath::source::kAbsUp);
|
EXPECT_EQ(up, omath::source_engine::kAbsUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnitTestSourceEngine, ProjectTargetMovedFromCamera)
|
TEST(UnitTestSourceEngine, ProjectTargetMovedFromCamera)
|
||||||
{
|
{
|
||||||
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
||||||
auto cam = omath::source::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
const auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
|
||||||
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
||||||
@@ -50,7 +50,7 @@ TEST(UnitTestSourceEngine, ProjectTargetMovedFromCamera)
|
|||||||
TEST(UnitTestSourceEngine, CameraSetAndGetFov)
|
TEST(UnitTestSourceEngine, CameraSetAndGetFov)
|
||||||
{
|
{
|
||||||
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
constexpr auto fov = omath::projection::FieldOfView::FromDegrees(90.f);
|
||||||
auto cam = omath::source::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 90.f);
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 90.f);
|
||||||
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
@@ -60,7 +60,7 @@ TEST(UnitTestSourceEngine, CameraSetAndGetFov)
|
|||||||
|
|
||||||
TEST(UnitTestSourceEngine, CameraSetAndGetOrigin)
|
TEST(UnitTestSourceEngine, CameraSetAndGetOrigin)
|
||||||
{
|
{
|
||||||
auto cam = omath::source::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||||
|
|
||||||
EXPECT_EQ(cam.GetOrigin(), omath::Vector3<float>{});
|
EXPECT_EQ(cam.GetOrigin(), omath::Vector3<float>{});
|
||||||
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ TEST_F(UnitTestMat, ToString)
|
|||||||
{
|
{
|
||||||
const std::string str = m2.ToString();
|
const std::string str = m2.ToString();
|
||||||
EXPECT_FALSE(str.empty());
|
EXPECT_FALSE(str.empty());
|
||||||
EXPECT_EQ(str, "1 2\n3 4\n");
|
EXPECT_EQ(str, "[[ 1.000, 2.000]\n [ 3.000, 4.000]]");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test assignment operators
|
// Test assignment operators
|
||||||
|
|||||||
@@ -3,15 +3,14 @@
|
|||||||
//
|
//
|
||||||
#include <complex>
|
#include <complex>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <omath/Matrix.hpp>
|
#include <omath/engines/source_engine/Camera.hpp>
|
||||||
#include <omath/engines/Source/Camera.hpp>
|
|
||||||
#include <omath/projection/Camera.hpp>
|
#include <omath/projection/Camera.hpp>
|
||||||
#include <print>
|
#include <print>
|
||||||
|
|
||||||
TEST(UnitTestProjection, Projection)
|
TEST(UnitTestProjection, Projection)
|
||||||
{
|
{
|
||||||
const auto x = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::FromDegrees(90.f);
|
const auto x = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::FromDegrees(90.f);
|
||||||
auto cam = omath::source::Camera({0, 0, 0}, omath::source::ViewAngles{}, {1920.f, 1080.f}, x, 0.01f, 1000.f);
|
auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, x, 0.01f, 1000.f);
|
||||||
|
|
||||||
const auto projected = cam.WorldToScreen({1000, 0, 50});
|
const auto projected = cam.WorldToScreen({1000, 0, 50});
|
||||||
std::print("{} {} {}", projected->x, projected->y, projected->z);
|
std::print("{} {} {}", projected->x, projected->y, projected->z);
|
||||||
|
|||||||
Reference in New Issue
Block a user