-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColliderTester.h
More file actions
71 lines (53 loc) · 1.85 KB
/
ColliderTester.h
File metadata and controls
71 lines (53 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include "IntersectData.h"
#include "Colliders.h"
#include <algorithm>
#include <cmath>
#include <array>
#include<limits>
static bool CMP(const float x, const float y)
{
return (std::fabs((x)-(y) )<= std::numeric_limits<float>::epsilon() * std::fmax(1.0f, fmax(fabs(x), fabs(y))));
}
typedef struct SAT
{
const glm::vec3& getMin(OBB obb);
const glm::vec3& getMax(OBB obb);
Interval getInterval(OBB obb, const glm::vec3 axis);
bool overlapOnAxis(OBB obb1, OBB obb2, const glm::vec3 axis);
} SAT;
enum class TYPE
{
SPHERE,
OBB,
};
class ColliderTester
{
public:
ColliderTester() { };
ColliderTester(const TYPE& type) : m_type(type) {}
inline void setType(TYPE type) { m_type = type; }
inline const TYPE& getType() const { return m_type; }
// OBBs with :
//IntersectData intersect(OBB obb1, OBB obb2);
IntersectData intersect(OBB obb, Plane plane);
// BoundingSpheres with :
IntersectData intersect(BoundingSphere sphere1, BoundingSphere sphere2);
IntersectData intersect(BoundingSphere sphere, OBB obb);
IntersectData intersect(BoundingSphere sphere, Plane plane);
IntersectData FindCollisionFeatures(OBB A, OBB B);
static inline Plane getPlaneCollider() { return Plane(); }
//private:
glm::vec3 closestPoint(OBB obb, const glm::vec3& point);
bool PointInOBB(glm::vec3 point, OBB obb);
glm::vec3 closestPoint(BoundingSphere sphere, const glm::vec3& point);
Interval getInterval(OBB obb, const glm::vec3 axis);
std::vector<glm::vec3> getVertices(OBB obb);
private:
TYPE m_type;
std::vector<Line> getEdges(OBB obb);
std::vector<Plane> getPlanes(OBB obb);
bool clipToPlane(Plane plane, const Line& line, glm::vec3* outPoint);
std::vector<glm::vec3> clipEdgesToOBB(const std::vector<Line>& edges, OBB obb);
float penetrationDepth(OBB o1, OBB o2, const glm::vec3& axis, bool* outShouldFlip);
};