From 8d56c159c685c4bb4958fd44c4b9624e95ebb4b9 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Tue, 26 Mar 2024 15:24:38 +0100 Subject: [PATCH] Mini tweak --- enginecustom/imgui.ini | 4 ++-- enginecustom/imguiManager.cpp | 20 +++++++++++++++++--- enginecustom/object.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index deb9108..48f8c8b 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -3,10 +3,10 @@ Pos=60,60 Size=400,400 [Window][Khaotic Engine] -Pos=1068,19 +Pos=765,19 Size=694,367 [Window][Objects] -Pos=74,113 +Pos=44,57 Size=492,353 diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index ac2907b..bbb374e 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -89,9 +89,23 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) 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)); + float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) }; + if (ImGui::DragFloat3("Position", pos)) + { + object->SetPosition(XMVectorSet(pos[0], pos[1], pos[2], 0.0f)); + } + + float rot[3] = { XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation) }; + if (ImGui::DragFloat3("Rotation", rot)) + { + object->SetRotation(XMVectorSet(rot[0], rot[1], rot[2], 0.0f)); + } + + float scl[3] = { XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale) }; + if (ImGui::DragFloat3("Scale", scl)) + { + object->SetScale(XMVectorSet(scl[0], scl[1], scl[2], 0.0f)); + } } index++; } diff --git a/enginecustom/object.cpp b/enginecustom/object.cpp index 58108f9..a299102 100644 --- a/enginecustom/object.cpp +++ b/enginecustom/object.cpp @@ -89,4 +89,32 @@ XMVECTOR Object::GetScale() 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); +} + +void Object::SetPosition(XMVECTOR position) +{ + XMFLOAT4X4 matrix; + XMStoreFloat4x4(&matrix, m_worldMatrix); + matrix._41 = XMVectorGetX(position); + matrix._42 = XMVectorGetY(position); + matrix._43 = XMVectorGetZ(position); + m_worldMatrix = XMLoadFloat4x4(&matrix); +} + +void Object::SetRotation(XMVECTOR rotation) +{ + XMFLOAT4X4 matrix; + XMStoreFloat4x4(&matrix, m_rotateMatrix); + XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation)); + m_rotateMatrix = rotationMatrix; +} + +void Object::SetScale(XMVECTOR scale) +{ + XMFLOAT4X4 matrix; + XMStoreFloat4x4(&matrix, m_scaleMatrix); + matrix._11 = XMVectorGetX(scale); + matrix._22 = XMVectorGetY(scale); + matrix._33 = XMVectorGetZ(scale); + m_scaleMatrix = XMLoadFloat4x4(&matrix); } \ No newline at end of file