-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransform.cpp
More file actions
116 lines (104 loc) · 2.18 KB
/
Transform.cpp
File metadata and controls
116 lines (104 loc) · 2.18 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
#include "stdafx.h"
Transform::Transform()
{
position.x = WINSIZEX / 2;
position.y = WINSIZEY / 2;
size.width = 100;
size.height = 100;
siblingIdx = -1;
}
Transform::~Transform()
{
}
bool Transform::Move(float x, float y)
{
int childCount = GetChildCount();
if (CheckCollision(position.x + x, position.y + y) == true) {
return false;
}
position.x += x;
position.y += y;
for (int i = 0; i < childCount; i++) {
child[i]->MoveX(x);
child[i]->MoveY(y);
}
return true;
}
bool Transform::MoveX(float x)
{
int childCount = GetChildCount();
if (CheckCollision(position.x + x, position.y) == true) {
return false;
}
position.x += x;
for (int i = 0; i < childCount; i++) {
child[i]->MoveX(x);
}
return true;
}
bool Transform::MoveY(float y)
{
int childCount = GetChildCount();
if (CheckCollision(position.x, position.y + y) == true) {
return false;
}
position.y += y;
for (int i = 0; i < childCount; i++) {
child[i]->MoveY(y);
}
return true;
}
bool Transform::CheckCollision(float tempX, float tempY)
{
BoxCollider* collider;
collider = gameObject->GetComponent<BoxCollider>();
if (collider == nullptr) {
return false;
}
else {
return collider->CheckCollision(tempX, tempY);
}
return false;
}
Transform* Transform::GetChild(int i)
{
if (i >= GetChildCount()) {
return nullptr;
}
else {
return child[i];
}
}
void Transform::AddChild(GameObject* gameObject)
{
child.push_back(gameObject->transform);
gameObject->transform->parent = this;
gameObject->transform->siblingIdx = GetChildCount() - 1;
}
void Transform::AddChild(Transform* transform)
{
child.push_back(transform);
transform->parent = this;
transform->siblingIdx = GetChildCount() - 1;
}
void Transform::DetachChild(int idx)
{
if (idx > GetChildCount() - 1)
{
sprintf_s(error, "DetachChild오류 : idx가 옳지 않습니다", idx);
throw "자식삭제 idx가 옳지 않습니다";
return;
}
child[idx]->parent = nullptr;
child[idx]->siblingIdx = -1;
child.erase(child.begin() + idx);
}
void Transform::DetachParent()
{
if (parent == nullptr) {
sprintf_s(error, "DetachParent오류 : 부모 오브젝트가 존재하지 않습니다");
throw "부모 오브젝트가 존재하지 않습니다";
return;
}
parent->DetachChild(siblingIdx);
}