mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-14 15:33:26 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cdce07f2a5 | |||
| 931937d010 | |||
| af880be056 | |||
| c3bfd12971 | |||
| 9ad8ec755b | |||
| 409cd18de6 | |||
| 001c6a8a47 | |||
| 30bc3f2c6d | |||
| 232f456a4d | |||
| 2b9575311e | |||
| e497308349 | |||
| 390e584aee | |||
| 93082d6a8d | |||
| c8c3c4e5fc | |||
|
|
24ad4ac698 |
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@@ -2,7 +2,6 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/extlibs/glm" vcs="Git" />
|
|
||||||
<mapping directory="$PROJECT_DIR$/extlibs/googletest" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/extlibs/googletest" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.26)
|
cmake_minimum_required(VERSION 3.26)
|
||||||
|
|
||||||
project(omath VERSION 1.0.0)
|
project(omath VERSION 1.0.1)
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
@@ -16,15 +16,14 @@ option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" 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/Vector3.cpp)
|
||||||
else()
|
else()
|
||||||
add_library(omath STATIC source/Vector3.cpp)
|
add_library(omath STATIC source/Vector3.cpp
|
||||||
|
include/omath/engines/OpenGL/Constants.hpp
|
||||||
|
include/omath/engines/OpenGL/Formulas.hpp
|
||||||
|
include/omath/engines/OpenGL/Camera.hpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(omath PUBLIC OMATH_EXPORT)
|
target_compile_definitions(omath PUBLIC OMATH_EXPORT)
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
||||||
target_compile_options(omath PRIVATE /Zc:static_assert-)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory(source)
|
add_subdirectory(source)
|
||||||
|
|
||||||
if(OMATH_BUILD_TESTS)
|
if(OMATH_BUILD_TESTS)
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -26,6 +26,20 @@ Oranges's Math Library (omath) is a comprehensive, open-source library aimed at
|
|||||||
- CMake (for building the project)
|
- CMake (for building the project)
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
### vcpkg
|
||||||
|
**Note**: Support vcpkg for package management
|
||||||
|
1. Install vcpkg (https://github.com/microsoft/vcpkg)
|
||||||
|
2. Run the following command to install the orange-math package:
|
||||||
|
```
|
||||||
|
vcpkg install orange-math
|
||||||
|
```
|
||||||
|
CMakeLists.txt
|
||||||
|
```cmake
|
||||||
|
find_package(omath CONFIG REQUIRED)
|
||||||
|
target_link_libraries(main PRIVATE omath::omath)
|
||||||
|
```
|
||||||
|
For detailed commands on installing different versions and more information, please refer to Microsoft's official instructions (https://learn.microsoft.com/en-us/vcpkg/get_started/overview)
|
||||||
|
### Build from source
|
||||||
1. Clone the repository:
|
1. Clone the repository:
|
||||||
```
|
```
|
||||||
git clone https://github.com/orange-cpp/omath.git
|
git clone https://github.com/orange-cpp/omath.git
|
||||||
@@ -69,4 +83,4 @@ Contributions to `omath` are welcome! Please read `CONTRIBUTING.md` for details
|
|||||||
This project is licensed under the MIT - see the `LICENSE` file for details.
|
This project is licensed under the MIT - see the `LICENSE` file for details.
|
||||||
|
|
||||||
## Acknowledgments
|
## Acknowledgments
|
||||||
- Orange | [Telegram](https://t.me/orange_cpp)
|
- [All contributors](https://github.com/orange-cpp/omath/graphs/contributors)
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ include(CMakeFindDependencyMacro)
|
|||||||
|
|
||||||
# Load the targets for the omath library
|
# Load the targets for the omath library
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/omathTargets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/omathTargets.cmake")
|
||||||
|
check_required_components(omath)
|
||||||
|
|||||||
@@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/Angles.hpp"
|
#include "omath/Angles.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -18,7 +16,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 OMATH_API Angle
|
class Angle
|
||||||
{
|
{
|
||||||
Type m_angle;
|
Type m_angle;
|
||||||
constexpr Angle(const Type& degrees)
|
constexpr Angle(const Type& degrees)
|
||||||
|
|||||||
@@ -7,11 +7,10 @@
|
|||||||
#include "omath/Vector3.hpp"
|
#include "omath/Vector3.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "omath/Vector4.hpp"
|
#include "omath/Vector4.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
struct OMATH_API HSV
|
struct HSV
|
||||||
{
|
{
|
||||||
float m_hue{};
|
float m_hue{};
|
||||||
float m_saturation{};
|
float m_saturation{};
|
||||||
@@ -19,7 +18,7 @@ namespace omath
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class OMATH_API Color final : public Vector4
|
class Color final : public Vector4
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr Color(float r, float g, float b, float a) : Vector4(r,g,b,a)
|
constexpr Color(float r, float g, float b, float a) : Vector4(r,g,b,a)
|
||||||
|
|||||||
@@ -8,11 +8,10 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "Vector3.hpp"
|
#include "Vector3.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
struct OMATH_API MatSize
|
struct MatSize
|
||||||
{
|
{
|
||||||
size_t rows, columns;
|
size_t rows, columns;
|
||||||
};
|
};
|
||||||
@@ -28,15 +27,15 @@ namespace omath
|
|||||||
class Mat final
|
class Mat final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OMATH_API constexpr Mat()
|
constexpr Mat()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
OMATH_API constexpr static MatStoreType GetStoreOrdering()
|
constexpr static MatStoreType GetStoreOrdering()
|
||||||
{
|
{
|
||||||
return StoreType;
|
return StoreType;
|
||||||
}
|
}
|
||||||
OMATH_API constexpr Mat(const std::initializer_list<std::initializer_list<Type>>& rows)
|
constexpr Mat(const std::initializer_list<std::initializer_list<Type>>& rows)
|
||||||
{
|
{
|
||||||
if (rows.size() != Rows)
|
if (rows.size() != Rows)
|
||||||
throw std::invalid_argument("Initializer list rows size does not match template parameter Rows");
|
throw std::invalid_argument("Initializer list rows size does not match template parameter Rows");
|
||||||
@@ -56,40 +55,45 @@ namespace omath
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr explicit Mat(const Type* rawData)
|
constexpr explicit Mat(const Type* rawData)
|
||||||
{
|
{
|
||||||
std::copy_n(rawData, Rows * Columns, m_data.begin());
|
std::copy_n(rawData, Rows * Columns, m_data.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr Mat(const Mat& other) noexcept
|
constexpr Mat(const Mat& other) noexcept
|
||||||
{
|
{
|
||||||
m_data = other.m_data;
|
m_data = other.m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr Mat(Mat&& other) noexcept
|
constexpr Type& operator[](const size_t row, const size_t col)
|
||||||
|
{
|
||||||
|
return At(row, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Mat(Mat&& other) noexcept
|
||||||
{
|
{
|
||||||
m_data = std::move(other.m_data);
|
m_data = std::move(other.m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API static constexpr size_t RowCount() noexcept
|
static constexpr size_t RowCount() noexcept
|
||||||
{
|
{
|
||||||
return Rows;
|
return Rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API static constexpr size_t ColumnsCount() noexcept
|
static constexpr size_t ColumnsCount() noexcept
|
||||||
{
|
{
|
||||||
return Columns;
|
return Columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API static consteval MatSize Size() noexcept
|
static consteval MatSize Size() noexcept
|
||||||
{
|
{
|
||||||
return {Rows, Columns};
|
return {Rows, Columns};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] OMATH_API 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");
|
||||||
@@ -107,13 +111,13 @@ namespace omath
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] OMATH_API constexpr Type& At(const size_t rowIndex, const size_t columnIndex)
|
[[nodiscard]] constexpr Type& At(const size_t rowIndex, const size_t columnIndex)
|
||||||
{
|
{
|
||||||
return const_cast<Type&>(std::as_const(*this).At(rowIndex, columnIndex));
|
return const_cast<Type&>(std::as_const(*this).At(rowIndex, columnIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API constexpr Type Sum() const noexcept
|
constexpr Type Sum() const noexcept
|
||||||
{
|
{
|
||||||
Type sum = 0;
|
Type sum = 0;
|
||||||
for (size_t i = 0; i < Rows; ++i)
|
for (size_t i = 0; i < Rows; ++i)
|
||||||
@@ -123,12 +127,12 @@ namespace omath
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr void Clear() noexcept
|
constexpr void Clear() noexcept
|
||||||
{
|
{
|
||||||
Set(0);
|
Set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr void Set(const Type& value) noexcept
|
constexpr void Set(const Type& value) noexcept
|
||||||
{
|
{
|
||||||
std::ranges::fill(m_data, value);
|
std::ranges::fill(m_data, value);
|
||||||
}
|
}
|
||||||
@@ -136,7 +140,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>
|
||||||
constexpr Mat<Rows, OtherColumns, Type, StoreType>
|
constexpr Mat<Rows, OtherColumns, Type, StoreType>
|
||||||
OMATH_API operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
|
operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
|
||||||
{
|
{
|
||||||
Mat<Rows, OtherColumns, Type, StoreType> result;
|
Mat<Rows, OtherColumns, Type, StoreType> result;
|
||||||
|
|
||||||
@@ -151,7 +155,7 @@ namespace omath
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr Mat& operator*=(const Type& f) noexcept
|
constexpr Mat& operator*=(const Type& f) noexcept
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < Rows; ++i)
|
for (size_t i = 0; i < Rows; ++i)
|
||||||
for (size_t j = 0; j < Columns; ++j)
|
for (size_t j = 0; j < Columns; ++j)
|
||||||
@@ -161,19 +165,19 @@ namespace omath
|
|||||||
|
|
||||||
template<size_t OtherColumns>
|
template<size_t OtherColumns>
|
||||||
constexpr Mat<Rows, OtherColumns, Type, StoreType>
|
constexpr Mat<Rows, OtherColumns, Type, StoreType>
|
||||||
OMATH_API operator*=(const Mat<Columns, OtherColumns, Type, StoreType>& other)
|
operator*=(const Mat<Columns, OtherColumns, Type, StoreType>& other)
|
||||||
{
|
{
|
||||||
return *this = *this * other;
|
return *this = *this * other;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr Mat operator*(const Type& f) const noexcept
|
constexpr Mat operator*(const Type& f) const noexcept
|
||||||
{
|
{
|
||||||
Mat result(*this);
|
Mat result(*this);
|
||||||
result *= f;
|
result *= f;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr Mat& operator/=(const Type& f) noexcept
|
constexpr Mat& operator/=(const Type& f) noexcept
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < Rows; ++i)
|
for (size_t i = 0; i < Rows; ++i)
|
||||||
for (size_t j = 0; j < Columns; ++j)
|
for (size_t j = 0; j < Columns; ++j)
|
||||||
@@ -181,14 +185,14 @@ namespace omath
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr Mat operator/(const Type& f) const noexcept
|
constexpr Mat operator/(const Type& f) const noexcept
|
||||||
{
|
{
|
||||||
Mat result(*this);
|
Mat result(*this);
|
||||||
result /= f;
|
result /= f;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr Mat& operator=(const Mat& other) noexcept
|
constexpr Mat& operator=(const Mat& other) noexcept
|
||||||
{
|
{
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
@@ -198,7 +202,7 @@ namespace omath
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OMATH_API constexpr Mat& operator=(Mat&& other) noexcept
|
constexpr Mat& operator=(Mat&& other) noexcept
|
||||||
{
|
{
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
@@ -211,7 +215,7 @@ namespace omath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API constexpr Mat<Columns, Rows, Type, StoreType> Transposed() const noexcept
|
constexpr Mat<Columns, Rows, Type, StoreType> Transposed() const noexcept
|
||||||
{
|
{
|
||||||
Mat<Columns, Rows, Type, StoreType> transposed;
|
Mat<Columns, Rows, Type, StoreType> transposed;
|
||||||
for (size_t i = 0; i < Rows; ++i)
|
for (size_t i = 0; i < Rows; ++i)
|
||||||
@@ -222,7 +226,7 @@ namespace omath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API constexpr Type Determinant() const
|
constexpr Type Determinant() const
|
||||||
{
|
{
|
||||||
static_assert(Rows == Columns, "Determinant is only defined for square matrices.");
|
static_assert(Rows == Columns, "Determinant is only defined for square matrices.");
|
||||||
|
|
||||||
@@ -244,7 +248,7 @@ namespace omath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API constexpr Mat<Rows - 1, Columns - 1, Type, StoreType> Minor(const size_t row, const size_t column) const
|
constexpr Mat<Rows - 1, Columns - 1, Type, StoreType> Minor(const size_t row, const size_t column) const
|
||||||
{
|
{
|
||||||
Mat<Rows - 1, Columns - 1, Type, StoreType> result;
|
Mat<Rows - 1, Columns - 1, Type, StoreType> result;
|
||||||
for (size_t i = 0, m = 0; i < Rows; ++i)
|
for (size_t i = 0, m = 0; i < Rows; ++i)
|
||||||
@@ -264,19 +268,19 @@ namespace omath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API constexpr const std::array<Type, Rows * Columns>& RawArray() const
|
constexpr const std::array<Type, Rows * Columns>& RawArray() const
|
||||||
{
|
{
|
||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API constexpr std::array<Type, Rows * Columns>& RawArray()
|
constexpr std::array<Type, Rows * Columns>& RawArray()
|
||||||
{
|
{
|
||||||
return const_cast<std::array<Type, Rows * Columns>>(std::as_const(*this).RawArray());
|
return const_cast<std::array<Type, Rows * Columns>>(std::as_const(*this).RawArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API std::string ToString() const noexcept
|
std::string ToString() const noexcept
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
for (size_t i = 0; i < Rows; ++i)
|
for (size_t i = 0; i < Rows; ++i)
|
||||||
@@ -293,20 +297,20 @@ namespace omath
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API bool operator==(const Mat& mat) const
|
bool operator==(const Mat& mat) const
|
||||||
{
|
{
|
||||||
return m_data == mat.m_data;
|
return m_data == mat.m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API bool operator!=(const Mat& mat) const
|
bool operator!=(const Mat& mat) const
|
||||||
{
|
{
|
||||||
return !operator==(mat);
|
return !operator==(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static methods that return fixed-size matrices
|
// Static methods that return fixed-size matrices
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API constexpr static Mat<4, 4> ToScreenMat(const Type& screenWidth, const Type& screenHeight) noexcept
|
constexpr static Mat<4, 4> ToScreenMat(const Type& screenWidth, const Type& screenHeight) noexcept
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
{screenWidth / 2, 0, 0, 0},
|
{screenWidth / 2, 0, 0, 0},
|
||||||
@@ -336,7 +340,7 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API constexpr Mat<4, 4, Type, St> MatTranslation(const Vector3& diff) noexcept
|
constexpr Mat<4, 4, Type, St> MatTranslation(const Vector3& diff) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
@@ -349,7 +353,7 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API Mat<4, 4, Type, St> MatRotationAxisX(const Angle& angle) noexcept
|
Mat<4, 4, Type, St> MatRotationAxisX(const Angle& angle) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
@@ -362,7 +366,7 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API Mat<4, 4, Type, St> MatRotationAxisY(const Angle& angle) noexcept
|
Mat<4, 4, Type, St> MatRotationAxisY(const Angle& angle) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
@@ -375,7 +379,7 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API Mat<4, 4, Type, St> MatRotationAxisZ(const Angle& angle) noexcept
|
Mat<4, 4, Type, St> MatRotationAxisZ(const Angle& angle) noexcept
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
@@ -403,7 +407,7 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API Mat<4, 4, Type, St> MatRotation(const ViewAngles& angles) noexcept
|
Mat<4, 4, Type, St> MatRotation(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
|
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -11,91 +10,98 @@ namespace omath
|
|||||||
class Matrix final
|
class Matrix final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OMATH_API Matrix();
|
Matrix();
|
||||||
OMATH_API Matrix(size_t rows, size_t columns);
|
Matrix(size_t rows, size_t columns);
|
||||||
|
|
||||||
OMATH_API Matrix(const std::initializer_list<std::initializer_list<float>>& rows);
|
Matrix(const std::initializer_list<std::initializer_list<float>>& rows);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API static Matrix ToScreenMatrix(float screenWidth, float screenHeight);
|
static Matrix ToScreenMatrix(float screenWidth, float screenHeight);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API static Matrix TranslationMatrix(const Vector3& diff);
|
static Matrix TranslationMatrix(const Vector3& diff);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API static Matrix OrientationMatrix(const Vector3& forward, const Vector3& right, const Vector3& up);
|
static Matrix OrientationMatrix(const Vector3& forward, const Vector3& right, const Vector3& up);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API static Matrix ProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
static Matrix ProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||||
|
|
||||||
OMATH_API Matrix(const Matrix& other);
|
Matrix(const Matrix& other);
|
||||||
|
|
||||||
OMATH_API Matrix(size_t rows, size_t columns, const float* pRaw);
|
Matrix(size_t rows, size_t columns, const float* pRaw);
|
||||||
|
|
||||||
OMATH_API Matrix(Matrix&& other) noexcept;
|
Matrix(Matrix&& other) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API size_t RowCount() const noexcept;
|
size_t RowCount() const noexcept;
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API size_t ColumnsCount() const noexcept;
|
float& operator[](size_t row, size_t column)
|
||||||
|
{
|
||||||
|
return At(row, column);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API std::pair<size_t, size_t> Size() const noexcept;
|
size_t ColumnsCount() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API float& At(size_t iRow, size_t iCol);
|
std::pair<size_t, size_t> Size() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API float Sum();
|
float& At(size_t iRow, size_t iCol);
|
||||||
|
|
||||||
OMATH_API void SetDataFromRaw(const float* pRawMatrix);
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API Matrix Transpose() const;
|
float Sum();
|
||||||
|
|
||||||
OMATH_API void Set(float val);
|
void SetDataFromRaw(const float* pRawMatrix);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API const float& At(size_t iRow, size_t iCol) const;
|
Matrix Transpose() const;
|
||||||
|
|
||||||
OMATH_API Matrix operator*(const Matrix& other) const;
|
void Set(float val);
|
||||||
|
|
||||||
OMATH_API Matrix& operator*=(const Matrix& other);
|
|
||||||
|
|
||||||
OMATH_API Matrix operator*(float f) const;
|
|
||||||
|
|
||||||
OMATH_API Matrix& operator*=(float f);
|
|
||||||
|
|
||||||
OMATH_API Matrix& operator/=(float f);
|
|
||||||
|
|
||||||
OMATH_API void Clear();
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API Matrix Strip(size_t row, size_t column) const;
|
const float& At(size_t iRow, size_t iCol) const;
|
||||||
|
|
||||||
|
Matrix operator*(const Matrix& other) const;
|
||||||
|
|
||||||
|
Matrix& operator*=(const Matrix& other);
|
||||||
|
|
||||||
|
Matrix operator*(float f) const;
|
||||||
|
|
||||||
|
Matrix& operator*=(float f);
|
||||||
|
|
||||||
|
Matrix& operator/=(float f);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API float Minor(size_t i, size_t j) const;
|
Matrix Strip(size_t row, size_t column) const;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API float AlgComplement(size_t i, size_t j) const;
|
float Minor(size_t i, size_t j) const;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API float Determinant() const;
|
float AlgComplement(size_t i, size_t j) const;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API const float* Raw() const;
|
float Determinant() const;
|
||||||
|
|
||||||
OMATH_API Matrix& operator=(const Matrix& other);
|
|
||||||
|
|
||||||
OMATH_API Matrix& operator=(Matrix&& other) noexcept;
|
|
||||||
|
|
||||||
OMATH_API Matrix operator/(float f) const;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API std::string ToString() const;
|
const float* Raw() const;
|
||||||
|
|
||||||
OMATH_API ~Matrix();
|
Matrix& operator=(const Matrix& other);
|
||||||
|
|
||||||
|
Matrix& operator=(Matrix&& other) noexcept;
|
||||||
|
|
||||||
|
Matrix operator/(float f) const;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
std::string ToString() const;
|
||||||
|
|
||||||
|
~Matrix();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_rows;
|
size_t m_rows;
|
||||||
|
|||||||
@@ -3,11 +3,10 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/Vector3.hpp"
|
#include "omath/Vector3.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
class OMATH_API Triangle3d final
|
class Triangle3d final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Triangle3d(const Vector3& vertex1, const Vector3& vertex2, const Vector3& vertex3);
|
Triangle3d(const Vector3& vertex1, const Vector3& vertex2, const Vector3& vertex3);
|
||||||
|
|||||||
@@ -5,11 +5,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
class OMATH_API Vector2
|
class Vector2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float x = 0.f;
|
float x = 0.f;
|
||||||
|
|||||||
@@ -7,11 +7,10 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "omath/Vector2.hpp"
|
#include "omath/Vector2.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
class OMATH_API Vector3 : public Vector2
|
class Vector3 : public Vector2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float z = 0.f;
|
float z = 0.f;
|
||||||
|
|||||||
@@ -5,11 +5,10 @@
|
|||||||
|
|
||||||
#include <omath/Vector3.hpp>
|
#include <omath/Vector3.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
class OMATH_API Vector4 : public Vector3
|
class Vector4 : public Vector3
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float w;
|
float w;
|
||||||
|
|||||||
@@ -3,12 +3,10 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
template<class PitchType, class YawType, class RollType>
|
template<class PitchType, class YawType, class RollType>
|
||||||
struct OMATH_API ViewAngles
|
struct ViewAngles
|
||||||
{
|
{
|
||||||
PitchType pitch;
|
PitchType pitch;
|
||||||
YawType yaw;
|
YawType yaw;
|
||||||
|
|||||||
@@ -5,11 +5,10 @@
|
|||||||
|
|
||||||
#include "omath/Vector3.hpp"
|
#include "omath/Vector3.hpp"
|
||||||
#include "omath/Triangle3d.hpp"
|
#include "omath/Triangle3d.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath::collision
|
namespace omath::collision
|
||||||
{
|
{
|
||||||
class OMATH_API Ray
|
class Ray
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Vector3 start;
|
Vector3 start;
|
||||||
@@ -21,7 +20,7 @@ namespace omath::collision
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3 DirectionVectorNormalized() const;
|
Vector3 DirectionVectorNormalized() const;
|
||||||
};
|
};
|
||||||
class OMATH_API LineTracer
|
class LineTracer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LineTracer() = delete;
|
LineTracer() = delete;
|
||||||
|
|||||||
19
include/omath/engines/OpenGL/Camera.hpp
Normal file
19
include/omath/engines/OpenGL/Camera.hpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by Orange on 12/23/2024.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "Constants.hpp"
|
||||||
|
#include "omath/projection/Camera.hpp"
|
||||||
|
|
||||||
|
namespace omath::opengl
|
||||||
|
{
|
||||||
|
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera(const Vector3& 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& target) override;
|
||||||
|
[[nodiscard]] Mat4x4 CalcViewMatrix() const override;
|
||||||
|
[[nodiscard]] Mat4x4 CalcProjectionMatrix() const override;
|
||||||
|
};
|
||||||
|
}
|
||||||
25
include/omath/engines/OpenGL/Constants.hpp
Normal file
25
include/omath/engines/OpenGL/Constants.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Orange on 12/23/2024.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <omath/Vector3.hpp>
|
||||||
|
#include <omath/Mat.hpp>
|
||||||
|
#include <omath/Angle.hpp>
|
||||||
|
#include <omath/ViewAngles.hpp>
|
||||||
|
|
||||||
|
namespace omath::opengl
|
||||||
|
{
|
||||||
|
constexpr Vector3 kAbsUp = {0, 1, 0};
|
||||||
|
constexpr Vector3 kAbsRight = {1, 0, 0};
|
||||||
|
constexpr Vector3 kAbsForward = {0, 0, -1};
|
||||||
|
|
||||||
|
using Mat4x4 = 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 PitchAngle = Angle<float, 0.f, 180.f, AngleFlags::Clamped>;
|
||||||
|
using YawAngle = Angle<float, 0.f, 360.f, AngleFlags::Normalized>;
|
||||||
|
using RollAngle = Angle<float, 0.f, 360.f, AngleFlags::Normalized>;
|
||||||
|
|
||||||
|
using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>;
|
||||||
|
}
|
||||||
54
include/omath/engines/OpenGL/Formulas.hpp
Normal file
54
include/omath/engines/OpenGL/Formulas.hpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
//
|
||||||
|
// Created by Orange on 12/23/2024.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "Constants.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace omath::opengl
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
inline Vector3 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 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 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& 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},
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,19 +2,18 @@
|
|||||||
// Created by Orange on 12/4/2024.
|
// Created by Orange on 12/4/2024.
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Constants.h"
|
#include "Constants.hpp"
|
||||||
#include "omath/projection/Camera.hpp"
|
#include "omath/projection/Camera.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath::source
|
namespace omath::source
|
||||||
{
|
{
|
||||||
class OMATH_API Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Camera(const Vector3& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
Camera(const Vector3& 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& target) override;
|
void LookAt(const Vector3& target) override;
|
||||||
[[nodiscard]] Mat4x4 GetViewMatrix() const override;
|
[[nodiscard]] Mat4x4 CalcViewMatrix() const override;
|
||||||
[[nodiscard]] Mat4x4 GetProjectionMatrix() const override;
|
[[nodiscard]] Mat4x4 CalcProjectionMatrix() const override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Created by Orange on 12/4/2024.
|
// Created by Orange on 12/4/2024.
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Constants.h"
|
#include "Constants.hpp"
|
||||||
|
|
||||||
namespace omath::source
|
namespace omath::source
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/* Export prefix for functions */
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
/* MSVC */
|
|
||||||
# define OMATH_API_EXPORT __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
/* GCC/Clang */
|
|
||||||
# define OMATH_API_EXPORT __attribute__((visibility("default")))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Import prefix for functions */
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# define OMATH_API_IMPORT __declspec(dllimport)
|
|
||||||
#else
|
|
||||||
# define OMATH_API_IMPORT extern
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Resolve import/export */
|
|
||||||
#ifdef OMATH_EXPORT
|
|
||||||
# define OMATH_API OMATH_API_EXPORT
|
|
||||||
#else
|
|
||||||
# define OMATH_API OMATH_API_IMPORT
|
|
||||||
#endif
|
|
||||||
@@ -6,11 +6,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "NavigationMesh.hpp"
|
#include "NavigationMesh.hpp"
|
||||||
#include "omath/Vector3.hpp"
|
#include "omath/Vector3.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath::pathfinding
|
namespace omath::pathfinding
|
||||||
{
|
{
|
||||||
class OMATH_API Astar final
|
class Astar final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include <expected>
|
#include <expected>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath::pathfinding
|
namespace omath::pathfinding
|
||||||
{
|
{
|
||||||
@@ -23,16 +22,16 @@ namespace omath::pathfinding
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API std::expected<Vector3, std::string> GetClosestVertex(const Vector3& point) const;
|
std::expected<Vector3, std::string> GetClosestVertex(const Vector3& point) const;
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API const std::vector<Vector3>& GetNeighbors(const Vector3& vertex) const;
|
const std::vector<Vector3>& GetNeighbors(const Vector3& vertex) const;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
OMATH_API bool Empty() const;
|
bool Empty() const;
|
||||||
[[nodiscard]] std::vector<uint8_t> Serialize() const;
|
[[nodiscard]] std::vector<uint8_t> Serialize() const;
|
||||||
OMATH_API void Deserialize(const std::vector<uint8_t>& raw);
|
void Deserialize(const std::vector<uint8_t>& raw);
|
||||||
|
|
||||||
std::unordered_map<Vector3, std::vector<Vector3>> m_verTextMap;
|
std::unordered_map<Vector3, std::vector<Vector3>> m_verTextMap;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,11 +8,10 @@
|
|||||||
#include "omath/Vector3.hpp"
|
#include "omath/Vector3.hpp"
|
||||||
#include "omath/prediction/Projectile.hpp"
|
#include "omath/prediction/Projectile.hpp"
|
||||||
#include "omath/prediction/Target.hpp"
|
#include "omath/prediction/Target.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath::prediction
|
namespace omath::prediction
|
||||||
{
|
{
|
||||||
class OMATH_API Engine final
|
class Engine final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Engine(float gravityConstant, float simulationTimeStep,
|
explicit Engine(float gravityConstant, float simulationTimeStep,
|
||||||
|
|||||||
@@ -4,11 +4,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/Vector3.hpp"
|
#include "omath/Vector3.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath::prediction
|
namespace omath::prediction
|
||||||
{
|
{
|
||||||
class OMATH_API Projectile final
|
class Projectile final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/Vector3.hpp"
|
#include "omath/Vector3.hpp"
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath::prediction
|
namespace omath::prediction
|
||||||
{
|
{
|
||||||
class OMATH_API Target final
|
class Target final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,10 @@
|
|||||||
#include "ErrorCodes.hpp"
|
#include "ErrorCodes.hpp"
|
||||||
#include <omath/Angle.hpp>
|
#include <omath/Angle.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include "omath/omath_export.hpp"
|
|
||||||
|
|
||||||
namespace omath::projection
|
namespace omath::projection
|
||||||
{
|
{
|
||||||
class OMATH_API ViewPort final
|
class ViewPort final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float m_width;
|
float m_width;
|
||||||
@@ -28,9 +27,8 @@ namespace omath::projection
|
|||||||
using FieldOfView = const Angle<float, 0.f, 180.f, AngleFlags::Clamped>;
|
using FieldOfView = const Angle<float, 0.f, 180.f, AngleFlags::Clamped>;
|
||||||
|
|
||||||
template<class Mat4x4Type, class ViewAnglesType>
|
template<class Mat4x4Type, class ViewAnglesType>
|
||||||
class OMATH_API Camera
|
class Camera
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Camera() = default;
|
virtual ~Camera() = default;
|
||||||
Camera(const Vector3& position, const ViewAnglesType& viewAngles, const ViewPort& viewPort,
|
Camera(const Vector3& position, const ViewAnglesType& viewAngles, const ViewPort& viewPort,
|
||||||
@@ -43,18 +41,82 @@ namespace omath::projection
|
|||||||
|
|
||||||
virtual void LookAt(const Vector3& target) = 0;
|
virtual void LookAt(const Vector3& target) = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual Mat4x4Type GetViewMatrix() const = 0;
|
[[nodiscard]] virtual Mat4x4Type CalcViewMatrix() const = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual Mat4x4Type GetProjectionMatrix() const = 0;
|
[[nodiscard]] virtual Mat4x4Type CalcProjectionMatrix() const = 0;
|
||||||
|
|
||||||
[[nodiscard]] Mat4x4Type GetViewProjectionMatrix()
|
[[nodiscard]] Mat4x4Type CalcViewProjectionMatrix() const
|
||||||
{
|
{
|
||||||
return GetProjectionMatrix() * GetViewMatrix();
|
return CalcProjectionMatrix() * CalcViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] std::expected<Vector3, Error> WorldToScreen(const Mat4x4Type& viewProj, const Vector3& worldPosition) const
|
void SetFieldOfView(const FieldOfView& fov)
|
||||||
{
|
{
|
||||||
auto projected = viewProj * MatColumnFromVector<float, Mat4x4Type::GetStoreOrdering()>(worldPosition);
|
m_fieldOfView = fov;
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetNearPlane(const float near)
|
||||||
|
{
|
||||||
|
m_nearPlaneDistance = near;
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetFarPlane(const float far)
|
||||||
|
{
|
||||||
|
m_farPlaneDistance = far;
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetViewAngles(const ViewAnglesType& viewAngles)
|
||||||
|
{
|
||||||
|
m_viewAngles = viewAngles;
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetOrigin(const Vector3& origin)
|
||||||
|
{
|
||||||
|
m_origin = origin;
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetViewPort(const ViewPort& viewPort)
|
||||||
|
{
|
||||||
|
m_viewPort = viewPort;
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const FieldOfView& GetFieldOfView() const
|
||||||
|
{
|
||||||
|
return m_fieldOfView;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const float& GetNearPlane() const
|
||||||
|
{
|
||||||
|
return m_nearPlaneDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const float& GetFarPlane() const
|
||||||
|
{
|
||||||
|
return m_farPlaneDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const ViewAnglesType& GetViewAngles() const
|
||||||
|
{
|
||||||
|
return m_viewAngles;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const Vector3& GetOrigin() const
|
||||||
|
{
|
||||||
|
return m_origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::expected<Vector3, Error> WorldToScreen(const Vector3& worldPosition) const
|
||||||
|
{
|
||||||
|
if (!m_viewProjectionMatrix.has_value())
|
||||||
|
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||||
|
|
||||||
|
auto projected = m_viewProjectionMatrix.value() * 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);
|
||||||
@@ -64,13 +126,18 @@ namespace omath::projection
|
|||||||
if (IsNdcOutOfBounds(projected))
|
if (IsNdcOutOfBounds(projected))
|
||||||
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
||||||
|
|
||||||
return Vector3{(projected.At(0,0)+1) / 2 * m_viewPort.m_width , (-projected.At(1,0)+1) / 2 * m_viewPort.m_height, projected.At(2,0)};
|
const auto screenPositionX = (projected.At(0,0)+1.f) / 2.f * m_viewPort.m_width;
|
||||||
|
const auto screenPositionY = (-projected.At(1,0)+1) / 2.f * m_viewPort.m_height;
|
||||||
|
|
||||||
|
return Vector3{screenPositionX, screenPositionY, projected.At(2,0)};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ViewPort m_viewPort{};
|
ViewPort m_viewPort{};
|
||||||
Angle<float, 0.f, 180.f, AngleFlags::Clamped> m_fieldOfView;
|
Angle<float, 0.f, 180.f, AngleFlags::Clamped> m_fieldOfView;
|
||||||
|
|
||||||
|
mutable std::optional<Mat4x4Type> m_viewProjectionMatrix;
|
||||||
|
|
||||||
float m_farPlaneDistance;
|
float m_farPlaneDistance;
|
||||||
float m_nearPlaneDistance;
|
float m_nearPlaneDistance;
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
add_subdirectory(Source)
|
add_subdirectory(Source)
|
||||||
|
add_subdirectory(OpenGL)
|
||||||
1
source/engines/OpenGL/CMakeLists.txt
Normal file
1
source/engines/OpenGL/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
target_sources(omath PRIVATE Camera.cpp)
|
||||||
35
source/engines/OpenGL/Camera.cpp
Normal file
35
source/engines/OpenGL/Camera.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// Created by Orange on 12/23/2024.
|
||||||
|
//
|
||||||
|
#include "omath/engines/OpenGL/Camera.hpp"
|
||||||
|
#include "omath/engines/OpenGL/Formulas.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace omath::opengl
|
||||||
|
{
|
||||||
|
|
||||||
|
Camera::Camera(const Vector3& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||||
|
const Angle<float, 0, 180, 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& 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 opengl::CalcViewMatrix(m_viewAngles, m_origin);
|
||||||
|
}
|
||||||
|
Mat4x4 Camera::CalcProjectionMatrix() const
|
||||||
|
{
|
||||||
|
return CalcPerspectiveProjectionMatrix(m_fieldOfView.AsDegrees(), m_viewPort.AspectRatio(), m_nearPlaneDistance,
|
||||||
|
m_farPlaneDistance);
|
||||||
|
}
|
||||||
|
} // namespace omath::opengl
|
||||||
@@ -24,13 +24,14 @@ namespace omath::source
|
|||||||
m_viewAngles.roll = RollAngle::FromRadians(0.f);
|
m_viewAngles.roll = RollAngle::FromRadians(0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4x4 Camera::GetViewMatrix() const
|
Mat4x4 Camera::CalcViewMatrix() const
|
||||||
{
|
{
|
||||||
return CalcViewMatrix(m_viewAngles, m_origin);
|
return source::CalcViewMatrix(m_viewAngles, m_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4x4 Camera::GetProjectionMatrix() const
|
Mat4x4 Camera::CalcProjectionMatrix() const
|
||||||
{
|
{
|
||||||
return CalcPerspectiveProjectionMatrix(m_fieldOfView.AsDegrees(), m_viewPort.AspectRatio(), m_nearPlaneDistance, m_farPlaneDistance);
|
return CalcPerspectiveProjectionMatrix(m_fieldOfView.AsDegrees(), m_viewPort.AspectRatio(), m_nearPlaneDistance,
|
||||||
|
m_farPlaneDistance);
|
||||||
}
|
}
|
||||||
} // namespace omath::source
|
} // namespace omath::source
|
||||||
|
|||||||
@@ -1,37 +1,69 @@
|
|||||||
//
|
//
|
||||||
// Created by Orange on 11/23/2024.
|
// Created by Orange on 11/23/2024.
|
||||||
//
|
//
|
||||||
#include <complex>
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <omath/Matrix.hpp>
|
#include <omath/engines/OpenGL/Camera.hpp>
|
||||||
#include <print>
|
#include <omath/engines/OpenGL/Constants.hpp>
|
||||||
|
#include <omath/engines/OpenGL/Formulas.hpp>
|
||||||
// #include <glm/glm.hpp>
|
|
||||||
|
|
||||||
// #include "glm/ext/matrix_clip_space.hpp"
|
|
||||||
// #include "glm/ext/matrix_transform.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
TEST(UnitTestOpenGL, Projection)
|
TEST(UnitTestOpenGL, ForwardVector)
|
||||||
{
|
{
|
||||||
|
const auto forward = omath::opengl::ForwardVector({});
|
||||||
|
|
||||||
/*const auto proj_glm = glm::perspective(glm::radians(90.f), 16.f / 9.f, 0.1f, 1000.f);
|
EXPECT_EQ(forward, omath::opengl::kAbsForward);
|
||||||
// const auto proj_glm2 = glm::perspectiveLH_NO(glm::radians(90.f), 16.f / 9.f, 0.1f, 1000.f);
|
}
|
||||||
// const auto proj_omath = omath::Mat<4, 4, float, omath::MatStoreType::COLUMN_MAJOR>((const float*)&proj_glm);
|
|
||||||
// EXPECT_EQ(omath::opengl::PerspectiveProjectionMatrix(90, 16.f / 9.f, 0.1f, 1000.f), proj_omath);
|
TEST(UnitTestOpenGL, RightVector)
|
||||||
|
{
|
||||||
|
const auto right = omath::opengl::RightVector({});
|
||||||
glm::vec4 ndc_glm2 = proj_glm * glm::vec4(300.f, 0.f, -1000.f, 1.f);
|
|
||||||
ndc_glm2 /= ndc_glm2.w;
|
EXPECT_EQ(right, omath::opengl::kAbsRight);
|
||||||
const omath::Mat<4, 1, float, omath::MatStoreType::COLUMN_MAJOR> cords_omath =
|
}
|
||||||
{
|
|
||||||
{0},
|
TEST(UnitTestOpenGL, UpVector)
|
||||||
{0},
|
{
|
||||||
{-0.2f},
|
const auto up = omath::opengl::UpVector({});
|
||||||
{1}
|
EXPECT_EQ(up, omath::opengl::kAbsUp);
|
||||||
};
|
}
|
||||||
|
|
||||||
//auto ndc_omath = proj_omath * cords_omath;
|
TEST(UnitTestOpenGL, ProjectTargetMovedFromCamera)
|
||||||
// ndc_omath /= ndc_omath.At(3, 0);
|
{
|
||||||
*/
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
for (float distance = -10.f; distance > -1000.f; distance -= 0.01f)
|
||||||
|
{
|
||||||
|
const auto projected = cam.WorldToScreen({0, 0, distance});
|
||||||
|
|
||||||
|
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(UnitTestOpenGL, CameraSetAndGetFov)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 90.f);
|
||||||
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 50.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestOpenGL, CameraSetAndGetOrigin)
|
||||||
|
{
|
||||||
|
auto cam = omath::opengl::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetOrigin(), omath::Vector3{});
|
||||||
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 50.f);
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <omath/engines/Source/Camera.hpp>
|
#include <omath/engines/Source/Camera.hpp>
|
||||||
#include <omath/engines/Source/Constants.h>
|
#include <omath/engines/Source/Constants.hpp>
|
||||||
#include <omath/engines/Source/Formulas.hpp>
|
#include <omath/engines/Source/Formulas.hpp>
|
||||||
|
|
||||||
|
|
||||||
@@ -27,17 +27,15 @@ TEST(UnitTestSourceEngine, UpVector)
|
|||||||
EXPECT_EQ(up, omath::source::kAbsUp);
|
EXPECT_EQ(up, omath::source::kAbsUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(UnitTestSourceEngine, PerpectiveProjectionAtCenter)
|
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);
|
auto cam = omath::source::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
|
||||||
const auto viewProjMatrix = cam.GetViewProjectionMatrix();
|
|
||||||
|
|
||||||
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
for (float distance = 0.02f; distance < 1000.f; distance += 0.01f)
|
||||||
{
|
{
|
||||||
const auto projected = cam.WorldToScreen(viewProjMatrix, {distance, 0, 0});
|
const auto projected = cam.WorldToScreen({distance, 0, 0});
|
||||||
|
|
||||||
EXPECT_TRUE(projected.has_value());
|
EXPECT_TRUE(projected.has_value());
|
||||||
|
|
||||||
@@ -48,3 +46,24 @@ TEST(UnitTestSourceEngine, PerpectiveProjectionAtCenter)
|
|||||||
EXPECT_NEAR(projected->y, 540, 0.00001f);
|
EXPECT_NEAR(projected->y, 540, 0.00001f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestSourceEngine, CameraSetAndGetFov)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 90.f);
|
||||||
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 50.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestSourceEngine, CameraSetAndGetOrigin)
|
||||||
|
{
|
||||||
|
auto cam = omath::source::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetOrigin(), omath::Vector3{});
|
||||||
|
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 50.f);
|
||||||
|
}
|
||||||
@@ -40,6 +40,14 @@ TEST_F(UnitTestMat, Constructor_InitializerList)
|
|||||||
EXPECT_FLOAT_EQ(m.At(1, 1), 4.0f);
|
EXPECT_FLOAT_EQ(m.At(1, 1), 4.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(UnitTestMat, Operator_SquareBrackets)
|
||||||
|
{
|
||||||
|
EXPECT_EQ((m2[0, 0]), 1.0f);
|
||||||
|
EXPECT_EQ((m2[0, 1]), 2.0f);
|
||||||
|
EXPECT_EQ((m2[1, 0]), 3.0f);
|
||||||
|
EXPECT_EQ((m2[1, 1]), 4.0f);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(UnitTestMat, Constructor_Copy)
|
TEST_F(UnitTestMat, Constructor_Copy)
|
||||||
{
|
{
|
||||||
Mat<2, 2> m3 = m2;
|
Mat<2, 2> m3 = m2;
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ TEST_F(UnitTestMatrix, Constructor_Size)
|
|||||||
EXPECT_EQ(m.ColumnsCount(), 3);
|
EXPECT_EQ(m.ColumnsCount(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(UnitTestMatrix, Operator_SquareBrackets)
|
||||||
|
{
|
||||||
|
EXPECT_EQ((m2[0, 0]), 1.0f);
|
||||||
|
EXPECT_EQ((m2[0, 1]), 2.0f);
|
||||||
|
EXPECT_EQ((m2[1, 0]), 3.0f);
|
||||||
|
EXPECT_EQ((m2[1, 1]), 4.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(UnitTestMatrix, Constructor_InitializerList)
|
TEST_F(UnitTestMatrix, Constructor_InitializerList)
|
||||||
{
|
{
|
||||||
Matrix m{{1.0f, 2.0f}, {3.0f, 4.0f}};
|
Matrix m{{1.0f, 2.0f}, {3.0f, 4.0f}};
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
TEST(UnitTestProjection, Projection)
|
TEST(UnitTestProjection, Projection)
|
||||||
{
|
{
|
||||||
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::Camera({0, 0, 0}, omath::source::ViewAngles{}, {1920.f, 1080.f}, x, 0.01f, 1000.f);
|
||||||
|
|
||||||
const auto projected = cam.WorldToScreen(cam.GetViewProjectionMatrix(), {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