-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCollider.h
More file actions
112 lines (84 loc) · 1.78 KB
/
Collider.h
File metadata and controls
112 lines (84 loc) · 1.78 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef _COLLIDER_H_
#define _COLLIDER_H_
#include <glm/glm.hpp>
#include <memory>
class Collider
{
public:
enum class ColliderTypes
{
POINT = 0,
SPHERE,
AABB,
OBB,
PLANE
};
Collider() = delete;
Collider(ColliderTypes type);
~Collider();
virtual bool TestCollision(Collider* other) = 0;
// getters
__forceinline ColliderTypes getColliderTypes() { return m_type; };
private:
ColliderTypes m_type;
};
/*
* Performance issue: Extra allocation needed
*/
class PointCollider final : public Collider
{
public:
PointCollider(glm::vec3 pos);
~PointCollider();
virtual bool TestCollision(Collider* other);
glm::vec3 m_position;
};
class SphereCollider final : public Collider
{
public:
SphereCollider() = delete;
SphereCollider(glm::vec3 center, float radius);
~SphereCollider();
virtual bool TestCollision(Collider* other);
glm::vec3 m_center;
float m_radius;
};
class AABB final : public Collider
{
public:
AABB() = delete;
AABB(glm::vec3 min, glm::vec3 max);
~AABB();
virtual bool TestCollision(Collider* other);
//getters
inline glm::vec3 getCenter() { return (m_max + m_min) * 0.5f; };
inline glm::vec3 getExtends() { return (m_max - m_min) * 0.5f; };
glm::vec3 m_min;
glm::vec3 m_max;
};
class OBB final : public Collider
{
public:
OBB() = delete;
OBB(glm::vec3 center,
glm::vec3 local_x_axis,
glm::vec3 local_y_axis,
glm::vec3 local_z_axis,
glm::vec3 extend);
~OBB();
virtual bool TestCollision(Collider* other);
glm::vec3 m_center;
glm::vec3 m_local_axis[3];
glm::vec3 m_extend;
};
class PlaneCollider final : public Collider
{
public:
PlaneCollider() = delete;
PlaneCollider(glm::vec3 plane_normal, float distance_from_orgin);
~PlaneCollider();
virtual bool TestCollision(Collider* other);
glm::vec3 m_normal;
float m_d;
};
#endif