1
0
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:
Danilo 2024-11-10 21:44:36 -03:00
parent e539dde3bd
commit 488e0a513e
2 changed files with 72 additions and 63 deletions

View File

@ -146,8 +146,8 @@ namespace xna {
//Defines a frustum and helps determine whether forms intersect with it.
struct BoundingFrustum {
inline static constexpr int CornerCount = 8;
inline static constexpr int PlaneCount = 6;
static constexpr int CornerCount = 8;
static constexpr int PlaneCount = 6;
constexpr BoundingFrustum() = default;
constexpr BoundingFrustum(Matrix const& matrix) {
@ -205,10 +205,10 @@ namespace xna {
constexpr void SupportMapping(Vector3 const& v, Vector3& result) const;
public:
std::vector<Vector3> corners{ 8 };
Vector3 corners[8];
Plane planes[6];
private:
std::vector<Plane> planes{ 6 };
Matrix matrix{ Matrix::Identity() };
Gjk gjk{};
@ -247,7 +247,11 @@ namespace xna {
//Creates the smallest BoundingBox that will contain the specified BoundingSphere.
static constexpr BoundingBox CreateFromSphere(BoundingSphere const& sphere);
//Creates the smallest BoundingBox that will contain a group of points.
static constexpr BoundingBox CreateFromPoints(std::vector<Vector3> const& points);
static constexpr BoundingBox CreateFromPoints(std::vector<Vector3> const& points) {
return CreateFromPoints(points.data(), points.size());
}
//Creates the smallest BoundingBox that will contain a group of points.
static constexpr BoundingBox CreateFromPoints(Vector3 const* points, size_t size);
//Checks whether the current BoundingBox intersects with another bounding volume.
constexpr bool Intersects(BoundingBox const& box) const;
@ -296,7 +300,12 @@ namespace xna {
//Creates the smallest BoundingSphere that can contain a specified BoundingBox.
static BoundingSphere CreateFromBoundingBox(BoundingBox const& box);
//Creates a BoundingSphere that can contain a specified list of points.
static BoundingSphere CreateFromPoints(std::vector<Vector3> const& points);
static BoundingSphere CreateFromPoints(std::vector<Vector3> const& points) {
return CreateFromPoints(points.data(), points.size());
}
//Creates a BoundingSphere that can contain a specified list of points.
static BoundingSphere CreateFromPoints(Vector3 const* points, size_t size);
//Creates the smallest BoundingSphere that can contain a specified BoundingFrustum.
static BoundingSphere CreateFromFrustum(BoundingFrustum const& points);
@ -566,11 +575,11 @@ namespace xna {
return fromSphere;
}
constexpr BoundingBox BoundingBox::CreateFromPoints(std::vector<Vector3> const& points) {
constexpr BoundingBox BoundingBox::CreateFromPoints(Vector3 const* points, size_t size) {
Vector3 result1 = Vector3(FLOAT_MAX_VALUE);
Vector3 result2 = Vector3(FLOAT_MIN_VALUE);
for (size_t i = 0; i < points.size(); ++i) {
for (size_t i = 0; i < size; ++i) {
const auto& point = points[i];
result1 = Vector3::Min(result1, point);
result2 = Vector3::Max(result2, point);

View File

@ -104,7 +104,7 @@ namespace xna {
auto num1 = FLOAT_MIN_VALUE;
auto num2 = FLOAT_MAX_VALUE;
for (size_t i = 0; i < planes.size(); ++i) {
for (size_t i = 0; i < PlaneCount; ++i) {
const auto& plane = planes[i];
Vector3 normal = plane.Normal;
@ -242,7 +242,7 @@ namespace xna {
if (Intersects(frustum)) {
containmentType = ContainmentType::Contains;
for (size_t index = 0; index < corners.size(); ++index) {
for (size_t index = 0; index < CornerCount; ++index) {
if (Contains(frustum.corners[index]) == ContainmentType::Disjoint)
{
containmentType = ContainmentType::Intersects;
@ -345,10 +345,10 @@ namespace xna {
}
BoundingSphere BoundingSphere::CreateFromFrustum(BoundingFrustum const& frustum) {
return BoundingSphere::CreateFromPoints(frustum.corners);
return BoundingSphere::CreateFromPoints(frustum.corners, frustum.CornerCount);
}
BoundingSphere BoundingSphere::CreateFromPoints(std::vector<Vector3> const& points) {
BoundingSphere BoundingSphere::CreateFromPoints(Vector3 const* points, size_t size) {
Vector3 current;
auto vector3_1 = current = points[0];
auto vector3_2 = current;
@ -357,7 +357,7 @@ namespace xna {
auto vector3_5 = current;
auto vector3_6 = current;
for (size_t i = 0; i < points.size(); ++i) {
for (size_t i = 0; i < size; ++i) {
const auto& point = points[i];
if (point.X < vector3_6.X)
@ -404,7 +404,7 @@ namespace xna {
num1 = result3 * 0.5f;
}
for (size_t i = 0; i < points.size(); ++i) {
for (size_t i = 0; i < size; ++i) {
const auto& point = points[i];
Vector3 vector3_7;