Add triangle SAT intersection
This commit is contained in:
@@ -27,5 +27,13 @@ namespace J3ML::Geometry
|
||||
// Methods required by Geometry types
|
||||
namespace J3ML::Geometry
|
||||
{
|
||||
// Represents a segment along an axis, with the axis as a unit
|
||||
struct Interval {
|
||||
float min;
|
||||
float max;
|
||||
|
||||
bool Intersects(const Interval& rhs) const;
|
||||
|
||||
bool operator==(const Interval& rhs) const = default;
|
||||
};
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "J3ML/LinearAlgebra/Vector3.h"
|
||||
#include <J3ML/Geometry/Common.h>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <cfloat>
|
||||
@@ -13,11 +14,18 @@ namespace J3ML::Geometry
|
||||
Vector3 V1;
|
||||
Vector3 V2;
|
||||
public:
|
||||
|
||||
float DistanceSq(const Vector3 &point) const;
|
||||
|
||||
/// Returns a new triangle, translated with a direction vector
|
||||
Triangle Translated(const Vector3& translation) const;
|
||||
/// Returns a new triangle, scaled from 3D factors
|
||||
Triangle Scaled(const Vector3& scaled) const;
|
||||
|
||||
bool Intersects(const AABB& aabb) const;
|
||||
bool Intersects(const Capsule& capsule) const;
|
||||
bool Intersects(const Triangle& rhs) const;
|
||||
friend bool Intersects(const Triangle& lhs, const Triangle &rhs);
|
||||
|
||||
AABB BoundingAABB() const;
|
||||
|
||||
/// Tests if the given object is fully contained inside this triangle.
|
||||
@@ -29,6 +37,8 @@ namespace J3ML::Geometry
|
||||
bool Contains(const LineSegment& lineSeg, float triangleThickness = 1e-3f) const;
|
||||
bool Contains(const Triangle& triangle, float triangleThickness = 1e-3f) const;
|
||||
|
||||
/// Project the triangle onto an axis, and returns the min and max value with the axis as a unit
|
||||
Interval ProjectionInterval(const Vector3& axis) const;
|
||||
void ProjectToAxis(const Vector3 &axis, float &dMin, float &dMax) const;
|
||||
|
||||
/// Quickly returns an arbitrary point inside this Triangle. Used in GJK intersection test.
|
||||
@@ -108,6 +118,8 @@ namespace J3ML::Geometry
|
||||
|
||||
Plane PlaneCW() const;
|
||||
|
||||
Vector3 FaceNormal() const;
|
||||
|
||||
Vector3 Vertex(int i) const;
|
||||
|
||||
LineSegment Edge(int i) const;
|
||||
|
Reference in New Issue
Block a user