From e331c5d5c676ef52f9ef912eb582b55a588bcade Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 11 Jul 2021 17:58:16 -0700 Subject: [PATCH] Add Player Transform tools --- Runtime/ImGuiConsole.cpp | 72 ++++++++++++++++++++++++++++++++++ Runtime/ImGuiConsole.hpp | 6 +++ Runtime/ImGuiEntitySupport.cpp | 7 +++- Runtime/ImGuiEntitySupport.hpp | 6 +++ extern/zeus | 2 +- hecl/include/hecl/hecl.hpp | 5 ++- 6 files changed, 94 insertions(+), 4 deletions(-) diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index 2726ec165..c6c660b27 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -5,10 +5,13 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/World/CPlayer.hpp" +#include "Runtime/ImGuiEntitySupport.hpp" #include "ImGuiEngine.hpp" #include "magic_enum.hpp" +#include + namespace ImGui { // Internal functions void ClearIniSettings(); @@ -1057,6 +1060,7 @@ void ImGuiConsole::ShowAppMainMenuBar(bool canInspect) { ImGui::EndMenu(); } if (ImGui::BeginMenu("Tools")) { + ImGui::MenuItem("Player Transform", nullptr, &m_showPlayerTransformEditor, canInspect && m_developer); ImGui::MenuItem("Inspect", nullptr, &m_showInspectWindow, canInspect && m_developer); ImGui::MenuItem("Items", nullptr, &m_showItemsWindow, canInspect && m_developer && m_cheats); ImGui::MenuItem("Layers", nullptr, &m_showLayersWindow, canInspect && m_developer); @@ -1196,6 +1200,7 @@ void ImGuiConsole::PreUpdate() { } ShowDebugOverlay(); ShowInputViewer(); + ShowPlayerTransformEditor(); } void ImGuiConsole::PostUpdate() { @@ -1545,4 +1550,71 @@ void ImGuiConsole::ShowMenuHint() { ImGui::PopStyleColor(2); } +void ImGuiConsole::ShowPlayerTransformEditor() { + if (!m_showPlayerTransformEditor) { + return; + } + + if (ImGui::Begin("Player Transform", &m_showPlayerTransformEditor, ImGuiWindowFlags_AlwaysAutoResize)) { + if (ImGui::CollapsingHeader("Position")) { + ImGui::PushID("player_position"); + zeus::CVector3f vec = g_StateManager->GetPlayer().GetTranslation(); + + if (ImGuiVector3fInput("Position", vec)) { + g_StateManager->GetPlayer().SetTranslation(vec); + } + + if (ImGui::Button("Save")) { + m_savedLocation.emplace(vec); + } + ImGui::SameLine(); + if (ImGui::Button("Load") && m_savedLocation) { + g_StateManager->GetPlayer().SetTranslation(*m_savedLocation); + } + ImGui::SameLine(); + if (ImGui::Button("Clear") && m_savedLocation) { + m_savedLocation.reset(); + } + if (m_savedLocation) { + ImGui::Text("Saved: %g, %g, %g", float(m_savedLocation->x()), float(m_savedLocation->y()), + float(m_savedLocation->z())); + } + ImGui::PopID(); + } + if (ImGui::CollapsingHeader("Rotation")) { + ImGui::PushID("player_rotation"); + zeus::CEulerAngles angles(g_StateManager->GetPlayer().GetTransform()); + angles = zeus::CEulerAngles(angles * zeus::skRadToDegVec); + if (ImGuiVector3fInput("Rotation", angles)) { + angles.x() = zeus::clamp(-179.999f, float(angles.x()), 179.999f); + angles.y() = zeus::clamp(-89.999f, float(angles.y()), 89.999f); + angles.z() = zeus::clamp(-179.999f, float(angles.z()), 179.999f); + auto xf = g_StateManager->GetPlayer().GetTransform(); + xf.setRotation(zeus::CQuaternion(angles * zeus::skDegToRadVec).toTransform().buildMatrix3f()); + g_StateManager->GetPlayer().SetTransform(xf); + } + + if (ImGui::Button("Save")) { + m_savedRotation.emplace(angles); + } + ImGui::SameLine(); + if (ImGui::Button("Load") && m_savedRotation) { + auto xf = g_StateManager->GetPlayer().GetTransform(); + xf.setRotation(zeus::CQuaternion((*m_savedRotation) * zeus::skDegToRadVec).toTransform().buildMatrix3f()); + g_StateManager->GetPlayer().SetTransform(xf); + } + ImGui::SameLine(); + if (ImGui::Button("Clear") && m_savedRotation) { + m_savedRotation.reset(); + } + + if (m_savedRotation) { + ImGui::Text("Saved: %g, %g, %g", float(m_savedRotation->x()), float(m_savedRotation->y()), + float(m_savedRotation->z())); + } + ImGui::PopID(); + } + } + ImGui::End(); +} } // namespace metaforce diff --git a/Runtime/ImGuiConsole.hpp b/Runtime/ImGuiConsole.hpp index f53b8c868..071c7ac0c 100644 --- a/Runtime/ImGuiConsole.hpp +++ b/Runtime/ImGuiConsole.hpp @@ -11,6 +11,8 @@ #include "hecl/CVarCommons.hpp" #include "hecl/CVarManager.hpp" +#include + namespace metaforce { void ImGuiStringViewText(std::string_view text); void ImGuiTextCenter(std::string_view text); @@ -57,6 +59,9 @@ private: bool m_showItemsWindow = false; bool m_showLayersWindow = false; bool m_showConsoleVariablesWindow = false; + bool m_showPlayerTransformEditor = false; + std::optional m_savedLocation; + std::optional m_savedRotation; bool m_paused = false; bool m_stepFrame = false; @@ -106,5 +111,6 @@ private: void ShowInputViewer(); void SetOverlayWindowLocation(int corner) const; void ShowCornerContextMenu(int& corner, int avoidCorner) const; + void ShowPlayerTransformEditor(); }; } // namespace metaforce diff --git a/Runtime/ImGuiEntitySupport.cpp b/Runtime/ImGuiEntitySupport.cpp index 3273e313e..9509975af 100644 --- a/Runtime/ImGuiEntitySupport.cpp +++ b/Runtime/ImGuiEntitySupport.cpp @@ -1,3 +1,5 @@ +#include "Runtime/ImGuiEntitySupport.hpp" + #include "Runtime/World/CActor.hpp" #include "Runtime/World/CAi.hpp" #include "Runtime/World/CAmbientAI.hpp" @@ -178,7 +180,9 @@ } \ } -static bool ImGuiVector3fInput(const char* label, zeus::CVector3f& vec) { +namespace metaforce { + +bool ImGuiVector3fInput(const char* label, zeus::CVector3f& vec) { std::array arr{vec.x(), vec.y(), vec.z()}; if (ImGui::DragFloat3(label, arr.data(), 0.1f)) { vec.assign(arr[0], arr[1], arr[2]); @@ -221,7 +225,6 @@ void ImGuiAnimRes(const char* label, metaforce::CAnimRes& res) { // TODO: More } -namespace metaforce { void CDamageVulnerability::ImGuiEditWindow(const char* title, bool& open) { if (!open) { return; diff --git a/Runtime/ImGuiEntitySupport.hpp b/Runtime/ImGuiEntitySupport.hpp index 6f70f09be..584774087 100644 --- a/Runtime/ImGuiEntitySupport.hpp +++ b/Runtime/ImGuiEntitySupport.hpp @@ -1 +1,7 @@ #pragma once + +#include + +namespace metaforce { +bool ImGuiVector3fInput(const char* label, zeus::CVector3f& vec); +} \ No newline at end of file diff --git a/extern/zeus b/extern/zeus index bb9b4c83a..f3630be9d 160000 --- a/extern/zeus +++ b/extern/zeus @@ -1 +1 @@ -Subproject commit bb9b4c83af12647df1db7978347bd297dda3277b +Subproject commit f3630be9dee64378e7bcf20b4602b64bd8c810c0 diff --git a/hecl/include/hecl/hecl.hpp b/hecl/include/hecl/hecl.hpp index be6d8812a..5c96a5b63 100644 --- a/hecl/include/hecl/hecl.hpp +++ b/hecl/include/hecl/hecl.hpp @@ -35,15 +35,18 @@ extern "C" int rep_closefrom(int lower); #include #include #include +#include #include #include -#include "logvisor/logvisor.hpp" +#include "FourCC.hpp" #include "athena/Global.hpp" +#include "logvisor/logvisor.hpp" #include "xxhash/xxhash.h" #include "SystemChar.hpp" #include "FourCC.hpp" + #if defined(__has_feature) #if __has_feature(thread_sanitizer) #define HECL_NO_SANITIZE_THREAD __attribute__((no_sanitize("thread")))