mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Correções em collision.hpp
This commit is contained in:
parent
bd65e9fb55
commit
e539dde3bd
@ -1,12 +1,20 @@
|
||||
#ifndef XNA_COMMON_COLLISION_HPP
|
||||
#define XNA_COMMON_COLLISION_HPP
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "math.hpp"
|
||||
#include "numerics.hpp"
|
||||
#include <optional>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
|
||||
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<float>;
|
||||
using listff = std::vector<std::vector<float>>;
|
||||
|
||||
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<Int>{
|
||||
inline static auto BitsToIndices = std::vector<int32_t>{
|
||||
0, 1, 2, 17, 3, 25, 26, 209, 4, 33, 34, 273, 35, 281, 282, 2257
|
||||
};
|
||||
|
||||
using listv3 = std::vector<Vector3>;
|
||||
using listv3v3 = std::vector<std::vector<Vector3>>;
|
||||
using listf = std::vector<float>;
|
||||
using listff = std::vector<std::vector<float>>;
|
||||
|
||||
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<float>::min)();
|
||||
static constexpr float FLOAT_MAX_VALUE = (std::numeric_limits<float>::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<float>::min)();
|
||||
static constexpr float FLOAT_MAX_VALUE = (std::numeric_limits<float>::max)();
|
||||
};
|
||||
|
||||
//Defines a sphere.
|
||||
@ -556,8 +567,8 @@ namespace xna {
|
||||
}
|
||||
|
||||
constexpr BoundingBox BoundingBox::CreateFromPoints(std::vector<Vector3> 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];
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
namespace xna {
|
||||
//Contains commonly used precalculated values.
|
||||
|
@ -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<float> 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)
|
||||
{
|
||||
|
@ -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];
|
||||
|
Loading…
x
Reference in New Issue
Block a user