728x90
GameObject를 이제 혼자서는 못그리게하겠다.
class Actor와 함께.
기존 클래스에 새로 추가되는 것들만
class Actor : public GameObject
{
private:
unordered_map<string, GameObject*> obList;
public:
Actor();
GameObject* Find(string name);
};
class GameObject
{
private:
class Actor* root;
GameObject* parent;
string name; // key 값
public:
void AddChild(GameObject* child);
}
Acotr::Actor()
{
root = this;
}
actor 라는애가 최상위 게임오브젝트 파일이다.
Find 함수 :
검색해서 있으면 반환해준다. ( 찾거나 못찾거나 ) 해싱이라 굉장히 빠르다.
AddChild 함수
Game Object는 무조건 하나 이상의 Actor를 가지고있다.
AddChild 할 때, 키가 겹치는지 안겹치는지 확인해야됨.
void GameObejct::AddChild(GameObject* child)
{
if(root->Find(child->name))
return;
root->obList[child->name] = child;
this->children.push_back(child);
child->parent = this; // 자식의 부모는 나
child->root = root; // 자식의 루트는 나의 루트
}
찾았다면 (중복 된다면) 그냥 리턴 , 아니라면 추가해준다.
키 값이 중요해진다.
//생성함수
static GameObject* Create(string name);
protected:
GameObject();
앞으로는 함부로 생성하지 못하게 기본 생성자를 protected 으로 감춰준다. ( 자식은 접근가능 )
기본생성자 막은이유 : 무조건 동적할당으로만 생성할 수 있게 만들기 위해서
Sun = Actor::Create();
식으로만 호출 가능하게 끔.
이러면 장점
Sun->Find("SunBone2")->rotation.y += 60.0f * TORADIAN * DELTA;
훨씬 빠르게 검색해서 접근이 가능하다.
ImGui 를 건드려보자
bool GameObject::RenderImGui()
{
ImGui::SliderFloat3("position", (float*)&position, -30.0f, 30.0f);
ImGui::SliderFloat3("rotation", (float*)&rotation, 0.0f, PI * 2.0f);
ImGui::SliderFloat3("scale", (float*)&scale, 0.0f, 100.0f);
return false;
}
Main.cpp - Update();
ImGui::Begin("Hierirchy");
Sun->RenderImGui();
ImGui::End();
Begin 과 End 사이에 창이 있으면 새로운 창을 만들어 구분 할 수 있다.
bool GameObject::RenderImGui()
{
if(ImGui::TreeNode(name.c_str())
{
ImGui::SliderFloat3("position", (float*)&position, -30.0f, 30.0f);
ImGui::SliderFloat3("rotation", (float*)&rotation, 0.0f, PI * 2.0f);
ImGui::SliderFloat3("scale", (float*)&scale, 0.0f, 100.0f);
for(int i = 0 ; i < children.size() ; i++)
{
children[i]->RenderImGui();
}
ImGui::TreePop();
}
return false;
}
728x90
'잠시 정리 > 수업 정리' 카테고리의 다른 글
22 . 07 . 05 수업정리 (Imgui, XML) (0) | 2022.07.05 |
---|---|
22. 06. 30 수업정리( 리소스 매니져 + IMGUI) (0) | 2022.06.30 |
22.06.29 수업정리 ( 구 + 색공간 + 스마트포인터) (0) | 2022.06.29 |
22-06-27 수업정리 (0) | 2022.06.27 |
22. 06. 24 수업정리 (0) | 2022.06.24 |