-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCapsuleColliderComponent.h
More file actions
189 lines (169 loc) · 4.04 KB
/
Copy pathCapsuleColliderComponent.h
File metadata and controls
189 lines (169 loc) · 4.04 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#pragma once
#include "Component.h"
#include "SceneManager.h"
#include "Scene.h"
#include "../physics/PhysicsCommon.h"
#include "../Physics/ICollider.h"
class CapsuleColliderComponent : public meta::identity<CapsuleColliderComponent, Component>, public ICollider
{
public:
static consteval auto reflect()
{
return meta::schema<Self>(
meta::field<&Self::m_radius>,
meta::field<&Self::m_posOffset>,
meta::field<&Self::m_rotOffset>,
meta::field<&Self::m_height>,
meta::field<&Self::staticFriction>,
meta::field<&Self::dynamicFriction>,
meta::field<&Self::restitution>,
meta::field<&Self::density>);
}
public:
CapsuleColliderComponent()
{
m_type = EColliderType::COLLISION;
m_Info.radius = 1.0f;
m_Info.height = 1.0f;
}
virtual ~CapsuleColliderComponent() = default;
void OnInitialized() override
{
auto scene = GetOwner()->m_ownerScene;
if (scene)
{
scene->CollectColliderComponent(this);
}
}
void OnUninitializing() override
{
auto scene = GetOwner()->m_ownerScene;
if (scene)
{
scene->UnCollectColliderComponent(this);
}
}
float m_radius{ 1.0f };
math::vector3 m_posOffset{ 0.0f, 0.0f, 0.0f };
math::quaternion m_rotOffset{ 0.0f, 0.0f, 0.0f, 1.0f };
float m_height{ 1.0f };
float staticFriction = 0.5f; //정적 물체 마찰 계수
float dynamicFriction = 0.4f; //동적 물체 마찰 계수
float restitution = 0.3f; //탄성 계수
float density = 10.0f; //밀도
private:
EColliderType m_type;
CapsuleColliderInfo m_Info;
int m_collsionCount{ 0 };
public:
//info
float GetRadius()
{
if (m_radius != 0.0f)
{
m_Info.radius = m_radius;
}
return m_Info.radius;
}
void SetRadius(float radius)
{
m_Info.radius = radius;
m_radius = m_Info.radius;
}
float GetHeight()
{
if (m_height != 0.0f)
{
m_Info.height = m_height;
}
return m_Info.height;
}
void SetHeight(float height)
{
m_Info.height = height;
m_height = m_Info.height;
}
EColliderType GetColliderType() const
{
return m_type;
}
void SetColliderType(EColliderType type)
{
m_type = type;
}
CapsuleColliderInfo GetCapsuleInfo()
{
if (m_radius != 0.0f)
{
m_Info.radius = m_radius;
}
if (m_height != 0.0f)
{
m_Info.height = m_height;
}
// 임시 콜리젼 레이어
m_Info.colliderInfo.layerNumber = GetOwner()->m_collisionType;
m_Info.colliderInfo.staticFriction = staticFriction;
m_Info.colliderInfo.dynamicFriction = dynamicFriction;
m_Info.colliderInfo.restitution = restitution;
m_Info.colliderInfo.density = density;
return m_Info;
}
void SetCapsuleInfoMation(const CapsuleColliderInfo& info)
{
m_Info = info;
m_radius = m_Info.radius;
m_height = m_Info.height;
}
float GetStaticFriction() const
{
return m_Info.colliderInfo.staticFriction;
}
void SetStaticFriction(float staticFriction)
{
m_Info.colliderInfo.staticFriction = staticFriction;
}
float GetDynamicFriction() const
{
return m_Info.colliderInfo.dynamicFriction;
}
void SetDynamicFriction(float dynamicFriction)
{
m_Info.colliderInfo.dynamicFriction = dynamicFriction;
}
float GetRestitution() const
{
return m_Info.colliderInfo.restitution;
}
void SetRestitution(float restitution)
{
m_Info.colliderInfo.restitution = restitution;
}
float GetDensity() const
{
return m_Info.colliderInfo.density;
}
void SetDensity(float density)
{
m_Info.colliderInfo.density = density;
}
void SetPositionOffset(math::vector3 pos) override {
m_posOffset = pos;
}
math::vector3 GetPositionOffset() override {
return m_posOffset;
}
void SetRotationOffset(math::quaternion rotation) override {
m_rotOffset = rotation;
}
math::quaternion GetRotationOffset() override {
return m_rotOffset;
}
//콜리전 이벤트
void OnTriggerEnter(ICollider* other) override;
void OnTriggerStay(ICollider* other) override;
void OnTriggerExit(ICollider* other) override;
void OnCollisionEnter(ICollider* other) override;
void OnCollisionStay(ICollider* other) override;
void OnCollisionExit(ICollider* other) override;
};