ImGuiLYCameraMonitor.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #ifdef IMGUI_ENABLED
  10. #include "ImGuiManager.h"
  11. #include "ImGuiBus.h"
  12. #include "LYImGuiUtils/HistogramContainer.h"
  13. #include <AzCore/Component/TickBus.h>
  14. namespace ImGui
  15. {
  16. // Per Camera Data and Histograms to record for history
  17. struct CameraInfo
  18. {
  19. AZ::EntityId m_camId;
  20. AZStd::string m_camName; // cache the name, especially useful if a camera is deleted after use
  21. ImGui::LYImGuiUtils::HistogramContainer m_fovHisto;
  22. ImGui::LYImGuiUtils::HistogramContainer m_facingVectorDeltaHisto;
  23. ImGui::LYImGuiUtils::HistogramContainer m_positionDeltaHisto;
  24. AZ::Vector3 m_lastWorldPos;
  25. AZ::Vector3 m_lastFacingVector;
  26. float m_activeTime;
  27. int m_activeFrames;
  28. };
  29. class ImGuiLYCameraMonitor
  30. : public AZ::TickBus::Handler
  31. , public ImGuiCameraMonitorRequestBus::Handler
  32. {
  33. public:
  34. ImGuiLYCameraMonitor();
  35. virtual ~ImGuiLYCameraMonitor() = default;
  36. // Called from owner
  37. void Initialize();
  38. void Shutdown();
  39. // Draw the ImGui Menu
  40. void ImGuiUpdate();
  41. // -- AZ::TickBus::Handler Interface ---------------------------------------
  42. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  43. // -- AZ::TickBus::Handler Interface ---------------------------------------
  44. // -- ImGuiCameraMonitorRequestBus::Handler Interface ----------------------
  45. void SetEnabled(bool enabled) override { m_enabled = enabled; m_recordCameraData = enabled; }
  46. // -- ImGuiCameraMonitorRequestBus::Handler Interface ----------------------
  47. // Toggle the menu on and off
  48. void ToggleEnabled() { m_enabled = !m_enabled; }
  49. private:
  50. // flag for if the entire Menu enabled / visible
  51. bool m_enabled;
  52. // flag for if we should record camera data ( on OnTick.. so menu can be off and we can still record data )
  53. bool m_recordCameraData;
  54. // The size of camera History we want to keep ( within reason )
  55. int m_camHistorySize;
  56. // The current Camera Entity Id ( so we can easily keep track of camera switches next frame )
  57. AZ::EntityId m_currentCamera;
  58. // A history of per camera data. Front of the queue is the current camera
  59. AZStd::deque<CameraInfo> m_cameraHistory;
  60. // Additionally, keep 1 history of the active camera ( global = one histogram of data, even between camera switches )
  61. CameraInfo m_globalActiveCamInfo;
  62. ImGui::LYImGuiUtils::HistogramContainer m_dofMinZHisto;
  63. ImGui::LYImGuiUtils::HistogramContainer m_dofMinZBlendMultHisto;
  64. ImGui::LYImGuiUtils::HistogramContainer m_dofMinZScaleHisto;
  65. // Helper functions for the ImGui Update
  66. void ImGuiUpdate_DrawMenu();
  67. void ImGuiUpdate_DrawOptions();
  68. // Helper functions for the OnTick Update
  69. void OnTick_GatherCameraData(float deltaTime);
  70. void OnTick_GatherCameraData_PushNewCameraToHistory(AZ::EntityId newCamId);
  71. static float GetAngleBetweenVectors(const AZ::Vector3& v1, const AZ::Vector3& v2);
  72. };
  73. }
  74. #endif // IMGUI_ENABLED