mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 15:03:27 +00:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d1d06c24ca | |||
| 169011e238 | |||
| 934ca0da0a | |||
| 4200ef63a6 | |||
| 58e2c3b5b7 | |||
|
|
c3202a3bc3 | ||
|
|
39ab9d065d | ||
|
|
ed372a1c78 | ||
| 70313f5ae0 | |||
|
|
978656b573 | ||
|
|
a0f746b84c | ||
|
|
6d0d267743 | ||
| 9ba3bc754a | |||
| 3d1844fa0e | |||
| f21d29c6c2 | |||
| 28a35d5bc9 | |||
| d9684ff73f | |||
| 900501f37e | |||
| 5639cd0eb5 | |||
| 244d01c313 | |||
| e31ffac103 | |||
| ae87257adf | |||
| 906f5099d1 |
@@ -1,32 +1,39 @@
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(omath VERSION 1.0.1)
|
||||
project(omath VERSION 1.0.1 LANGUAGES CXX)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||
|
||||
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_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
||||
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
||||
|
||||
|
||||
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
||||
add_library(omath SHARED source/Vector3.cpp)
|
||||
else()
|
||||
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)
|
||||
add_library(omath STATIC source/Matrix.cpp)
|
||||
endif()
|
||||
|
||||
set_target_properties(omath PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
UNITY_BUILD ON
|
||||
UNITY_BUILD_BATCH_SIZE 20
|
||||
CXX_STANDARD 23
|
||||
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_definitions(omath PUBLIC OMATH_EXPORT)
|
||||
if (OMATH_USE_AVX2)
|
||||
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
|
||||
endif()
|
||||
|
||||
add_subdirectory(source)
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ For detailed commands on installing different versions and more information, ple
|
||||
3. Build the project using CMake:
|
||||
```
|
||||
cmake --preset windows-release -S .
|
||||
cmake --build cmake-build/build/windows-release --target server -j 6
|
||||
cmake --build cmake-build/build/windows-release --target omath -j 6
|
||||
```
|
||||
Use **\<platform\>-\<build configuration\>** preset to build siutable version for yourself. Like **windows-release** or **linux-release**.
|
||||
## ❔ Usage
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace omath
|
||||
class Angle
|
||||
{
|
||||
Type m_angle;
|
||||
constexpr Angle(const Type& degrees)
|
||||
constexpr explicit Angle(const Type& degrees)
|
||||
{
|
||||
if constexpr (flags == AngleFlags::Normalized)
|
||||
m_angle = angles::WrapAngle(degrees, min, max);
|
||||
@@ -36,7 +36,7 @@ namespace omath
|
||||
[[nodiscard]]
|
||||
constexpr static Angle FromDegrees(const Type& degrees)
|
||||
{
|
||||
return {degrees};
|
||||
return Angle{degrees};
|
||||
}
|
||||
constexpr Angle() : m_angle(0)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace omath
|
||||
[[nodiscard]]
|
||||
constexpr static Angle FromRadians(const Type& degrees)
|
||||
{
|
||||
return {angles::RadiansToDegrees<Type>(degrees)};
|
||||
return Angle{angles::RadiansToDegrees<Type>(degrees)};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@@ -146,7 +146,7 @@ namespace omath
|
||||
[[nodiscard]]
|
||||
constexpr Angle operator-() const
|
||||
{
|
||||
return {-m_angle};
|
||||
return Angle{-m_angle};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ namespace omath
|
||||
};
|
||||
|
||||
|
||||
class Color final : public Vector4
|
||||
class Color final : public Vector4<float>
|
||||
{
|
||||
public:
|
||||
constexpr Color(float r, float g, float b, float a) : Vector4(r,g,b,a)
|
||||
constexpr Color(const float r, const float g, const float b, const float a) : Vector4(r,g,b,a)
|
||||
{
|
||||
Clamp(0.f, 1.f);
|
||||
}
|
||||
|
||||
@@ -34,11 +34,13 @@ namespace omath
|
||||
class Mat final
|
||||
{
|
||||
public:
|
||||
constexpr Mat()
|
||||
constexpr Mat() noexcept
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
constexpr static MatStoreType GetStoreOrdering()
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr static MatStoreType GetStoreOrdering() noexcept
|
||||
{
|
||||
return StoreType;
|
||||
}
|
||||
@@ -72,6 +74,7 @@ namespace omath
|
||||
m_data = other.m_data;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Type& operator[](const size_t row, const size_t col)
|
||||
{
|
||||
return At(row, col);
|
||||
@@ -100,7 +103,8 @@ namespace omath
|
||||
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)
|
||||
throw std::out_of_range("Index out of range");
|
||||
@@ -177,6 +181,7 @@ namespace omath
|
||||
return *this = *this * other;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Mat operator*(const Type& f) const noexcept
|
||||
{
|
||||
Mat result(*this);
|
||||
@@ -192,6 +197,7 @@ namespace omath
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Mat operator/(const Type& f) const noexcept
|
||||
{
|
||||
Mat result(*this);
|
||||
@@ -333,21 +339,21 @@ namespace omath
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||
[[nodiscard]]
|
||||
constexpr static Mat<1, 4, Type, St> MatRowFromVector(const Vector3& vector) noexcept
|
||||
constexpr static Mat<1, 4, Type, St> MatRowFromVector(const Vector3<Type>& vector) noexcept
|
||||
{
|
||||
return {{vector.x, vector.y, vector.z, 1}};
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||
[[nodiscard]]
|
||||
constexpr static Mat<4, 1, Type, St> MatColumnFromVector(const Vector3& vector) noexcept
|
||||
constexpr static Mat<4, 1, Type, St> MatColumnFromVector(const Vector3<Type>& vector) noexcept
|
||||
{
|
||||
return {{vector.x}, {vector.y}, {vector.z}, {1}};
|
||||
}
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||
[[nodiscard]]
|
||||
constexpr Mat<4, 4, Type, St> MatTranslation(const Vector3& diff) noexcept
|
||||
constexpr Mat<4, 4, Type, St> MatTranslation(const Vector3<Type>& diff) noexcept
|
||||
{
|
||||
return
|
||||
{
|
||||
@@ -399,8 +405,8 @@ namespace omath
|
||||
|
||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||
[[nodiscard]]
|
||||
static Mat<4, 4, Type, St> MatCameraView(const Vector3& forward, const Vector3& right, const Vector3& up,
|
||||
const Vector3& cameraOrigin) noexcept
|
||||
static Mat<4, 4, Type, St> MatCameraView(const Vector3<Type>& forward, const Vector3<Type>& right,
|
||||
const Vector3<Type>& up, const Vector3<Type>& cameraOrigin) noexcept
|
||||
{
|
||||
return Mat<4, 4, Type, St>
|
||||
{
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "Vector3.hpp"
|
||||
|
||||
namespace omath
|
||||
{
|
||||
class Vector3;
|
||||
|
||||
class Matrix final
|
||||
{
|
||||
@@ -19,10 +19,10 @@ namespace omath
|
||||
static Matrix ToScreenMatrix(float screenWidth, float screenHeight);
|
||||
|
||||
[[nodiscard]]
|
||||
static Matrix TranslationMatrix(const Vector3& diff);
|
||||
static Matrix TranslationMatrix(const Vector3<float>& diff);
|
||||
|
||||
[[nodiscard]]
|
||||
static Matrix OrientationMatrix(const Vector3& forward, const Vector3& right, const Vector3& up);
|
||||
static Matrix OrientationMatrix(const Vector3<float>& forward, const Vector3<float>& right, const Vector3<float>& up);
|
||||
|
||||
[[nodiscard]]
|
||||
static Matrix ProjectionMatrix(float fieldOfView, float aspectRatio, float near, float far);
|
||||
|
||||
@@ -6,6 +6,16 @@
|
||||
|
||||
namespace omath
|
||||
{
|
||||
/*
|
||||
|\
|
||||
| \
|
||||
a | \ hypot
|
||||
| \
|
||||
-----
|
||||
b
|
||||
*/
|
||||
|
||||
|
||||
template<class Vector>
|
||||
class Triangle final
|
||||
{
|
||||
@@ -16,12 +26,12 @@ namespace omath
|
||||
{
|
||||
}
|
||||
|
||||
Vector3 m_vertex1;
|
||||
Vector3 m_vertex2;
|
||||
Vector3 m_vertex3;
|
||||
Vector3<float> m_vertex1;
|
||||
Vector3<float> m_vertex2;
|
||||
Vector3<float> m_vertex3;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector3 CalculateNormal() const
|
||||
constexpr Vector3<float> CalculateNormal() const
|
||||
{
|
||||
const auto b = SideBVector();
|
||||
const auto a = SideAVector();
|
||||
@@ -41,7 +51,7 @@ namespace omath
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector3 SideAVector() const
|
||||
constexpr Vector3<float> SideAVector() const
|
||||
{
|
||||
return m_vertex1 - m_vertex2;
|
||||
}
|
||||
@@ -61,12 +71,12 @@ namespace omath
|
||||
return std::abs(sideA*sideA + sideB*sideB - hypot*hypot) <= 0.0001f;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr Vector3 SideBVector() const
|
||||
constexpr Vector3<float> SideBVector() const
|
||||
{
|
||||
return m_vertex3 - m_vertex2;
|
||||
}
|
||||
[[nodiscard]]
|
||||
constexpr Vector3 MidPoint() const
|
||||
constexpr Vector3<float> MidPoint() const
|
||||
{
|
||||
return (m_vertex1 + m_vertex2 + m_vertex3) / 3;
|
||||
}
|
||||
|
||||
@@ -8,16 +8,18 @@
|
||||
|
||||
namespace omath
|
||||
{
|
||||
|
||||
template<class Type> requires std::is_arithmetic_v<Type>
|
||||
class Vector2
|
||||
{
|
||||
public:
|
||||
float x = 0.f;
|
||||
float y = 0.f;
|
||||
Type x = static_cast<Type>(0);
|
||||
Type y = static_cast<Type>(0);
|
||||
|
||||
// Constructors
|
||||
constexpr Vector2() = default;
|
||||
|
||||
constexpr Vector2(const float x, const float y) : x(x), y(y) {}
|
||||
constexpr Vector2(const Type& x, const Type& y) : x(x), y(y) {}
|
||||
|
||||
// Equality operators
|
||||
[[nodiscard]]
|
||||
@@ -65,7 +67,7 @@ namespace omath
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator*=(const float fl)
|
||||
constexpr Vector2& operator*=(const Type& fl)
|
||||
{
|
||||
x *= fl;
|
||||
y *= fl;
|
||||
@@ -73,7 +75,7 @@ namespace omath
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator/=(const float fl)
|
||||
constexpr Vector2& operator/=(const Type& fl)
|
||||
{
|
||||
x /= fl;
|
||||
y /= fl;
|
||||
@@ -81,7 +83,7 @@ namespace omath
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator+=(const float fl)
|
||||
constexpr Vector2& operator+=(const Type& fl)
|
||||
{
|
||||
x += fl;
|
||||
y += fl;
|
||||
@@ -89,7 +91,7 @@ namespace omath
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector2& operator-=(const float fl)
|
||||
constexpr Vector2& operator-=(const Type& fl)
|
||||
{
|
||||
x -= fl;
|
||||
y -= fl;
|
||||
@@ -98,45 +100,45 @@ namespace omath
|
||||
}
|
||||
|
||||
// Basic vector operations
|
||||
[[nodiscard]] float DistTo(const Vector2& vOther) const
|
||||
[[nodiscard]] Type DistTo(const Vector2& vOther) const
|
||||
{
|
||||
return std::sqrt(DistToSqr(vOther));
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr float DistToSqr(const Vector2& vOther) const
|
||||
[[nodiscard]] constexpr Type DistToSqr(const Vector2& vOther) const
|
||||
{
|
||||
return (x - vOther.x) * (x - vOther.x) + (y - vOther.y) * (y - vOther.y);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr float Dot(const Vector2& vOther) const
|
||||
[[nodiscard]] constexpr Type Dot(const Vector2& vOther) const
|
||||
{
|
||||
return x * vOther.x + y * vOther.y;
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
[[nodiscard]] constexpr float Length() const
|
||||
[[nodiscard]] constexpr Type& Length() const
|
||||
{
|
||||
return std::hypot(x, y);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector2 Normalized() const
|
||||
{
|
||||
const float len = Length();
|
||||
const Type len = Length();
|
||||
return len > 0.f ? *this / len : *this;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] float Length() const
|
||||
[[nodiscard]] Type Length() const
|
||||
{
|
||||
return std::hypot(x, y);
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector2 Normalized() const
|
||||
{
|
||||
const float len = Length();
|
||||
const Type len = Length();
|
||||
return len > 0.f ? *this / len : *this;
|
||||
}
|
||||
#endif
|
||||
[[nodiscard]] constexpr float LengthSqr() const
|
||||
[[nodiscard]] constexpr Type LengthSqr() const
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
@@ -187,13 +189,13 @@ namespace omath
|
||||
}
|
||||
|
||||
// Sum of elements
|
||||
[[nodiscard]] constexpr float Sum() const
|
||||
[[nodiscard]] constexpr Type Sum() const
|
||||
{
|
||||
return x + y;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::tuple<float, float> AsTuple() const
|
||||
constexpr std::tuple<Type, Type> AsTuple() const
|
||||
{
|
||||
return std::make_tuple(x, y);
|
||||
}
|
||||
|
||||
@@ -20,16 +20,17 @@ namespace omath
|
||||
IMPOSSIBLE_BETWEEN_ANGLE,
|
||||
};
|
||||
|
||||
class Vector3 : public Vector2
|
||||
template<class Type> requires std::is_arithmetic_v<Type>
|
||||
class Vector3 : public Vector2<Type>
|
||||
{
|
||||
public:
|
||||
float z = 0.f;
|
||||
constexpr Vector3(const float x, const float y, const float z) : Vector2(x, y), z(z) { }
|
||||
constexpr Vector3() : Vector2() {};
|
||||
Type z = static_cast<Type>(0);
|
||||
constexpr Vector3(const Type& x, const Type& y, const Type& z) : Vector2<Type>(x, y), z(z) { }
|
||||
constexpr Vector3() : Vector2<Type>() {};
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(const Vector3& src) const
|
||||
{
|
||||
return Vector2::operator==(src) && (src.z == z);
|
||||
return Vector2<Type>::operator==(src) && (src.z == z);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator!=(const Vector3& src) const
|
||||
@@ -39,7 +40,7 @@ namespace omath
|
||||
|
||||
constexpr Vector3& operator+=(const Vector3& v)
|
||||
{
|
||||
Vector2::operator+=(v);
|
||||
Vector2<Type>::operator+=(v);
|
||||
z += v.z;
|
||||
|
||||
return *this;
|
||||
@@ -47,7 +48,7 @@ namespace omath
|
||||
|
||||
constexpr Vector3& operator-=(const Vector3& v)
|
||||
{
|
||||
Vector2::operator-=(v);
|
||||
Vector2<Type>::operator-=(v);
|
||||
z -= v.z;
|
||||
|
||||
return *this;
|
||||
@@ -55,7 +56,7 @@ namespace omath
|
||||
|
||||
constexpr Vector3& operator*=(const float fl)
|
||||
{
|
||||
Vector2::operator*=(fl);
|
||||
Vector2<Type>::operator*=(fl);
|
||||
z *= fl;
|
||||
|
||||
return *this;
|
||||
@@ -63,7 +64,7 @@ namespace omath
|
||||
|
||||
constexpr Vector3& operator*=(const Vector3& v)
|
||||
{
|
||||
Vector2::operator*=(v);
|
||||
Vector2<Type>::operator*=(v);
|
||||
z *= v.z;
|
||||
|
||||
return *this;
|
||||
@@ -71,7 +72,7 @@ namespace omath
|
||||
|
||||
constexpr Vector3& operator/=(const Vector3& v)
|
||||
{
|
||||
Vector2::operator/=(v);
|
||||
Vector2<Type>::operator/=(v);
|
||||
z /= v.z;
|
||||
|
||||
return *this;
|
||||
@@ -79,7 +80,7 @@ namespace omath
|
||||
|
||||
constexpr Vector3& operator+=(const float fl)
|
||||
{
|
||||
Vector2::operator+=(fl);
|
||||
Vector2<Type>::operator+=(fl);
|
||||
z += fl;
|
||||
|
||||
return *this;
|
||||
@@ -87,7 +88,7 @@ namespace omath
|
||||
|
||||
constexpr Vector3& operator/=(const float fl)
|
||||
{
|
||||
Vector2::operator/=(fl);
|
||||
Vector2<Type>::operator/=(fl);
|
||||
z /= fl;
|
||||
|
||||
return *this;
|
||||
@@ -95,7 +96,7 @@ namespace omath
|
||||
|
||||
constexpr Vector3& operator-=(const float fl)
|
||||
{
|
||||
Vector2::operator-=(fl);
|
||||
Vector2<Type>::operator-=(fl);
|
||||
z -= fl;
|
||||
|
||||
return *this;
|
||||
@@ -103,117 +104,117 @@ namespace omath
|
||||
|
||||
constexpr Vector3& Abs()
|
||||
{
|
||||
Vector2::Abs();
|
||||
Vector2<Type>::Abs();
|
||||
z = z < 0.f ? -z : z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr float DistToSqr(const Vector3& vOther) const
|
||||
[[nodiscard]] constexpr Type DistToSqr(const Vector3& vOther) const
|
||||
{
|
||||
return (*this - vOther).LengthSqr();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr float Dot(const Vector3& vOther) const
|
||||
[[nodiscard]] constexpr Type Dot(const Vector3& vOther) const
|
||||
{
|
||||
return Vector2::Dot(vOther) + z * vOther.z;
|
||||
return Vector2<Type>::Dot(vOther) + z * vOther.z;
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
[[nodiscard]] constexpr float Length() const
|
||||
[[nodiscard]] constexpr Type Length() const
|
||||
{
|
||||
return std::hypot(x, y, z);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr float Length2D() const
|
||||
[[nodiscard]] constexpr Type Length2D() const
|
||||
{
|
||||
return Vector2::Length();
|
||||
}
|
||||
[[nodiscard]] float DistTo(const Vector3& vOther) const
|
||||
[[nodiscard]] Type DistTo(const Vector3& vOther) const
|
||||
{
|
||||
return (*this - vOther).Length();
|
||||
}
|
||||
[[nodiscard]] constexpr Vector3 Normalized() const
|
||||
{
|
||||
const float length = this->Length();
|
||||
const Type length = this->Length();
|
||||
|
||||
return length != 0 ? *this / length : *this;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] float Length() const
|
||||
[[nodiscard]] Type Length() const
|
||||
{
|
||||
return std::hypot(x, y, z);
|
||||
return std::hypot(this->x, this->y, z);
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3 Normalized() const
|
||||
{
|
||||
const float length = this->Length();
|
||||
const Type length = this->Length();
|
||||
|
||||
return length != 0 ? *this / length : *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] float Length2D() const
|
||||
[[nodiscard]] Type Length2D() const
|
||||
{
|
||||
return Vector2::Length();
|
||||
return Vector2<Type>::Length();
|
||||
}
|
||||
|
||||
[[nodiscard]] float DistTo(const Vector3& vOther) const
|
||||
[[nodiscard]] Type DistTo(const Vector3& vOther) const
|
||||
{
|
||||
return (*this - vOther).Length();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
[[nodiscard]] constexpr float LengthSqr() const
|
||||
[[nodiscard]] constexpr Type LengthSqr() const
|
||||
{
|
||||
return Vector2::LengthSqr() + z * z;
|
||||
return Vector2<Type>::LengthSqr() + z * z;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator-() const
|
||||
{
|
||||
return {-x, -y, -z};
|
||||
return {-this->x, -this->y, -z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator+(const Vector3& v) const
|
||||
{
|
||||
return {x + v.x, y + v.y, z + v.z};
|
||||
return {this->x + v.x, this->y + v.y, z + v.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator-(const Vector3& v) const
|
||||
{
|
||||
return {x - v.x, y - v.y, z - v.z};
|
||||
return {this->x - v.x, this->y - v.y, z - v.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator*(const float fl) const
|
||||
{
|
||||
return {x * fl, y * fl, z * fl};
|
||||
return {this->x * fl, this->y * fl, z * fl};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator*(const Vector3& v) const
|
||||
{
|
||||
return {x * v.x, y * v.y, z * v.z};
|
||||
return {this->x * v.x, this->y * v.y, z * v.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator/(const float fl) const
|
||||
{
|
||||
return {x / fl, y / fl, z / fl};
|
||||
return {this->x / fl, this->y / fl, z / fl};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 operator/(const Vector3& v) const
|
||||
{
|
||||
return {x / v.x, y / v.y, z / v.z};
|
||||
return {this->x / v.x, this->y / v.y, z / v.z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vector3 Cross(const Vector3 &v) const
|
||||
{
|
||||
return
|
||||
{
|
||||
y * v.z - z * v.y,
|
||||
z * v.x - x * v.z,
|
||||
x * v.y - y * v.x
|
||||
this->y * v.z - z * v.y,
|
||||
z * v.x - this->x * v.z,
|
||||
this->x * v.y - this->y * v.x
|
||||
};
|
||||
}
|
||||
[[nodiscard]] constexpr float Sum() const
|
||||
[[nodiscard]] constexpr Type Sum() const
|
||||
{
|
||||
return Sum2D() + z;
|
||||
}
|
||||
@@ -237,16 +238,27 @@ namespace omath
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr float Sum2D() const
|
||||
[[nodiscard]] constexpr Type Sum2D() const
|
||||
{
|
||||
return Vector2::Sum();
|
||||
return Vector2<Type>::Sum();
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3 ViewAngleTo(const Vector3& other) const;
|
||||
|
||||
[[nodiscard]] constexpr std::tuple<float, float, float> AsTuple() const
|
||||
[[nodiscard]] constexpr std::tuple<Type, Type, Type> AsTuple() const
|
||||
{
|
||||
return std::make_tuple(x, y, z);
|
||||
return std::make_tuple(this->x, this->y, z);
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3 ViewAngleTo(const Vector3 &other) const
|
||||
{
|
||||
const float distance = DistTo(other);
|
||||
const auto delta = other - *this;
|
||||
|
||||
return
|
||||
{
|
||||
angles::RadiansToDegrees(std::asin(delta.z / distance)),
|
||||
angles::RadiansToDegrees(std::atan2(delta.y, delta.x)),
|
||||
0
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -254,9 +266,9 @@ namespace omath
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<omath::Vector3>
|
||||
struct hash<omath::Vector3<float>>
|
||||
{
|
||||
std::size_t operator()(const omath::Vector3& vec) const noexcept
|
||||
std::size_t operator()(const omath::Vector3<float>& vec) const noexcept
|
||||
{
|
||||
std::size_t hash = 0;
|
||||
constexpr std::hash<float> hasher;
|
||||
|
||||
@@ -8,18 +8,19 @@
|
||||
|
||||
namespace omath
|
||||
{
|
||||
class Vector4 : public Vector3
|
||||
template <class Type>
|
||||
class Vector4 : public Vector3<Type>
|
||||
{
|
||||
public:
|
||||
float w;
|
||||
Type w;
|
||||
|
||||
constexpr Vector4(const float x, const float y, const float z, const float w) : Vector3(x, y, z), w(w) {}
|
||||
constexpr Vector4() : Vector3(), w(0.f) {};
|
||||
constexpr Vector4(const Type& x, const Type& y, const Type& z, const Type& w) : Vector3<Type>(x, y, z), w(w) {}
|
||||
constexpr Vector4() : Vector3<Type>(), w(0) {};
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator==(const Vector4& src) const
|
||||
{
|
||||
return Vector3::operator==(src) && w == src.w;
|
||||
return Vector3<Type>::operator==(src) && w == src.w;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@@ -30,7 +31,7 @@ namespace omath
|
||||
|
||||
constexpr Vector4& operator+=(const Vector4& v)
|
||||
{
|
||||
Vector3::operator+=(v);
|
||||
Vector3<Type>::operator+=(v);
|
||||
w += v.w;
|
||||
|
||||
return *this;
|
||||
@@ -38,7 +39,7 @@ namespace omath
|
||||
|
||||
constexpr Vector4& operator-=(const Vector4& v)
|
||||
{
|
||||
Vector3::operator-=(v);
|
||||
Vector3<Type>::operator-=(v);
|
||||
w -= v.w;
|
||||
|
||||
return *this;
|
||||
@@ -46,7 +47,7 @@ namespace omath
|
||||
|
||||
constexpr Vector4& operator*=(const float scalar)
|
||||
{
|
||||
Vector3::operator*=(scalar);
|
||||
Vector3<Type>::operator*=(scalar);
|
||||
w *= scalar;
|
||||
|
||||
return *this;
|
||||
@@ -54,7 +55,7 @@ namespace omath
|
||||
|
||||
constexpr Vector4& operator*=(const Vector4& v)
|
||||
{
|
||||
Vector3::operator*=(v);
|
||||
Vector3<Type>::operator*=(v);
|
||||
w *= v.w;
|
||||
|
||||
return *this;
|
||||
@@ -62,7 +63,7 @@ namespace omath
|
||||
|
||||
constexpr Vector4& operator/=(const float scalar)
|
||||
{
|
||||
Vector3::operator/=(scalar);
|
||||
Vector3<Type>::operator/=(scalar);
|
||||
w /= scalar;
|
||||
|
||||
return *this;
|
||||
@@ -70,35 +71,38 @@ namespace omath
|
||||
|
||||
constexpr Vector4& operator/=(const Vector4& v)
|
||||
{
|
||||
Vector3::operator/=(v);
|
||||
Vector3<Type>::operator/=(v);
|
||||
w /= v.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr float LengthSqr() const
|
||||
[[nodiscard]] constexpr Type LengthSqr() const
|
||||
{
|
||||
return Vector3::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::Dot(vOther) + w * vOther.w;
|
||||
return Vector3<Type>::Dot(vOther) + w * vOther.w;
|
||||
}
|
||||
|
||||
[[nodiscard]] float Length() const;
|
||||
[[nodiscard]] Vector3<Type> Length() const
|
||||
{
|
||||
return std::sqrt(LengthSqr());
|
||||
}
|
||||
|
||||
constexpr Vector4& Abs()
|
||||
{
|
||||
Vector3::Abs();
|
||||
Vector3<Type>::Abs();
|
||||
w = w < 0.f ? -w : w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
constexpr Vector4& Clamp(const float min, const float max)
|
||||
constexpr Vector4& Clamp(const Type& min, const Type& max)
|
||||
{
|
||||
x = std::clamp(x, min, max);
|
||||
y = std::clamp(y, min, max);
|
||||
z = std::clamp(z, min, max);
|
||||
this->x = std::clamp(this->x, min, max);
|
||||
this->y = std::clamp(this->y, min, max);
|
||||
this->z = std::clamp(this->z, min, max);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -106,49 +110,49 @@ namespace omath
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator-() const
|
||||
{
|
||||
return {-x, -y, -z, -w};
|
||||
return {-this->x, -this->y, -this->z, -w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator+(const Vector4& v) const
|
||||
{
|
||||
return {x + v.x, y + v.y, z + v.z, w + v.w};
|
||||
return {this->x + v.x, this->y + v.y, this->z + v.z, w + v.w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator-(const Vector4& v) const
|
||||
{
|
||||
return {x - v.x, y - v.y, z - v.z, w - v.w};
|
||||
return {this->x - v.x, this->y - v.y, this->z - v.z, w - v.w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator*(const float scalar) const
|
||||
constexpr Vector4 operator*(const Type& scalar) const
|
||||
{
|
||||
return {x * scalar, y * scalar, z * scalar, w * scalar};
|
||||
return {this->x * scalar, this->y * scalar, this->z * scalar, w * scalar};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator*(const Vector4& v) const
|
||||
{
|
||||
return {x * v.x, y * v.y, z * v.z, w * v.w};
|
||||
return {this->x * v.x, this->y * v.y, this->z * v.z, w * v.w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator/(const float scalar) const
|
||||
constexpr Vector4 operator/(const Type& scalar) const
|
||||
{
|
||||
return {x / scalar, y / scalar, z / scalar, w / scalar};
|
||||
return {this->x / scalar, this->y / scalar, this->z / scalar, w / scalar};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector4 operator/(const Vector4& v) const
|
||||
{
|
||||
return {x / v.x, y / v.y, z / v.z, w / v.w};
|
||||
return {this->x / v.x, this->y / v.y, this->z / v.z, w / v.w};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr float Sum() const
|
||||
constexpr Type Sum() const
|
||||
{
|
||||
return Vector3::Sum() + w;
|
||||
return Vector3<Type>::Sum() + w;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ namespace omath::collision
|
||||
class Ray
|
||||
{
|
||||
public:
|
||||
Vector3 start;
|
||||
Vector3 end;
|
||||
Vector3<float> start;
|
||||
Vector3<float> end;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3 DirectionVector() const;
|
||||
Vector3<float> DirectionVector() const;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3 DirectionVectorNormalized() const;
|
||||
Vector3<float> DirectionVectorNormalized() const;
|
||||
};
|
||||
class LineTracer
|
||||
{
|
||||
@@ -27,12 +27,12 @@ namespace omath::collision
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
static bool CanTraceLine(const Ray& ray, const Triangle<Vector3>& triangle);
|
||||
static bool CanTraceLine(const Ray& ray, const Triangle<Vector3<float>>& triangle);
|
||||
|
||||
|
||||
// Realization of Möller–Trumbore intersection algorithm
|
||||
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
|
||||
[[nodiscard]]
|
||||
static Vector3 GetRayHitPoint(const Ray& ray, const Triangle<Vector3>& triangle);
|
||||
static Vector3<float> GetRayHitPoint(const Ray& ray, const Triangle<Vector3<float>>& triangle);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace omath::opengl
|
||||
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
||||
{
|
||||
public:
|
||||
Camera(const Vector3& 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);
|
||||
void LookAt(const Vector3& target) override;
|
||||
void LookAt(const Vector3<float>& target) override;
|
||||
[[nodiscard]] Mat4x4 CalcViewMatrix() const override;
|
||||
[[nodiscard]] Mat4x4 CalcProjectionMatrix() const override;
|
||||
};
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
namespace omath::opengl
|
||||
{
|
||||
constexpr Vector3 kAbsUp = {0, 1, 0};
|
||||
constexpr Vector3 kAbsRight = {1, 0, 0};
|
||||
constexpr Vector3 kAbsForward = {0, 0, -1};
|
||||
constexpr Vector3<float> kAbsUp = {0, 1, 0};
|
||||
constexpr Vector3<float> kAbsRight = {1, 0, 0};
|
||||
constexpr Vector3<float> kAbsForward = {0, 0, -1};
|
||||
|
||||
using Mat4x4 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>;
|
||||
using Mat3x3 = Mat<4, 4, float, MatStoreType::COLUMN_MAJOR>;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace omath::opengl
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline Vector3 ForwardVector(const ViewAngles& angles)
|
||||
inline Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||
{
|
||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace omath::opengl
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline Vector3 RightVector(const ViewAngles& angles)
|
||||
inline Vector3<float> RightVector(const ViewAngles& angles)
|
||||
{
|
||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace omath::opengl
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline Vector3 UpVector(const ViewAngles& angles)
|
||||
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& cam_origin)
|
||||
[[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);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace omath::source
|
||||
class Camera final : public projection::Camera<Mat4x4, ViewAngles>
|
||||
{
|
||||
public:
|
||||
Camera(const Vector3& 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);
|
||||
void LookAt(const Vector3& target) override;
|
||||
void LookAt(const Vector3<float>& target) override;
|
||||
[[nodiscard]] Mat4x4 CalcViewMatrix() const override;
|
||||
[[nodiscard]] Mat4x4 CalcProjectionMatrix() const override;
|
||||
};
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <omath/ViewAngles.hpp>
|
||||
namespace omath::source
|
||||
{
|
||||
constexpr Vector3 kAbsUp = {0, 0, 1};
|
||||
constexpr Vector3 kAbsRight = {0, -1, 0};
|
||||
constexpr Vector3 kAbsForward = {1, 0, 0};
|
||||
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>;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace omath::source
|
||||
{
|
||||
[[nodiscard]]
|
||||
inline Vector3 ForwardVector(const ViewAngles& angles)
|
||||
inline Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||
{
|
||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsForward);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace omath::source
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline Vector3 RightVector(const ViewAngles& angles)
|
||||
inline Vector3<float> RightVector(const ViewAngles& angles)
|
||||
{
|
||||
const auto vec = MatRotation(angles) * MatColumnFromVector(kAbsRight);
|
||||
|
||||
@@ -23,14 +23,14 @@ namespace omath::source
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline Vector3 UpVector(const ViewAngles& angles)
|
||||
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& cam_origin)
|
||||
[[nodiscard]] inline Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||
{
|
||||
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,22 @@
|
||||
|
||||
namespace omath::pathfinding
|
||||
{
|
||||
struct PathNode;
|
||||
class Astar final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
static std::vector<Vector3> FindPath(const Vector3& start, const Vector3& end, const NavigationMesh& navMesh);
|
||||
static std::vector<Vector3<float>> FindPath(const Vector3<float>& start, const Vector3<float>& end,
|
||||
const NavigationMesh& navMesh);
|
||||
|
||||
private:
|
||||
[[nodiscard]]
|
||||
static std::vector<Vector3<float>>
|
||||
ReconstructFinalPath(const std::unordered_map<Vector3<float>, PathNode>& closedList,
|
||||
const Vector3<float>& current);
|
||||
|
||||
[[nodiscard]]
|
||||
static auto GetPerfectNode(const std::unordered_map<Vector3<float>, PathNode>& openList,
|
||||
const Vector3<float>& endVertex);
|
||||
};
|
||||
}
|
||||
} // namespace omath::pathfinding
|
||||
|
||||
@@ -22,17 +22,17 @@ namespace omath::pathfinding
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
std::expected<Vector3, std::string> GetClosestVertex(const Vector3& point) const;
|
||||
std::expected<Vector3<float>, std::string> GetClosestVertex(const Vector3<float>& point) const;
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
const std::vector<Vector3>& GetNeighbors(const Vector3& vertex) const;
|
||||
const std::vector<Vector3<float>>& GetNeighbors(const Vector3<float>& vertex) const;
|
||||
|
||||
[[nodiscard]]
|
||||
bool Empty() const;
|
||||
[[nodiscard]] std::vector<uint8_t> Serialize() const;
|
||||
void Deserialize(const std::vector<uint8_t>& raw);
|
||||
|
||||
std::unordered_map<Vector3, std::vector<Vector3>> m_verTextMap;
|
||||
std::unordered_map<Vector3<float>, std::vector<Vector3<float>>> m_verTextMap;
|
||||
};
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include "omath/Vector3.hpp"
|
||||
#include "omath/prediction/Projectile.hpp"
|
||||
#include "omath/prediction/Target.hpp"
|
||||
|
||||
namespace omath::prediction
|
||||
{
|
||||
class Engine final
|
||||
{
|
||||
public:
|
||||
explicit Engine(float gravityConstant, float simulationTimeStep,
|
||||
float maximumSimulationTime, float distanceTolerance);
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<Vector3> MaybeCalculateAimPoint(const Projectile& projectile, const Target& target) const;
|
||||
|
||||
private:
|
||||
const float m_gravityConstant;
|
||||
const float m_simulationTimeStep;
|
||||
const float m_maximumSimulationTime;
|
||||
const float m_distanceTolerance;
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<float> MaybeCalculateProjectileLaunchPitchAngle(const Projectile& projectile,
|
||||
const Vector3& targetPosition) const;
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsProjectileReachedTarget(const Vector3& targetPosition, const Projectile& projectile, float pitch, float time) const;
|
||||
|
||||
};
|
||||
}
|
||||
20
include/omath/projectile_prediction/ProjPredEngine.hpp
Normal file
20
include/omath/projectile_prediction/ProjPredEngine.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by Vlad on 2/23/2025.
|
||||
//
|
||||
#pragma once
|
||||
#include "Projectile.hpp"
|
||||
#include "Target.hpp"
|
||||
#include "omath/Vector3.hpp"
|
||||
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
class ProjPredEngine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]]
|
||||
virtual std::optional<Vector3<float>> MaybeCalculateAimPoint(const Projectile& projectile,
|
||||
const Target& target) const = 0;
|
||||
virtual ~ProjPredEngine() = default;
|
||||
};
|
||||
} // namespace omath::projectile_prediction
|
||||
26
include/omath/projectile_prediction/ProjPredEngineAVX2.hpp
Normal file
26
include/omath/projectile_prediction/ProjPredEngineAVX2.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Vlad on 2/23/2025.
|
||||
//
|
||||
#pragma once
|
||||
#include "ProjPredEngine.hpp"
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
class ProjPredEngineAVX2 final : public ProjPredEngine
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] std::optional<Vector3<float>> MaybeCalculateAimPoint(const Projectile& projectile,
|
||||
const Target& target) const override;
|
||||
|
||||
|
||||
ProjPredEngineAVX2(float gravityConstant, float simulationTimeStep, float maximumSimulationTime);
|
||||
~ProjPredEngineAVX2() override = default;
|
||||
|
||||
private:
|
||||
[[nodiscard]] static std::optional<float> CalculatePitch(const Vector3<float>& projOrigin, const Vector3<float>& targetPos,
|
||||
float bulletGravity, float v0, float time);
|
||||
const float m_gravityConstant;
|
||||
const float m_simulationTimeStep;
|
||||
const float m_maximumSimulationTime;
|
||||
};
|
||||
} // namespace omath::projectile_prediction
|
||||
41
include/omath/projectile_prediction/ProjPredEngineLegacy.hpp
Normal file
41
include/omath/projectile_prediction/ProjPredEngineLegacy.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include "omath/Vector3.hpp"
|
||||
#include "omath/projectile_prediction/ProjPredEngine.hpp"
|
||||
#include "omath/projectile_prediction/Projectile.hpp"
|
||||
#include "omath/projectile_prediction/Target.hpp"
|
||||
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
class ProjPredEngineLegacy final : public ProjPredEngine
|
||||
{
|
||||
public:
|
||||
explicit ProjPredEngineLegacy(float gravityConstant, float simulationTimeStep, float maximumSimulationTime,
|
||||
float distanceTolerance);
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<Vector3<float>> MaybeCalculateAimPoint(const Projectile& projectile,
|
||||
const Target& target) const override;
|
||||
|
||||
private:
|
||||
const float m_gravityConstant;
|
||||
const float m_simulationTimeStep;
|
||||
const float m_maximumSimulationTime;
|
||||
const float m_distanceTolerance;
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<float> MaybeCalculateProjectileLaunchPitchAngle(const Projectile& projectile,
|
||||
const Vector3<float>& targetPosition) const;
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsProjectileReachedTarget(const Vector3<float>& targetPosition, const Projectile& projectile, float pitch,
|
||||
float time) const;
|
||||
};
|
||||
} // namespace omath::projectile_prediction
|
||||
@@ -5,16 +5,16 @@
|
||||
#pragma once
|
||||
#include "omath/Vector3.hpp"
|
||||
|
||||
namespace omath::prediction
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
class Projectile final
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3 PredictPosition(float pitch, float yaw, float time, float gravity) const;
|
||||
Vector3<float> PredictPosition(float pitch, float yaw, float time, float gravity) const;
|
||||
|
||||
Vector3 m_origin;
|
||||
Vector3<float> m_origin;
|
||||
float m_launchSpeed{};
|
||||
float m_gravityScale{};
|
||||
};
|
||||
@@ -5,14 +5,14 @@
|
||||
#pragma once
|
||||
#include "omath/Vector3.hpp"
|
||||
|
||||
namespace omath::prediction
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
class Target final
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Vector3 PredictPosition(const float time, const float gravity) const
|
||||
constexpr Vector3<float> PredictPosition(const float time, const float gravity) const
|
||||
{
|
||||
auto predicted = m_origin + m_velocity * time;
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace omath::prediction
|
||||
return predicted;
|
||||
}
|
||||
|
||||
Vector3 m_origin;
|
||||
Vector3 m_velocity;
|
||||
Vector3<float> m_origin;
|
||||
Vector3<float> m_velocity;
|
||||
bool m_isAirborne{};
|
||||
};
|
||||
}
|
||||
@@ -31,15 +31,15 @@ namespace omath::projection
|
||||
{
|
||||
public:
|
||||
virtual ~Camera() = default;
|
||||
Camera(const Vector3& position, const ViewAnglesType& viewAngles, const ViewPort& viewPort,
|
||||
Camera(const Vector3<float>& position, const ViewAnglesType& viewAngles, const ViewPort& viewPort,
|
||||
const FieldOfView& fov, const float near, const float far) :
|
||||
m_viewPort(viewPort), m_fieldOfView(fov), m_farPlaneDistance(far), m_nearPlaneDistance(near),
|
||||
m_viewAngles(viewAngles), m_origin(position)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void LookAt(const Vector3& target) = 0;
|
||||
protected:
|
||||
virtual void LookAt(const Vector3<float>& target) = 0;
|
||||
|
||||
[[nodiscard]] virtual Mat4x4Type CalcViewMatrix() const = 0;
|
||||
|
||||
@@ -49,41 +49,44 @@ namespace omath::projection
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
void SetOrigin(const Vector3<float>& origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||
}
|
||||
|
||||
void SetViewPort(const ViewPort& viewPort)
|
||||
{
|
||||
m_viewPort = viewPort;
|
||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||
}
|
||||
|
||||
[[nodiscard]] const FieldOfView& GetFieldOfView() const
|
||||
@@ -106,17 +109,16 @@ namespace omath::projection
|
||||
return m_viewAngles;
|
||||
}
|
||||
|
||||
[[nodiscard]] const Vector3& GetOrigin() const
|
||||
[[nodiscard]] const Vector3<float>& GetOrigin() const
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::expected<Vector3, Error> WorldToScreen(const Vector3& worldPosition) const
|
||||
[[nodiscard]] std::expected<Vector3<float>, Error> WorldToScreen(const Vector3<float>& worldPosition) const
|
||||
{
|
||||
if (!m_viewProjectionMatrix.has_value())
|
||||
m_viewProjectionMatrix = CalcViewProjectionMatrix();
|
||||
const auto& viewProjMatrix = GetViewProjectionMatrix();
|
||||
|
||||
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)
|
||||
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
||||
@@ -143,7 +145,7 @@ namespace omath::projection
|
||||
|
||||
|
||||
ViewAnglesType m_viewAngles;
|
||||
Vector3 m_origin;
|
||||
Vector3<float> m_origin;
|
||||
|
||||
private:
|
||||
template<class Type>
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
target_sources(omath PRIVATE
|
||||
Vector3.cpp
|
||||
Matrix.cpp
|
||||
color.cpp
|
||||
Vector4.cpp
|
||||
Vector2.cpp
|
||||
)
|
||||
|
||||
add_subdirectory(prediction)
|
||||
add_subdirectory(projectile_prediction)
|
||||
add_subdirectory(pathfinding)
|
||||
add_subdirectory(projection)
|
||||
add_subdirectory(collision)
|
||||
|
||||
@@ -315,7 +315,7 @@ namespace omath
|
||||
};
|
||||
}
|
||||
|
||||
Matrix Matrix::TranslationMatrix(const Vector3& diff)
|
||||
Matrix Matrix::TranslationMatrix(const Vector3<float>& diff)
|
||||
{
|
||||
return {
|
||||
{1.f, 0.f, 0.f, 0.f},
|
||||
@@ -325,7 +325,7 @@ namespace omath
|
||||
};
|
||||
}
|
||||
|
||||
Matrix Matrix::OrientationMatrix(const Vector3& forward, const Vector3& right, const Vector3& up)
|
||||
Matrix Matrix::OrientationMatrix(const Vector3<float>& forward, const Vector3<float>& right, const Vector3<float>& up)
|
||||
{
|
||||
return {
|
||||
{right.x, up.x, forward.x, 0.f},
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
//
|
||||
// Created by Vlad on 02.09.2024.
|
||||
//
|
||||
#include "omath/Vector2.hpp"
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace omath
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
//
|
||||
// Created by vlad on 10/28/23.
|
||||
//
|
||||
|
||||
#include <omath/Vector3.hpp>
|
||||
#include <cmath>
|
||||
#include <omath/Angles.hpp>
|
||||
|
||||
namespace omath
|
||||
{
|
||||
Vector3 Vector3::ViewAngleTo(const Vector3 &other) const
|
||||
{
|
||||
const float distance = DistTo(other);
|
||||
const auto delta = other - *this;
|
||||
|
||||
return
|
||||
{
|
||||
angles::RadiansToDegrees(std::asin(delta.z / distance)),
|
||||
angles::RadiansToDegrees(std::atan2(delta.y, delta.x)),
|
||||
0.f
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// Vector4.cpp
|
||||
//
|
||||
|
||||
#include "omath/Vector4.hpp"
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace omath
|
||||
{
|
||||
|
||||
float Vector4::Length() const
|
||||
{
|
||||
return std::sqrt(LengthSqr());
|
||||
}
|
||||
}
|
||||
@@ -5,21 +5,21 @@
|
||||
|
||||
namespace omath::collision
|
||||
{
|
||||
bool LineTracer::CanTraceLine(const Ray& ray, const Triangle<Vector3>& triangle)
|
||||
bool LineTracer::CanTraceLine(const Ray& ray, const Triangle<Vector3<float>>& triangle)
|
||||
{
|
||||
return GetRayHitPoint(ray, triangle) == ray.end;
|
||||
}
|
||||
Vector3 Ray::DirectionVector() const
|
||||
Vector3<float> Ray::DirectionVector() const
|
||||
{
|
||||
return end - start;
|
||||
}
|
||||
|
||||
Vector3 Ray::DirectionVectorNormalized() const
|
||||
Vector3<float> Ray::DirectionVectorNormalized() const
|
||||
{
|
||||
return DirectionVector().Normalized();
|
||||
}
|
||||
|
||||
Vector3 LineTracer::GetRayHitPoint(const Ray& ray, const Triangle<Vector3>& triangle)
|
||||
Vector3<float> LineTracer::GetRayHitPoint(const Ray& ray, const Triangle<Vector3<float>>& triangle)
|
||||
{
|
||||
constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
namespace omath::opengl
|
||||
{
|
||||
|
||||
Camera::Camera(const Vector3& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||
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& target)
|
||||
void Camera::LookAt([[maybe_unused]] const Vector3<float>& target)
|
||||
{
|
||||
const float distance = m_origin.DistTo(target);
|
||||
const auto delta = target - m_origin;
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
namespace omath::source
|
||||
{
|
||||
|
||||
Camera::Camera(const Vector3& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||
const projection::FieldOfView& fov, const float near, const float far) :
|
||||
projection::Camera<Mat4x4, ViewAngles>(position, viewAngles, viewPort, fov, near, far)
|
||||
{
|
||||
}
|
||||
void Camera::LookAt(const Vector3& target)
|
||||
void Camera::LookAt(const Vector3<float>& target)
|
||||
{
|
||||
const float distance = m_origin.DistTo(target);
|
||||
const auto delta = target - m_origin;
|
||||
|
||||
@@ -3,60 +3,98 @@
|
||||
//
|
||||
#include "omath/pathfinding/Astar.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace omath::pathfinding
|
||||
{
|
||||
struct PathNode final
|
||||
{
|
||||
std::optional<Vector3> cameFrom;
|
||||
std::optional<Vector3<float>> cameFrom;
|
||||
float gCost = 0.f;
|
||||
};
|
||||
|
||||
|
||||
std::vector<Vector3> Astar::FindPath(const Vector3 &start, const Vector3 &end, const NavigationMesh &navMesh)
|
||||
std::vector<Vector3<float>> Astar::ReconstructFinalPath(const std::unordered_map<Vector3<float>, PathNode>& closedList,
|
||||
const Vector3<float>& current)
|
||||
{
|
||||
std::unordered_map<Vector3, PathNode> closedList;
|
||||
std::unordered_map<Vector3, PathNode> openList;
|
||||
std::vector<Vector3<float>> path;
|
||||
std::optional currentOpt = current;
|
||||
|
||||
while (currentOpt)
|
||||
{
|
||||
path.push_back(*currentOpt);
|
||||
|
||||
auto it = closedList.find(*currentOpt);
|
||||
|
||||
if (it == closedList.end())
|
||||
break;
|
||||
|
||||
currentOpt = it->second.cameFrom;
|
||||
}
|
||||
|
||||
std::ranges::reverse(path);
|
||||
return path;
|
||||
}
|
||||
auto Astar::GetPerfectNode(const std::unordered_map<Vector3<float>, PathNode>& openList, const Vector3<float>& endVertex)
|
||||
{
|
||||
return std::ranges::min_element(openList,
|
||||
[&endVertex](const auto& a, const auto& b)
|
||||
{
|
||||
const float fA = a.second.gCost + a.first.DistTo(endVertex);
|
||||
const float fB = b.second.gCost + b.first.DistTo(endVertex);
|
||||
return fA < fB;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<Vector3<float>> Astar::FindPath(const Vector3<float>& start, const Vector3<float>& end, const NavigationMesh& navMesh)
|
||||
{
|
||||
std::unordered_map<Vector3<float>, PathNode> closedList;
|
||||
std::unordered_map<Vector3<float>, PathNode> openList;
|
||||
|
||||
auto maybeStartVertex = navMesh.GetClosestVertex(start);
|
||||
auto maybeEndVertex = navMesh.GetClosestVertex(end);
|
||||
|
||||
if (!maybeStartVertex || !maybeEndVertex)
|
||||
return {};
|
||||
|
||||
const auto startVertex = maybeStartVertex.value();
|
||||
const auto endVertex = maybeEndVertex.value();
|
||||
|
||||
const auto startVertex = navMesh.GetClosestVertex(start).value();
|
||||
const auto endVertex = navMesh.GetClosestVertex(end).value();
|
||||
|
||||
openList.emplace(startVertex, PathNode{std::nullopt, 0.f});
|
||||
|
||||
while (!openList.empty())
|
||||
{
|
||||
const auto perfectVertex = *std::ranges::min_element(openList,
|
||||
[&endVertex](const auto& a, const auto& b) -> bool
|
||||
{
|
||||
const auto aCost = a.second.gCost + a.first.DistTo(endVertex);
|
||||
const auto bCost = b.second.gCost + b.first.DistTo(endVertex);
|
||||
return aCost < bCost;
|
||||
});
|
||||
auto currentIt = GetPerfectNode(openList, endVertex);
|
||||
|
||||
closedList.emplace(perfectVertex);
|
||||
openList.erase(perfectVertex.first);
|
||||
const auto current = currentIt->first;
|
||||
const auto currentNode = currentIt->second;
|
||||
|
||||
for (const auto& neighbor : navMesh.GetNeighbors(perfectVertex.first))
|
||||
if (!closedList.contains(neighbor))
|
||||
openList.emplace(neighbor, PathNode{perfectVertex.first, neighbor.DistTo(perfectVertex.first) + perfectVertex.second.gCost});
|
||||
if (current == endVertex)
|
||||
return ReconstructFinalPath(closedList, current);
|
||||
|
||||
|
||||
if (perfectVertex.first != endVertex)
|
||||
continue;
|
||||
closedList.emplace(current, currentNode);
|
||||
openList.erase(currentIt);
|
||||
|
||||
std::vector<Vector3> path = {};
|
||||
for (const auto& neighbor: navMesh.GetNeighbors(current))
|
||||
{
|
||||
if (closedList.contains(neighbor))
|
||||
continue;
|
||||
|
||||
for (std::optional current = perfectVertex.first; current; current = closedList.at(*current).cameFrom )
|
||||
path.push_back(current.value());
|
||||
const float tentativeGCost = currentNode.gCost + neighbor.DistTo(current);
|
||||
|
||||
return path;
|
||||
const auto openIt = openList.find(neighbor);
|
||||
|
||||
if (openIt == openList.end() || tentativeGCost < openIt->second.gCost)
|
||||
openList[neighbor] = PathNode{current, tentativeGCost};
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
} // namespace omath::pathfinding
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <algorithm>
|
||||
namespace omath::pathfinding
|
||||
{
|
||||
std::expected<Vector3, std::string> NavigationMesh::GetClosestVertex(const Vector3 &point) const
|
||||
std::expected<Vector3<float>, std::string> NavigationMesh::GetClosestVertex(const Vector3<float> &point) const
|
||||
{
|
||||
const auto res = std::ranges::min_element(m_verTextMap,
|
||||
[&point](const auto& a, const auto& b)
|
||||
@@ -21,7 +21,7 @@ namespace omath::pathfinding
|
||||
return res->first;
|
||||
}
|
||||
|
||||
const std::vector<Vector3>& NavigationMesh::GetNeighbors(const Vector3 &vertex) const
|
||||
const std::vector<Vector3<float>>& NavigationMesh::GetNeighbors(const Vector3<float> &vertex) const
|
||||
{
|
||||
return m_verTextMap.at(vertex);
|
||||
}
|
||||
@@ -73,18 +73,18 @@ namespace omath::pathfinding
|
||||
|
||||
while (offset < raw.size())
|
||||
{
|
||||
Vector3 vertex;
|
||||
Vector3<float> vertex;
|
||||
loadFromVector(raw, offset, vertex);
|
||||
|
||||
uint16_t neighborsCount;
|
||||
loadFromVector(raw, offset, neighborsCount);
|
||||
|
||||
std::vector<Vector3> neighbors;
|
||||
std::vector<Vector3<float>> neighbors;
|
||||
neighbors.reserve(neighborsCount);
|
||||
|
||||
for (size_t i = 0; i < neighborsCount; ++i)
|
||||
{
|
||||
Vector3 neighbor;
|
||||
Vector3<float> neighbor;
|
||||
loadFromVector(raw, offset, neighbor);
|
||||
neighbors.push_back(neighbor);
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
target_sources(omath PRIVATE Engine.cpp Projectile.cpp Target.cpp)
|
||||
1
source/projectile_prediction/CMakeLists.txt
Normal file
1
source/projectile_prediction/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
target_sources(omath PRIVATE ProjPredEngineLegacy.cpp Projectile.cpp Target.cpp ProjPredEngineAVX2.cpp ProjPredEngine.cpp)
|
||||
10
source/projectile_prediction/ProjPredEngine.cpp
Normal file
10
source/projectile_prediction/ProjPredEngine.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by Vlad on 2/23/2025.
|
||||
//
|
||||
#include "omath/projectile_prediction/ProjPredEngine.hpp"
|
||||
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
|
||||
} // namespace omath::projectile_prediction
|
||||
145
source/projectile_prediction/ProjPredEngineAVX2.cpp
Normal file
145
source/projectile_prediction/ProjPredEngineAVX2.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// Created by Vlad on 2/23/2025.
|
||||
//
|
||||
#include "omath/projectile_prediction/ProjPredEngineAVX2.hpp"
|
||||
#include "source_location"
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
std::optional<Vector3<float>>
|
||||
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 v0 = projectile.m_launchSpeed;
|
||||
const float v0Sqr = v0 * v0;
|
||||
const Vector3 projOrigin = projectile.m_origin;
|
||||
|
||||
constexpr int SIMD_FACTOR = 8;
|
||||
float currentTime = m_simulationTimeStep;
|
||||
|
||||
for (; currentTime <= m_maximumSimulationTime; currentTime += m_simulationTimeStep * SIMD_FACTOR)
|
||||
{
|
||||
const __m256 times =
|
||||
_mm256_setr_ps(currentTime, currentTime + m_simulationTimeStep,
|
||||
currentTime + m_simulationTimeStep * 2, currentTime + m_simulationTimeStep * 3,
|
||||
currentTime + m_simulationTimeStep * 4, currentTime + m_simulationTimeStep * 5,
|
||||
currentTime + m_simulationTimeStep * 6, currentTime + m_simulationTimeStep * 7);
|
||||
|
||||
const __m256 targetX =
|
||||
_mm256_fmadd_ps(_mm256_set1_ps(target.m_velocity.x), times, _mm256_set1_ps(target.m_origin.x));
|
||||
const __m256 targetY =
|
||||
_mm256_fmadd_ps(_mm256_set1_ps(target.m_velocity.y), times, _mm256_set1_ps(target.m_origin.y));
|
||||
const __m256 timesSq = _mm256_mul_ps(times, times);
|
||||
const __m256 targetZ = _mm256_fmadd_ps(_mm256_set1_ps(target.m_velocity.z), times,
|
||||
_mm256_fnmadd_ps(_mm256_set1_ps(0.5f * m_gravityConstant), timesSq,
|
||||
_mm256_set1_ps(target.m_origin.z)));
|
||||
|
||||
const __m256 deltaX = _mm256_sub_ps(targetX, _mm256_set1_ps(projOrigin.x));
|
||||
const __m256 deltaY = _mm256_sub_ps(targetY, _mm256_set1_ps(projOrigin.y));
|
||||
const __m256 deltaZ = _mm256_sub_ps(targetZ, _mm256_set1_ps(projOrigin.z));
|
||||
|
||||
const __m256 dSqr = _mm256_add_ps(_mm256_mul_ps(deltaX, deltaX), _mm256_mul_ps(deltaY, deltaY));
|
||||
|
||||
const __m256 bgTimesSq = _mm256_mul_ps(_mm256_set1_ps(bulletGravity), timesSq);
|
||||
const __m256 term = _mm256_add_ps(deltaZ, _mm256_mul_ps(_mm256_set1_ps(0.5f), bgTimesSq));
|
||||
const __m256 termSq = _mm256_mul_ps(term, term);
|
||||
const __m256 numerator = _mm256_add_ps(dSqr, termSq);
|
||||
const __m256 denominator = _mm256_add_ps(timesSq, _mm256_set1_ps(1e-8f)); // Avoid division by zero
|
||||
const __m256 requiredV0Sqr = _mm256_div_ps(numerator, denominator);
|
||||
|
||||
const __m256 v0SqrVec = _mm256_set1_ps(v0Sqr + 1e-3f);
|
||||
const __m256 mask = _mm256_cmp_ps(requiredV0Sqr, v0SqrVec, _CMP_LE_OQ);
|
||||
|
||||
const unsigned validMask = _mm256_movemask_ps(mask);
|
||||
|
||||
if (!validMask)
|
||||
continue;
|
||||
|
||||
alignas(32) float validTimes[SIMD_FACTOR];
|
||||
_mm256_store_ps(validTimes, times);
|
||||
|
||||
for (int i = 0; i < SIMD_FACTOR; ++i)
|
||||
{
|
||||
if (!(validMask & (1 << i)))
|
||||
continue;
|
||||
|
||||
const float candidateTime = validTimes[i];
|
||||
|
||||
if (candidateTime > m_maximumSimulationTime)
|
||||
continue;
|
||||
|
||||
// Fine search around candidate time
|
||||
for (float fineTime = candidateTime - m_simulationTimeStep * 2;
|
||||
fineTime <= candidateTime + m_simulationTimeStep * 2; fineTime += m_simulationTimeStep)
|
||||
{
|
||||
if (fineTime < 0)
|
||||
continue;
|
||||
|
||||
const Vector3 targetPos = target.PredictPosition(fineTime, m_gravityConstant);
|
||||
const auto pitch = CalculatePitch(projOrigin, targetPos, bulletGravity, v0, fineTime);
|
||||
if (!pitch)
|
||||
continue;
|
||||
|
||||
const Vector3 delta = targetPos - projOrigin;
|
||||
const float d = std::sqrt(delta.x * delta.x + delta.y * delta.y);
|
||||
const float height = d * std::tan(angles::DegreesToRadians(*pitch));
|
||||
return Vector3(targetPos.x, targetPos.y, projOrigin.z + height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback scalar processing for remaining times
|
||||
for (; currentTime <= m_maximumSimulationTime; currentTime += m_simulationTimeStep)
|
||||
{
|
||||
const Vector3 targetPos = target.PredictPosition(currentTime, m_gravityConstant);
|
||||
const auto pitch = CalculatePitch(projOrigin, targetPos, bulletGravity, v0, currentTime);
|
||||
if (!pitch)
|
||||
continue;
|
||||
|
||||
const Vector3 delta = targetPos - projOrigin;
|
||||
const float d = std::sqrt(delta.x * delta.x + delta.y * delta.y);
|
||||
const float height = d * std::tan(angles::DegreesToRadians(*pitch));
|
||||
return Vector3(targetPos.x, targetPos.y, projOrigin.z + height);
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
ProjPredEngineAVX2::ProjPredEngineAVX2(const float gravityConstant, const float simulationTimeStep,
|
||||
const float maximumSimulationTime) :
|
||||
m_gravityConstant(gravityConstant), m_simulationTimeStep(simulationTimeStep),
|
||||
m_maximumSimulationTime(maximumSimulationTime)
|
||||
{
|
||||
}
|
||||
std::optional<float> ProjPredEngineAVX2::CalculatePitch(const Vector3<float>& projOrigin,
|
||||
const Vector3<float>& targetPos, const float bulletGravity,
|
||||
const float v0, const float time)
|
||||
{
|
||||
if (time <= 0.0f)
|
||||
return std::nullopt;
|
||||
|
||||
const Vector3 delta = targetPos - projOrigin;
|
||||
const float dSqr = delta.x * delta.x + delta.y * delta.y;
|
||||
const float h = delta.z;
|
||||
|
||||
const float term = h + 0.5f * bulletGravity * time * time;
|
||||
const float requiredV0Sqr = (dSqr + term * term) / (time * time);
|
||||
const float v0Sqr = v0 * v0;
|
||||
|
||||
if (requiredV0Sqr > v0Sqr + 1e-3f)
|
||||
return std::nullopt;
|
||||
|
||||
if (dSqr == 0.0f)
|
||||
return term >= 0.0f ? 90.0f : -90.0f;
|
||||
|
||||
|
||||
const float d = std::sqrt(dSqr);
|
||||
const float tanTheta = term / d;
|
||||
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
|
||||
@@ -1,25 +1,18 @@
|
||||
//
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
|
||||
#include "omath/prediction/Engine.hpp"
|
||||
#include "omath/projectile_prediction/ProjPredEngineLegacy.hpp"
|
||||
#include <cmath>
|
||||
#include <omath/Angles.hpp>
|
||||
|
||||
|
||||
namespace omath::prediction
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
Engine::Engine(const float gravityConstant, const float simulationTimeStep,
|
||||
const float maximumSimulationTime, const float distanceTolerance)
|
||||
: m_gravityConstant(gravityConstant),
|
||||
m_simulationTimeStep(simulationTimeStep),
|
||||
m_maximumSimulationTime(maximumSimulationTime),
|
||||
m_distanceTolerance(distanceTolerance)
|
||||
ProjPredEngineLegacy::ProjPredEngineLegacy(const float gravityConstant, const float simulationTimeStep,
|
||||
const float maximumSimulationTime, const float distanceTolerance) :
|
||||
m_gravityConstant(gravityConstant), m_simulationTimeStep(simulationTimeStep),
|
||||
m_maximumSimulationTime(maximumSimulationTime), m_distanceTolerance(distanceTolerance)
|
||||
{
|
||||
}
|
||||
|
||||
std::optional<Vector3> Engine::MaybeCalculateAimPoint(const Projectile &projectile, const Target &target) const
|
||||
std::optional<Vector3<float>> ProjPredEngineLegacy::MaybeCalculateAimPoint(const Projectile& projectile,
|
||||
const Target& target) const
|
||||
{
|
||||
for (float time = 0.f; time < m_maximumSimulationTime; time += m_simulationTimeStep)
|
||||
{
|
||||
@@ -28,7 +21,7 @@ namespace omath::prediction
|
||||
const auto projectilePitch = MaybeCalculateProjectileLaunchPitchAngle(projectile, predictedTargetPosition);
|
||||
|
||||
if (!projectilePitch.has_value()) [[unlikely]]
|
||||
continue;
|
||||
continue;
|
||||
|
||||
if (!IsProjectileReachedTarget(predictedTargetPosition, projectile, projectilePitch.value(), time))
|
||||
continue;
|
||||
@@ -41,8 +34,9 @@ namespace omath::prediction
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<float> Engine::MaybeCalculateProjectileLaunchPitchAngle(const Projectile &projectile,
|
||||
const Vector3 &targetPosition) const
|
||||
std::optional<float>
|
||||
ProjPredEngineLegacy::MaybeCalculateProjectileLaunchPitchAngle(const Projectile& projectile,
|
||||
const Vector3<float>& targetPosition) const
|
||||
{
|
||||
const auto bulletGravity = m_gravityConstant * projectile.m_gravityScale;
|
||||
const auto delta = targetPosition - projectile.m_origin;
|
||||
@@ -51,11 +45,11 @@ namespace omath::prediction
|
||||
const auto distance2dSqr = distance2d * distance2d;
|
||||
const auto launchSpeedSqr = projectile.m_launchSpeed * projectile.m_launchSpeed;
|
||||
|
||||
float root = launchSpeedSqr * launchSpeedSqr - bulletGravity * (bulletGravity *
|
||||
distance2dSqr + 2.0f * delta.z * launchSpeedSqr);
|
||||
float root = launchSpeedSqr * launchSpeedSqr -
|
||||
bulletGravity * (bulletGravity * distance2dSqr + 2.0f * delta.z * launchSpeedSqr);
|
||||
|
||||
if (root < 0.0f) [[unlikely]]
|
||||
return std::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
root = std::sqrt(root);
|
||||
const float angle = std::atan((launchSpeedSqr - root) / (bulletGravity * distance2d));
|
||||
@@ -63,12 +57,12 @@ namespace omath::prediction
|
||||
return angles::RadiansToDegrees(angle);
|
||||
}
|
||||
|
||||
bool Engine::IsProjectileReachedTarget(const Vector3 &targetPosition, const Projectile &projectile,
|
||||
const float pitch, const float time) const
|
||||
bool ProjPredEngineLegacy::IsProjectileReachedTarget(const Vector3<float>& targetPosition, const Projectile& projectile,
|
||||
const float pitch, const float time) const
|
||||
{
|
||||
const auto yaw = projectile.m_origin.ViewAngleTo(targetPosition).y;
|
||||
const auto projectilePosition = projectile.PredictPosition(pitch, yaw, time, m_gravityConstant);
|
||||
|
||||
return projectilePosition.DistTo(targetPosition) <= m_distanceTolerance;
|
||||
}
|
||||
}
|
||||
} // namespace omath::projectile_prediction
|
||||
@@ -2,13 +2,13 @@
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#include "omath/prediction/Projectile.hpp"
|
||||
#include <cmath>
|
||||
#include "omath/projectile_prediction/Projectile.hpp"
|
||||
|
||||
#include <omath/engines/Source/Formulas.hpp>
|
||||
|
||||
namespace omath::prediction
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
Vector3 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),
|
||||
source::YawAngle::FromDegrees(yaw),
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#include "omath/prediction/Target.hpp"
|
||||
#include "omath/projectile_prediction/Projectile.hpp"
|
||||
|
||||
|
||||
namespace omath::prediction
|
||||
@@ -1,7 +1,6 @@
|
||||
enable_testing()
|
||||
|
||||
project(unit-tests)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}")
|
||||
|
||||
include(GoogleTest)
|
||||
add_executable(unit-tests
|
||||
@@ -26,6 +25,15 @@ add_executable(unit-tests
|
||||
|
||||
)
|
||||
|
||||
set_target_properties(unit-tests PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||
UNITY_BUILD ON
|
||||
UNITY_BUILD_BATCH_SIZE 20
|
||||
CXX_STANDARD 23
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath)
|
||||
|
||||
gtest_discover_tests(unit-tests)
|
||||
@@ -62,7 +62,7 @@ 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{});
|
||||
EXPECT_EQ(cam.GetOrigin(), omath::Vector3<float>{});
|
||||
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||
|
||||
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 50.f);
|
||||
|
||||
@@ -62,7 +62,7 @@ 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{});
|
||||
EXPECT_EQ(cam.GetOrigin(), omath::Vector3<float>{});
|
||||
cam.SetFieldOfView(omath::projection::FieldOfView::FromDegrees(50.f));
|
||||
|
||||
EXPECT_EQ(cam.GetFieldOfView().AsDegrees(), 50.f);
|
||||
|
||||
@@ -10,10 +10,10 @@ class LineTracerTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
// Set up common variables for use in each test
|
||||
Vector3 vertex1{0.0f, 0.0f, 0.0f};
|
||||
Vector3 vertex2{1.0f, 0.0f, 0.0f};
|
||||
Vector3 vertex3{0.0f, 1.0f, 0.0f};
|
||||
Triangle<Vector3> triangle{vertex1, vertex2, vertex3};
|
||||
Vector3<float> vertex1{0.0f, 0.0f, 0.0f};
|
||||
Vector3<float> vertex2{1.0f, 0.0f, 0.0f};
|
||||
Vector3<float> vertex3{0.0f, 1.0f, 0.0f};
|
||||
Triangle<Vector3<float>> triangle{vertex1, vertex2, vertex3};
|
||||
};
|
||||
|
||||
// Test that a ray intersecting the triangle returns false for CanTraceLine
|
||||
@@ -71,7 +71,7 @@ TEST_F(LineTracerTest, TriangleFarBeyondRayEndPoint)
|
||||
constexpr Ray ray{{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
|
||||
|
||||
// Define a triangle far beyond the ray's endpoint
|
||||
constexpr Triangle<Vector3> distantTriangle{
|
||||
constexpr Triangle<Vector3<float>> distantTriangle{
|
||||
{1000.0f, 1000.0f, 1000.0f}, {1001.0f, 1000.0f, 1000.0f}, {1000.0f, 1001.0f, 1000.0f}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/prediction/Engine.hpp>
|
||||
#include <omath/projectile_prediction/ProjPredEngineLegacy.hpp>
|
||||
|
||||
TEST(UnitTestPrediction, PredictionTest)
|
||||
{
|
||||
constexpr omath::prediction::Target target{
|
||||
constexpr omath::projectile_prediction::Target target{
|
||||
.m_origin = {100, 0, 90}, .m_velocity = {0, 0, 0}, .m_isAirborne = false};
|
||||
constexpr omath::prediction::Projectile proj = {.m_origin = {3,2,1}, .m_launchSpeed = 5000, .m_gravityScale= 0.4};
|
||||
const auto viewPoint = omath::prediction::Engine(400, 1.f / 1000.f, 50, 5.f).MaybeCalculateAimPoint(proj, target);
|
||||
constexpr omath::projectile_prediction::Projectile proj = {
|
||||
.m_origin = {3, 2, 1}, .m_launchSpeed = 5000, .m_gravityScale = 0.4};
|
||||
const auto viewPoint =
|
||||
omath::projectile_prediction::ProjPredEngineLegacy(400, 1.f / 1000.f, 50, 5.f).MaybeCalculateAimPoint(proj, target);
|
||||
|
||||
const auto [pitch, yaw, _] = proj.m_origin.ViewAngleTo(viewPoint.value()).AsTuple();
|
||||
|
||||
EXPECT_NEAR(42.547142, pitch, 0.0001f);
|
||||
EXPECT_NEAR(-1.181189, yaw, 0.0001f);
|
||||
}
|
||||
EXPECT_NEAR(42.547142, pitch, 0.01f);
|
||||
EXPECT_NEAR(-1.181189, yaw, 0.01f);
|
||||
}
|
||||
|
||||
@@ -13,28 +13,28 @@ class UnitTestTriangle : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
// Define some Triangles to use in tests
|
||||
Triangle<Vector3> t1;
|
||||
Triangle<Vector3> t2;
|
||||
Triangle<Vector3> t3;
|
||||
Triangle<Vector3<float>> t1;
|
||||
Triangle<Vector3<float>> t2;
|
||||
Triangle<Vector3<float>> t3;
|
||||
|
||||
constexpr void SetUp() override
|
||||
{
|
||||
// Triangle with vertices (0, 0, 0), (1, 0, 0), (0, 1, 0)
|
||||
t1 = Triangle<Vector3>(
|
||||
t1 = Triangle<Vector3<float>>(
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
Vector3(1.0f, 0.0f, 0.0f),
|
||||
Vector3(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
|
||||
// Triangle with vertices (1, 2, 3), (4, 5, 6), (7, 8, 9)
|
||||
t2 = Triangle<Vector3>(
|
||||
t2 = Triangle<Vector3<float>>(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Vector3(4.0f, 5.0f, 6.0f),
|
||||
Vector3(7.0f, 8.0f, 9.0f)
|
||||
);
|
||||
|
||||
// An isosceles right triangle
|
||||
t3 = Triangle<Vector3>(
|
||||
t3 = Triangle<Vector3<float>>(
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
Vector3(2.0f, 0.0f, 0.0f),
|
||||
Vector3(0.0f, 2.0f, 0.0f)
|
||||
@@ -45,7 +45,7 @@ protected:
|
||||
// Test constructor and vertices
|
||||
TEST_F(UnitTestTriangle, Constructor)
|
||||
{
|
||||
constexpr Triangle<Vector3> t(
|
||||
constexpr Triangle<Vector3<float>> t(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Vector3(4.0f, 5.0f, 6.0f),
|
||||
Vector3(7.0f, 8.0f, 9.0f)
|
||||
@@ -113,7 +113,7 @@ TEST_F(UnitTestTriangle, SideVectors)
|
||||
|
||||
TEST_F(UnitTestTriangle, IsRectangular)
|
||||
{
|
||||
EXPECT_TRUE(Triangle<Vector3>({2,0,0}, {}, {0,2,0}).IsRectangular());
|
||||
EXPECT_TRUE(Triangle<Vector3<float>>({2,0,0}, {}, {0,2,0}).IsRectangular());
|
||||
}
|
||||
// Test midpoint
|
||||
TEST_F(UnitTestTriangle, MidPoint)
|
||||
|
||||
@@ -12,8 +12,8 @@ using namespace omath;
|
||||
class UnitTestVector2 : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
Vector2 v1;
|
||||
Vector2 v2;
|
||||
Vector2<float> v1;
|
||||
Vector2<float> v2;
|
||||
|
||||
constexpr void SetUp() override
|
||||
{
|
||||
@@ -25,7 +25,7 @@ protected:
|
||||
// Test constructor and default values
|
||||
TEST_F(UnitTestVector2, Constructor_Default)
|
||||
{
|
||||
constexpr Vector2 v;
|
||||
constexpr Vector2<float> v;
|
||||
EXPECT_FLOAT_EQ(v.x, 0.0f);
|
||||
EXPECT_FLOAT_EQ(v.y, 0.0f);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ using namespace omath;
|
||||
class UnitTestVector3 : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
Vector3 v1;
|
||||
Vector3 v2;
|
||||
Vector3<float> v1;
|
||||
Vector3<float> v2;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
@@ -26,7 +26,7 @@ protected:
|
||||
// Test constructor and default values
|
||||
TEST_F(UnitTestVector3, Constructor_Default)
|
||||
{
|
||||
constexpr Vector3 v;
|
||||
constexpr Vector3<float> v;
|
||||
EXPECT_FLOAT_EQ(v.x, 0.0f);
|
||||
EXPECT_FLOAT_EQ(v.y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(v.z, 0.0f);
|
||||
@@ -34,7 +34,7 @@ TEST_F(UnitTestVector3, Constructor_Default)
|
||||
|
||||
TEST_F(UnitTestVector3, Constructor_Values)
|
||||
{
|
||||
constexpr Vector3 v(1.0f, 2.0f, 3.0f);
|
||||
constexpr Vector3<float> v(1.0f, 2.0f, 3.0f);
|
||||
EXPECT_FLOAT_EQ(v.x, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v.y, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v.z, 3.0f);
|
||||
|
||||
@@ -14,8 +14,8 @@ using namespace omath;
|
||||
class UnitTestVector4 : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
Vector4 v1;
|
||||
Vector4 v2;
|
||||
Vector4<float> v1;
|
||||
Vector4<float> v2;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
@@ -27,7 +27,7 @@ protected:
|
||||
// Test constructor and default values
|
||||
TEST_F(UnitTestVector4, Constructor_Default)
|
||||
{
|
||||
constexpr Vector4 v;
|
||||
constexpr Vector4<float> v;
|
||||
EXPECT_FLOAT_EQ(v.x, 0.0f);
|
||||
EXPECT_FLOAT_EQ(v.y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(v.z, 0.0f);
|
||||
|
||||
Reference in New Issue
Block a user