ProximitySensor.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  4. * of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. #pragma once
  10. #include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
  11. #include <AzCore/Component/Component.h>
  12. #include <AzCore/Component/TickBus.h>
  13. #include <AzCore/Math/Vector3.h>
  14. namespace WarehouseAutomation
  15. {
  16. //! Simple proximity sensor based on raycasting
  17. //! This component publishes a bool topic depending on the object presence
  18. class ProximitySensor
  19. : public AZ::Component
  20. , public AZ::TickBus::Handler
  21. {
  22. public:
  23. AZ_COMPONENT(ProximitySensor, "{1f7b51f6-9450-4da4-9636-672a056e8812}", AZ::Component);
  24. ProximitySensor();
  25. ~ProximitySensor() = default;
  26. static void Reflect(AZ::ReflectContext* context);
  27. //////////////////////////////////////////////////////////////////////////
  28. // Component overrides
  29. void Activate() override;
  30. void Deactivate() override;
  31. //////////////////////////////////////////////////////////////////////////
  32. private:
  33. //////////////////////////////////////////////////////////////////////////
  34. // AZ::TickBus::Handler overrides
  35. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  36. //////////////////////////////////////////////////////////////////////////
  37. void Visualize();
  38. void DetectionCheck();
  39. bool m_visualize{ true };
  40. float m_frequency{ 10.f };
  41. AZ::Vector3 m_detectionDirection{ AZ::Vector3::CreateAxisX() };
  42. float m_detectionDistance{ 1.f };
  43. std::optional<AZ::Vector3> m_position;
  44. float m_timeElapsedSinceLastTick{ 0.f };
  45. AZ::RPI::AuxGeomDrawPtr m_drawQueue;
  46. };
  47. } // namespace WarehouseAutomation