diff --git a/includes/xna/common/collision.hpp b/includes/xna/common/collision.hpp index 1d49d7b..5d589bf 100644 --- a/includes/xna/common/collision.hpp +++ b/includes/xna/common/collision.hpp @@ -1,12 +1,20 @@ #ifndef XNA_COMMON_COLLISION_HPP #define XNA_COMMON_COLLISION_HPP -#include "../default.hpp" #include "math.hpp" #include "numerics.hpp" #include +#include +#include +#include namespace xna { + struct Plane; + struct BoundingFrustum; + struct BoundingBox; + struct BoundingSphere; + struct Ray; + class Gjk { public: constexpr Gjk() {} @@ -28,11 +36,11 @@ namespace xna { using listf = std::vector; using listff = std::vector>; - void UpdateDeterminant(Int xmIdx); - bool UpdateSimplex(Int newIndex); + void UpdateDeterminant(int32_t xmIdx); + bool UpdateSimplex(int32_t newIndex); Vector3 ComputeClosestPoint(); - constexpr bool IsSatisfiesRule(Int xBits, Int yBits) const { + constexpr bool IsSatisfiesRule(int32_t xBits, int32_t yBits) const { bool flag = true; for (auto bitsToIndex = Gjk::BitsToIndices[yBits]; bitsToIndex != 0; bitsToIndex >>= 3) { @@ -54,17 +62,12 @@ namespace xna { } private: - inline static auto BitsToIndices = std::vector{ + inline static auto BitsToIndices = std::vector{ 0, 1, 2, 17, 3, 25, 26, 209, 4, 33, 34, 273, 35, 281, 282, 2257 }; - using listv3 = std::vector; - using listv3v3 = std::vector>; - using listf = std::vector; - using listff = std::vector>; - Vector3 closestPoint{}; - Int simplexBits{ 0 }; + int32_t simplexBits{ 0 }; float maxLengthSq{ 0 }; listv3 y = listv3(4); listf yLengthSq = listf(4); @@ -212,6 +215,10 @@ namespace xna { private: static constexpr Ray ComputeIntersectionLine(Plane const& p1, Plane const& p2); static constexpr Vector3 ComputeIntersection(Plane const& plane, Ray const& ray); + + private: + static constexpr float FLOAT_MIN_VALUE = (std::numeric_limits::min)(); + static constexpr float FLOAT_MAX_VALUE = (std::numeric_limits::max)(); }; //Defines an axis-aligned box-shaped 3D volume. @@ -263,6 +270,10 @@ namespace xna { constexpr ContainmentType Contains(BoundingSphere const& sphere) const; constexpr void SupportMapping(Vector3 const& v, Vector3& result) const; + + private: + static constexpr float FLOAT_MIN_VALUE = (std::numeric_limits::min)(); + static constexpr float FLOAT_MAX_VALUE = (std::numeric_limits::max)(); }; //Defines a sphere. @@ -556,8 +567,8 @@ namespace xna { } constexpr BoundingBox BoundingBox::CreateFromPoints(std::vector const& points) { - Vector3 result1 = Vector3(FloatMaxValue); - Vector3 result2 = Vector3(FloatMinValue); + Vector3 result1 = Vector3(FLOAT_MAX_VALUE); + Vector3 result2 = Vector3(FLOAT_MIN_VALUE); for (size_t i = 0; i < points.size(); ++i) { const auto& point = points[i]; diff --git a/includes/xna/common/math.hpp b/includes/xna/common/math.hpp index 033f534..dfe5a34 100644 --- a/includes/xna/common/math.hpp +++ b/includes/xna/common/math.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace xna { //Contains commonly used precalculated values. diff --git a/sources/framework/common/collision.cpp b/sources/framework/common/collision.cpp index a1f1714..c774fe0 100644 --- a/sources/framework/common/collision.cpp +++ b/sources/framework/common/collision.cpp @@ -64,7 +64,7 @@ namespace xna { if (result1.LengthSquared() < 9.9999997473787516E-06) result1 = Vector3::Subtract(corners[0], box.Max); - auto num1 = FloatMaxValue; + auto num1 = FLOAT_MAX_VALUE; float num2 = 0; do { @@ -101,8 +101,8 @@ namespace xna { if (result1 == ContainmentType::Contains) return 0.0F; - auto num1 = FloatMinValue; - auto num2 = FloatMaxValue; + auto num1 = FLOAT_MIN_VALUE; + auto num2 = FLOAT_MAX_VALUE; for (size_t i = 0; i < planes.size(); ++i) { const auto& plane = planes[i]; @@ -153,7 +153,7 @@ namespace xna { if (result1.LengthSquared() < 9.9999997473787516E-06) result1 = Vector3::UnitX(); - auto num1 = FloatMaxValue; + auto num1 = FLOAT_MAX_VALUE; auto num2 = 0.0F; do @@ -199,7 +199,7 @@ namespace xna { if (result1.LengthSquared() < 9.9999997473787516E-06) result1 = Vector3::Subtract(corners[0], frustum.corners[1]); - float num1 = FloatMaxValue; + float num1 = FLOAT_MAX_VALUE; float num2 = 0; do @@ -255,7 +255,7 @@ namespace xna { std::optional BoundingBox::Intersects(Ray const& ray) const { float num1 = 0.0f; - float num2 = FloatMaxValue; + float num2 = FLOAT_MAX_VALUE; if (std::abs(ray.Direction.X) < 9.9999999747524271E-07) { diff --git a/sources/framework/common/gjk.cpp b/sources/framework/common/gjk.cpp index 8d602d6..e7d5a72 100644 --- a/sources/framework/common/gjk.cpp +++ b/sources/framework/common/gjk.cpp @@ -18,7 +18,7 @@ namespace xna { return zero / num1; } - bool Gjk::UpdateSimplex(Int newIndex) { + bool Gjk::UpdateSimplex(int32_t newIndex) { auto yBits = simplexBits | 1 << newIndex; auto xBits = 1 << newIndex; for (auto sb = simplexBits; sb != 0; --sb) @@ -43,7 +43,7 @@ namespace xna { return flag; } - void Gjk::UpdateDeterminant(Int xmIdx) { + void Gjk::UpdateDeterminant(int32_t xmIdx) { auto index1 = 1 << xmIdx; det[index1][xmIdx] = 1.0f; auto bitsToIndex = Gjk::BitsToIndices[simplexBits];