-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlueOnGround.cpp
92 lines (74 loc) · 2.01 KB
/
GlueOnGround.cpp
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
#include "GlueOnGround.h"
GlueOnGround::GlueOnGround() {
translate = new glm::vec2(0.f, 0.f);
translate3D = new glm::vec3(0.f, 0.f, 0.f);
rotation = glm::mat4(1);
collider_ = new ColliderCircle(glm::vec2(0, 0), 5, false);
collider_->collider_is_trigger = true;
}
GlueOnGround::~GlueOnGround() {
delete collider_;
delete translate;
delete translate3D;
}
void GlueOnGround::FixedUpdate()
{
collider_->center = *translate;
if (gluedPlayer != nullptr) {
const auto delta = static_cast<float>(GameManager::GetFixedDeltaTime());
glueTime += delta;
}
if (glueTime >= maxGlueTime) {
gluedPlayer->isGlued = false;
GameManager::RemoveEntities({ this });
}
}
void GlueOnGround::OnTrigger(PhysicsObject *object) {
if (auto player = dynamic_cast<Player*>(object)) {
if (ownerOfGlue == player || gluedPlayer !=nullptr)
return;
else {
gluedPlayer = player;
player->isGlued = true;
glueTime = 0;
}
}
}
glm::mat4 GlueOnGround::GetParentTransform()
{
return GetTranslation() * rotation;
}
ModelEnum GlueOnGround::GetModelEnum() { return model; }
AniMode GlueOnGround::GetAniMode() { return modelAnim; }
std::vector<Collider*> GlueOnGround::GetColliders()
{
return { collider_ };
}
glm::vec2* GlueOnGround::GetWorldPosition()
{
return translate;
}
glm::vec3 GlueOnGround::GetPosition() const
{
return glm::vec3((*translate3D)[0], (*translate3D)[1], -(*translate3D)[2]);
}
void GlueOnGround::SetPosition(glm::vec3 position)
{
*translate = glm::vec2(position[0], -position[2]);
*translate3D = glm::vec3(position[0], position[1], -position[2]);
}
void GlueOnGround::SetRotation(glm::mat4 rotation)
{
this->rotation = rotation;
}
glm::mat4 GlueOnGround::GetTranslation() {
return glm::translate(glm::vec3((*translate3D)[0], (*translate3D)[1], -(*translate3D)[2]));
}
glm::mat4 GlueOnGround::GetRotation() const
{
return rotation;
}
glm::mat4 GlueOnGround::GetTransformation() {
const glm::mat4 trans = glm::translate(glm::vec3((*translate3D)[0], (*translate3D)[1], -(*translate3D)[2])) * rotation;
return trans;
}