Skip to content

Commit

Permalink
Showing Position and Scale info in Inspector (and enabled input)
Browse files Browse the repository at this point in the history
  • Loading branch information
AitorSimona committed Oct 21, 2019
1 parent beb6ac1 commit 0825afa
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 8 deletions.
21 changes: 21 additions & 0 deletions CENTRAL 3D/Source/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions CENTRAL 3D/Source/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions CENTRAL 3D/Source/Imgui/imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
72 changes: 66 additions & 6 deletions CENTRAL 3D/Source/PanelInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 0825afa

Please sign in to comment.