diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 8307a7f..1170c0e 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -39,7 +39,7 @@ add_executable (xna WIN32 "content/manager.cpp" "content/reader.cpp" "csharp/binary.cpp" -"content/decstream.cpp" "content/lzx/decoder.cpp" "content/lzx/decoderstream.cpp" "content/typereadermanager.cpp" "csharp/object.cpp" "csharp/type.cpp" "platform/init-dx.cpp" "game/servicecontainer.cpp") +"content/decstream.cpp" "content/lzx/decoder.cpp" "content/lzx/decoderstream.cpp" "content/typereadermanager.cpp" "csharp/object.cpp" "csharp/type.cpp" "platform/init-dx.cpp" "game/servicecontainer.cpp" "common/color.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET xna PROPERTY CXX_STANDARD 20) diff --git a/framework/common/color.cpp b/framework/common/color.cpp new file mode 100644 index 0000000..c25e283 --- /dev/null +++ b/framework/common/color.cpp @@ -0,0 +1,5 @@ +#include "color.hpp" + +namespace xna { + +} \ No newline at end of file diff --git a/framework/common/math.hpp b/framework/common/math.hpp index a417d1f..452d28d 100644 --- a/framework/common/math.hpp +++ b/framework/common/math.hpp @@ -2,6 +2,7 @@ #define XNA_COMMON_MATH_HPP #include +#include namespace xna { struct MathHelper { @@ -9,9 +10,49 @@ namespace xna { static constexpr double PI = 3.1415926535897931; static constexpr double TAU = 6.2831853071795862; static constexpr double EPSILON = std::numeric_limits::epsilon(); - }; - using Math = MathHelper; + static constexpr float ToRadians(float degrees) { return degrees * (static_cast(PI) / 180.0f); } + static constexpr float ToDegrees(float radians) { return radians * 57.2957764F; } + static float Distance(float value1, float value2) { return std::abs(value1 - value2); } + static float Min(float value1, float value2) { return (std::min)(value1, value2); } + static float Max(float value1, float value2) { return (std::max)(value1, value2); } + + static constexpr float Clamp(float value, float min, float max) { + value = value > max ? max : value; + value = value < min ? min : value; + return value; + } + + static constexpr float Lerp(float value1, float value2, float amount) { + return value1 + (value2 - value1) * amount; + } + + static constexpr float Barycentric(float value1, float value2, float value3, float amount1, float amount2) { + return value1 + amount1 * (value2 - value1) + amount2 * (value3 - value1); + } + + static constexpr float SmoothStep(float value1, float value2, float amount) { + const auto num = Clamp(amount, 0.0f, 1.0f); + return Lerp(value1, value2, (num * num * (3.0F - 2.0F * num))); + } + + static float CatmullRom(float value1, float value2, float value3, float value4, float amount) { + const auto num1 = amount * amount; + const auto num2 = amount * num1; + return (0.5F * (2.0F * value2 + (-value1 + value3) * amount + (2.0F * value1 - 5.0F * value2 + 4.0F * value3 - value4) * num1 + (-value1 + 3.0F * value2 - 3.0F * value3 + value4) * num2)); + } + + static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount) { + const auto num1 = amount; + const auto num2 = num1 * num1; + const auto num3 = num1 * num2; + const auto num4 = (2.0F * num3 - 3.0F * num2 + 1.0F); + const auto num5 = (-2.0F * num3 + 3.0F * num2); + const auto num6 = num3 - 2.0f * num2 + num1; + const auto num7 = num3 - num2; + return value1 * num4 + value2 * num5 + tangent1 * num6 + tangent2 * num7; + } + }; } #endif \ No newline at end of file diff --git a/framework/common/matrix.cpp b/framework/common/matrix.cpp index b2bcf1f..bcd2621 100644 --- a/framework/common/matrix.cpp +++ b/framework/common/matrix.cpp @@ -212,7 +212,7 @@ namespace xna { } Matrix Matrix::CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance) { - if (fieldOfView <= 0.0 || fieldOfView >= Math::PI || nearPlaneDistance <= 0.0 || farPlaneDistance <= 0.0 || nearPlaneDistance >= farPlaneDistance) { + if (fieldOfView <= 0.0 || fieldOfView >= MathHelper::PI || nearPlaneDistance <= 0.0 || farPlaneDistance <= 0.0 || nearPlaneDistance >= farPlaneDistance) { return Matrix(); }