Add triangle SAT intersection

This commit is contained in:
Mishura
2024-05-08 09:23:20 -04:00
parent ac4538bba5
commit 4830015060
6 changed files with 284 additions and 2 deletions

View File

@@ -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;