From c153c88032d7f5804955a97fe507bdef4570deb9 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Tue, 26 Mar 2024 13:01:33 +0100 Subject: [PATCH] Object inspector window --- enginecustom/Systemclass.cpp | 1 + enginecustom/applicationclass.h | 1 + enginecustom/imgui.ini | 6 +++++- enginecustom/imguiManager.cpp | 23 +++++++++++++++++++++++ enginecustom/imguiManager.h | 2 ++ enginecustom/object.cpp | 28 ++++++++++++++++++++++++++++ enginecustom/object.h | 8 ++++++++ 7 files changed, 68 insertions(+), 1 deletion(-) diff --git a/enginecustom/Systemclass.cpp b/enginecustom/Systemclass.cpp index 3e72119..755205b 100644 --- a/enginecustom/Systemclass.cpp +++ b/enginecustom/Systemclass.cpp @@ -164,6 +164,7 @@ bool SystemClass::Frame() m_imguiManager->WidgetButton(); m_imguiManager->WidgetFPS(); m_imguiManager->WidgetAddObject(m_Application); + m_imguiManager->WidgetObjectWindow(m_Application); ImGui::End(); diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 54e1f10..8f837f6 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -44,6 +44,7 @@ public: void AddCube(); int GetCubeCount() const { return m_cubes.size(); }; + std::vector GetCubes() const { return m_cubes; }; private: bool Render(float); diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index a626c36..deb9108 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -3,6 +3,10 @@ Pos=60,60 Size=400,400 [Window][Khaotic Engine] -Pos=54,81 +Pos=1068,19 Size=694,367 +[Window][Objects] +Pos=74,113 +Size=492,353 + diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index 710038c..ac2907b 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -1,5 +1,6 @@ #include "imguiManager.h" #include "applicationclass.h" +#include imguiManager::imguiManager() { @@ -75,3 +76,25 @@ void imguiManager::WidgetAddObject(ApplicationClass* app) ImGui::Text("Number of cubes: %d", app->GetCubeCount()); } } + +void imguiManager::WidgetObjectWindow(ApplicationClass* app) +{ + ImGui::Begin("Objects"); + int index = 0; + for (auto object : app->GetCubes()) + { + std::string headerName = "Object " + std::to_string(index); + if (ImGui::CollapsingHeader(headerName.c_str())) + { + XMVECTOR position = object->GetPosition(); + XMVECTOR rotation = object->GetRotation(); + XMVECTOR scale = object->GetScale(); + ImGui::Text("Position: %.2f %.2f %.2f", XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position)); + ImGui::Text("Rotation: %.2f %.2f %.2f", XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation)); + ImGui::Text("Scale: %.2f %.2f %.2f", XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale)); + } + index++; + } + + ImGui::End(); +} \ No newline at end of file diff --git a/enginecustom/imguiManager.h b/enginecustom/imguiManager.h index 9cb406f..4b83aa5 100644 --- a/enginecustom/imguiManager.h +++ b/enginecustom/imguiManager.h @@ -26,6 +26,8 @@ public: void WidgetFPS(); void WidgetAddObject(ApplicationClass* app); + void WidgetObjectWindow(ApplicationClass* app); + private: ImGuiIO* io; }; diff --git a/enginecustom/object.cpp b/enginecustom/object.cpp index 302642f..58108f9 100644 --- a/enginecustom/object.cpp +++ b/enginecustom/object.cpp @@ -61,4 +61,32 @@ XMMATRIX Object::GetSRMatrix() XMMATRIX Object::GetWorldMatrix() { return m_worldMatrix; +} + +XMVECTOR Object::GetPosition() +{ + XMFLOAT4X4 matrix; + XMStoreFloat4x4(&matrix, m_worldMatrix); + return XMVectorSet(matrix._41, matrix._42, matrix._43, 0.0f); +} + +XMVECTOR Object::GetRotation() +{ + XMFLOAT4X4 matrix; + XMStoreFloat4x4(&matrix, m_rotateMatrix); + float rotationX = atan2f(matrix._32, matrix._33); + float rotationY = atan2f(-matrix._31, sqrtf(matrix._32 * matrix._32 + matrix._33 * matrix._33)); + float rotationZ = atan2f(matrix._21, matrix._11); + return XMVectorSet(rotationX, rotationY, rotationZ, 0.0f); +} + + +XMVECTOR Object::GetScale() +{ + XMFLOAT4X4 matrix; + XMStoreFloat4x4(&matrix, m_scaleMatrix); + float scaleX = XMVectorGetX(XMVector3Length(XMVectorSet(matrix._11, matrix._12, matrix._13, 0.0f))); + float scaleY = XMVectorGetX(XMVector3Length(XMVectorSet(matrix._21, matrix._22, matrix._23, 0.0f))); + float scaleZ = XMVectorGetX(XMVector3Length(XMVectorSet(matrix._31, matrix._32, matrix._33, 0.0f))); + return XMVectorSet(scaleX, scaleY, scaleZ, 0.0f); } \ No newline at end of file diff --git a/enginecustom/object.h b/enginecustom/object.h index cd62595..a110311 100644 --- a/enginecustom/object.h +++ b/enginecustom/object.h @@ -13,12 +13,20 @@ public: void SetSRMatrix(XMMATRIX srMatrix); void SetWorldMatrix(XMMATRIX worldMatrix); + void SetPosition(XMVECTOR position); + void SetRotation(XMVECTOR rotation); + void SetScale(XMVECTOR scale); + XMMATRIX GetScaleMatrix(); XMMATRIX GetRotateMatrix(); XMMATRIX GetTranslateMatrix(); XMMATRIX GetSRMatrix(); XMMATRIX GetWorldMatrix(); + XMVECTOR GetPosition(); + XMVECTOR GetRotation(); + XMVECTOR GetScale(); + private: XMMATRIX m_scaleMatrix; XMMATRIX m_rotateMatrix;