ShapeDisplay.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include <AzCore/Math/Color.h>
  10. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  11. #include <AzFramework/Viewport/ViewportColors.h>
  12. #include <LmbrCentral/Shape/ShapeComponentBus.h>
  13. namespace LmbrCentral
  14. {
  15. const ShapeDrawParams g_defaultShapeDrawParams = {
  16. AzFramework::ViewportColors::DeselectedColor,
  17. AzFramework::ViewportColors::WireColor,
  18. true
  19. };
  20. /// @brief Helper function to be used when drawing debug shapes - called from DisplayEntity on
  21. /// the EntityDebugDisplayEventBus.
  22. /// @param handled Did we display anything.
  23. /// @param canDraw Functor to decide should the shape be drawn or not.
  24. /// @param drawShape Functor to draw a specific shape (box/capsule/sphere etc).
  25. /// @param worldFromLocal Transform of object in world space, push to matrix stack and render shape in local space.
  26. template<typename CanDraw, typename DrawShape>
  27. void DisplayShape(
  28. AzFramework::DebugDisplayRequests& debugDisplay,
  29. CanDraw&& canDraw, DrawShape&& drawShape, const AZ::Transform& worldFromLocal)
  30. {
  31. if (!canDraw())
  32. {
  33. return;
  34. }
  35. // only uniform scale is supported in physics so the debug visuals reflect this fact
  36. AZ::Transform worldFromLocalWithUniformScale = worldFromLocal;
  37. worldFromLocalWithUniformScale.SetUniformScale(worldFromLocalWithUniformScale.GetUniformScale());
  38. debugDisplay.PushMatrix(worldFromLocalWithUniformScale);
  39. drawShape(debugDisplay);
  40. debugDisplay.PopMatrix();
  41. }
  42. } // namespace LmbrCentral