From 0825afa0ee18cc7086ebc6345e22db2f48feaab7 Mon Sep 17 00:00:00 2001 From: Aitor Simona Bouzas Date: Mon, 21 Oct 2019 20:54:58 +0200 Subject: [PATCH] Showing Position and Scale info in Inspector (and enabled input) --- CENTRAL 3D/Source/GameObject.cpp | 21 +++++++ CENTRAL 3D/Source/GameObject.h | 2 + CENTRAL 3D/Source/Imgui/imgui_widgets.cpp | 5 +- CENTRAL 3D/Source/PanelInspector.cpp | 72 +++++++++++++++++++++-- 4 files changed, 92 insertions(+), 8 deletions(-) diff --git a/CENTRAL 3D/Source/GameObject.cpp b/CENTRAL 3D/Source/GameObject.cpp index d2097a819..7010f7ee4 100644 --- a/CENTRAL 3D/Source/GameObject.cpp +++ b/CENTRAL 3D/Source/GameObject.cpp @@ -53,6 +53,27 @@ float3 GameObject::GetPosition() return position; } +float3 GameObject::GetScale() +{ + float3 scale; + + scale.x = Local_transform.ptr()[0]; + scale.y = Local_transform.ptr()[5]; + scale.z = Local_transform.ptr()[10]; + + return scale; +} + +float3 GameObject::GetRotation() +{ + float3 rotation; + + //rotation.x = Atan2(Local_transform.ptr()[2][0], Local_transform.ptr()[2][0]); + + + return rotation; +} + float4x4 GameObject::GetLocalTransform() { return Local_transform; diff --git a/CENTRAL 3D/Source/GameObject.h b/CENTRAL 3D/Source/GameObject.h index 6cd03fd64..e2feeb818 100644 --- a/CENTRAL 3D/Source/GameObject.h +++ b/CENTRAL 3D/Source/GameObject.h @@ -20,6 +20,8 @@ class GameObject uint GetUID() const; std::string GetName() const; float3 GetPosition(); + float3 GetScale(); + float3 GetRotation(); float4x4 GetLocalTransform(); Component* GetComponent(Component::ComponentType type); diff --git a/CENTRAL 3D/Source/Imgui/imgui_widgets.cpp b/CENTRAL 3D/Source/Imgui/imgui_widgets.cpp index 76af04c65..740d2ca5f 100644 --- a/CENTRAL 3D/Source/Imgui/imgui_widgets.cpp +++ b/CENTRAL 3D/Source/Imgui/imgui_widgets.cpp @@ -2126,8 +2126,9 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, v, format); RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f)); - if (label_size.x > 0.0f) - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + // --- LIBCHANGE: Commented this to prevent imgui from displaying drag widget's labels + /* if (label_size.x > 0.0f) + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);*/ IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags); return value_changed; diff --git a/CENTRAL 3D/Source/PanelInspector.cpp b/CENTRAL 3D/Source/PanelInspector.cpp index e245e5a79..d79254327 100644 --- a/CENTRAL 3D/Source/PanelInspector.cpp +++ b/CENTRAL 3D/Source/PanelInspector.cpp @@ -30,31 +30,91 @@ bool PanelInspector::Draw() if (ImGui::TreeNode("Transform")) { - // --- Transform --- + // --- Transform Position --- + ImGui::Text("Position "); + ImGui::SameLine(); + float3 position = Selected->GetPosition(); ImGui::Text("X"); ImGui::SameLine(); - ImGui::SetNextItemWidth(100.0f); + ImGui::SetNextItemWidth(75.0f); - ImGui::DragFloat(" ", &position.x, 0.005f); + ImGui::DragFloat("PX", &position.x, 0.005f); ImGui::SameLine(); ImGui::Text("Y"); ImGui::SameLine(); - ImGui::SetNextItemWidth(100.0f); + ImGui::SetNextItemWidth(75.0f); - ImGui::DragFloat(" ", &position.y, 0.005f); + ImGui::DragFloat("PY", &position.y, 0.005f); ImGui::SameLine(); + ImGui::Text("Z"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(75.0f); + + ImGui::DragFloat("PZ", &position.z, 0.005f); + + // --- Transform Rotation --- + /*float3 rotation = Selected->GetRotation(); + ImGui::Text("X"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(100.0f); + + ImGui::DragFloat(" ", &position.x, 0.005f); + + ImGui::SameLine(); + + ImGui::Text("Y"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(100.0f); + + ImGui::DragFloat(" ", &position.y, 0.005f); + + ImGui::SameLine(); + ImGui::Text("Z"); ImGui::SameLine(); ImGui::SetNextItemWidth(100.0f); - ImGui::DragFloat(" ", &position.z, 0.005f); + ImGui::DragFloat(" ", &position.z, 0.005f); + Selected->SetPosition(position.x, position.y, position.z);*/ + + // --- Transform Scale --- + ImGui::Text("Scale "); + ImGui::SameLine(); + + float3 scale = Selected->GetScale(); + ImGui::Text("X"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(75.0f); + + ImGui::DragFloat("SX", &scale.x, 0.005f); + + ImGui::SameLine(); + + ImGui::Text("Y"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(75.0f); + + ImGui::DragFloat("SY", &scale.y, 0.005f); + + ImGui::SameLine(); + + ImGui::Text("Z"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(75.0f); + + ImGui::DragFloat("SZ", &scale.z, 0.005f); + + + // --- Transform Set --- Selected->SetPosition(position.x, position.y, position.z); + Selected->Scale(scale.x, scale.y, scale.z); + ImGui::TreePop(); }