응애맘마조
ImGui에서 노드 추가 및 삭제와 탐색 본문
이진탐색트리에서 사용했던 노드 추가 및 삭제와 탐색을 ImGui에서 하는 것이 과제였습니다.
#include "framework.h"
bool GameObject::RenderHierarchy()
{
ImGui::PushID(this);
if (ImGui::TreeNode(name.c_str()))
{
if (ImGui::IsItemToggledOpen() or
ImGui::IsItemClicked())
{
GUI->target = this;
}
if (ImGui::Button("addChild"))
{
ImGui::OpenPopup("childName");
}
if (ImGui::BeginPopup("childName"))
{
static char childName[32] = "None";
ImGui::InputText("childName", childName, 32);
if (ImGui::Button("G.O"))
{
AddChild(GameObject::Create(childName));
}
ImGui::SameLine();
if (ImGui::Button("Actor"))
{
AddChild(Actor::Create(childName));
}
ImGui::EndPopup();
}
ImGui::SameLine();
if (ImGui::Button("delete"))
{
if (parent == nullptr)
ImGui::OpenPopup("SearchDeleteName");
else
ImGui::OpenPopup("DeleteChild");
}
if (ImGui::BeginPopup("SearchDeleteName"))
{
static char deleteName[32] = "None";
ImGui::InputText("deleteName", deleteName, 32);
if (ImGui::Button("DeleteAll"))
{
root->DeleteAllObject(deleteName);
ImGui::EndPopup();
ImGui::TreePop();
ImGui::PopID();
GUI->target = nullptr;
return true;
}
ImGui::SameLine();
if (ImGui::Button("Delete2"))
{
root->DeleteObject(deleteName);
ImGui::EndPopup();
ImGui::TreePop();
ImGui::PopID();
GUI->target = nullptr;
return true;
}
ImGui::EndPopup();
}
if (ImGui::BeginPopup("DeleteChild"))
{
if (ImGui::Button("DeleteAll"))
{
//부모한테 접근
if (parent)
{
root->DeleteAllObject(name);
ImGui::EndPopup();
ImGui::TreePop();
ImGui::PopID();
GUI->target = nullptr;
return true;
}
}
ImGui::SameLine();
if (ImGui::Button("Delete2"))
{
//부모한테 접근
if (parent)
{
root->DeleteObject(name);
ImGui::EndPopup();
ImGui::TreePop();
ImGui::PopID();
GUI->target = nullptr;
return true;
}
}
ImGui::EndPopup();
}
// l->r
for (auto it = children.begin(); it != children.end(); it++)
{
if (it->second->RenderHierarchy())
{
ImGui::TreePop();
ImGui::PopID();
GUI->target = nullptr;
return true;
}
}
ImGui::TreePop();
}
ImGui::PopID();
return false;
}
void Transform::RenderDetail()
{
ImGui::Checkbox("WorldPos", &worldPos);
if (worldPos)
{
//get
Vector3 wol = GetWorldPos();
if (ImGui::DragFloat3("WorldPos", (float*)&wol, 0.05f))
//set
SetWorldPos(wol);
}
else
{
Vector3 loc = GetLocalPos();
if (ImGui::DragFloat3("LocalPos", (float*)&loc, 0.05f))
SetLocalPos(loc);
}
ImGui::SliderAngle("rotationX", &rotation.x);
ImGui::SliderAngle("rotationY", &rotation.y);
ImGui::SliderAngle("rotationZ", &rotation.z);
ImGui::DragFloat3("scale", (float*)&scale, 0.05f);
}
void GameObject::RenderDetail()
{
ImGui::Text(name.c_str());
ImGui::Checkbox("visible", &visible);
if (ImGui::BeginTabBar("MyTabBar"))
{
if (ImGui::BeginTabItem("Transform"))
{
Transform::RenderDetail();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
void Actor::RenderDetail()
{
GameObject::RenderDetail();
if (ImGui::BeginTabBar("MyTabBar2"))
{
if (ImGui::BeginTabItem("Actor"))
{
if (GUI->FileImGui("Save", "Save Actor",
".xml", "../Contents/GameObject"))
{
string path = ImGuiFileDialog::Instance()->GetCurrentPath();
Util::Replace(&path, "\\", "/");
if (path.find("/GameObject/") != -1)
{
size_t tok = path.find("/GameObject/") + 12;
path = path.substr(tok, path.length())
+ "/" + ImGuiFileDialog::Instance()->GetCurrentFileName();
}
else
{
path = ImGuiFileDialog::Instance()->GetCurrentFileName();
}
SaveFile(path);
}
ImGui::SameLine();
if (GUI->FileImGui("Load", "Load Actor",
".xml", "../Contents/GameObject"))
{
string path = ImGuiFileDialog::Instance()->GetCurrentPath();
Util::Replace(&path, "\\", "/");
if (path.find("/GameObject/") != -1)
{
size_t tok = path.find("/GameObject/") + 12;
path = path.substr(tok, path.length())
+ "/" + ImGuiFileDialog::Instance()->GetCurrentFileName();
}
else
{
path = ImGuiFileDialog::Instance()->GetCurrentFileName();
}
LoadFile(path);
}
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
void Camera::RenderDetail()
{
Actor::RenderDetail();
if (ImGui::BeginTabBar("MyTabBar3"))
{
if (ImGui::BeginTabItem("Camera"))
{
ImGui::Checkbox("ortho", &ortho);
ImGui::SliderAngle("fov", &fov,0,180.0f);
ImGui::DragFloat("nearZ", &nearZ, 0.05f,0.00001f);
ImGui::DragFloat("farZ", &farZ, 0.05f, 0.00001f,1.0f);
ImGui::DragFloat("width", &width, 0.05f,1.0f);
ImGui::DragFloat("height", &height, 0.05f, 1.0f);
ImGui::DragFloat("x", &viewport.x, 0.05f, 0.0f);
ImGui::DragFloat("y", &viewport.y, 0.05f, 0.0f);
ImGui::DragFloat("w", &viewport.width, 0.05f, 1.0f);
ImGui::DragFloat("h", &viewport.height, 0.05f, 1.0f);
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
코드입니다.
읽어주셔서 감사합니다.
'공부 > 3D과제' 카테고리의 다른 글
큐브 그리기 (0) | 2023.05.08 |
---|---|
동적할당 및 해제/댕글링 포인터/가비지 컬렉션/스마트 포인터/메모리 단편화/메모리 풀 (1) | 2023.05.04 |
전위, 중위, 후위 노드 추가 탐색 및 삭제 (0) | 2023.05.01 |
이진탐색트리, DFS, BFS, (전위, 중위, 후위) 순회 (0) | 2023.04.27 |
진짜 사람 찾기 (0) | 2023.04.27 |
Comments