mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-14 07:23:26 +00:00
Merge pull request #30 from orange-cpp/u/orange-cpp/imgui-integration
ImGUI Vector integration
This commit is contained in:
@@ -9,7 +9,7 @@ option(OMATH_BUILD_TESTS "Build unit tests" OFF)
|
|||||||
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
|
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
|
||||||
option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
||||||
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
||||||
|
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
|
||||||
|
|
||||||
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)
|
||||||
@@ -17,6 +17,14 @@ else()
|
|||||||
add_library(omath STATIC source/Matrix.cpp)
|
add_library(omath STATIC source/Matrix.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (OMATH_IMGUI_INTEGRATION)
|
||||||
|
target_compile_definitions(omath PUBLIC OMATH_IMGUI_INTEGRATION)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (OMATH_USE_AVX2)
|
||||||
|
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
|
||||||
|
endif()
|
||||||
|
|
||||||
set_target_properties(omath PROPERTIES
|
set_target_properties(omath PROPERTIES
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
@@ -31,9 +39,6 @@ endif()
|
|||||||
|
|
||||||
target_compile_features(omath PUBLIC cxx_std_23)
|
target_compile_features(omath PUBLIC cxx_std_23)
|
||||||
|
|
||||||
if (OMATH_USE_AVX2)
|
|
||||||
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory(source)
|
add_subdirectory(source)
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <tuple>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
|
#include <imgui.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
|
|
||||||
template<class Type> requires std::is_arithmetic_v<Type>
|
template<class Type>
|
||||||
|
requires std::is_arithmetic_v<Type>
|
||||||
class Vector2
|
class Vector2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -19,7 +25,9 @@ namespace omath
|
|||||||
// Constructors
|
// Constructors
|
||||||
constexpr Vector2() = default;
|
constexpr Vector2() = default;
|
||||||
|
|
||||||
constexpr Vector2(const Type& x, const Type& y) : x(x), y(y) {}
|
constexpr Vector2(const Type& x, const Type& y) : x(x), y(y)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// Equality operators
|
// Equality operators
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@@ -145,23 +153,12 @@ namespace omath
|
|||||||
|
|
||||||
constexpr Vector2& Abs()
|
constexpr Vector2& Abs()
|
||||||
{
|
{
|
||||||
//FIXME: Replace with std::abs, if it will become constexprable
|
// FIXME: Replace with std::abs, if it will become constexprable
|
||||||
x = x < 0 ? -x : x;
|
x = x < 0 ? -x : x;
|
||||||
y = y < 0 ? -y : y;
|
y = y < 0 ? -y : y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class type>
|
|
||||||
[[nodiscard]] constexpr const type& As() const
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<const type*>(this);
|
|
||||||
}
|
|
||||||
template<class type>
|
|
||||||
[[nodiscard]] constexpr type& As()
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<type*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr Vector2 operator-() const
|
[[nodiscard]] constexpr Vector2 operator-() const
|
||||||
{
|
{
|
||||||
return {-x, -y};
|
return {-x, -y};
|
||||||
@@ -188,7 +185,7 @@ namespace omath
|
|||||||
return {x / fl, y / fl};
|
return {x / fl, y / fl};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sum of elements
|
// Sum of elements
|
||||||
[[nodiscard]] constexpr Type Sum() const
|
[[nodiscard]] constexpr Type Sum() const
|
||||||
{
|
{
|
||||||
return x + y;
|
return x + y;
|
||||||
@@ -199,5 +196,13 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return std::make_tuple(x, y);
|
return std::make_tuple(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
|
[[nodiscard]]
|
||||||
|
ImVec2 ToImVec2() const
|
||||||
|
{
|
||||||
|
return {static_cast<float>(this->x), static_cast<float>(this->y)};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
} // namespace omath
|
||||||
|
|||||||
@@ -4,13 +4,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Vector2.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
|
||||||
#include "omath/Vector2.hpp"
|
|
||||||
#include "omath/Angle.hpp"
|
|
||||||
#include <expected>
|
#include <expected>
|
||||||
#include <immintrin.h>
|
#include <functional>
|
||||||
|
#include "omath/Angle.hpp"
|
||||||
|
#include "omath/Vector2.hpp"
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <omath/Vector3.hpp>
|
#include <omath/Vector3.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
template <class Type>
|
template <class Type>
|
||||||
@@ -154,5 +155,19 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return Vector3<Type>::Sum() + w;
|
return Vector3<Type>::Sum() + w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
|
[[nodiscard]]
|
||||||
|
ImVec4 ToImVec4() const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
{
|
||||||
|
static_cast<float>(this->x),
|
||||||
|
static_cast<float>(this->y),
|
||||||
|
static_cast<float>(this->z),
|
||||||
|
static_cast<float>(w),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user