GeoreferenceLevelComponent.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/Component/Component.h>
  10. #include <AzCore/Component/EntityBus.h>
  11. #include <AzCore/Component/TransformBus.h>
  12. #include <AzCore/Math/Transform.h>
  13. #include <AzCore/Serialization/SerializeContext.h>
  14. #include <AzFramework/Components/ComponentAdapter.h>
  15. #include <Georeferencing/GeoreferenceBus.h>
  16. namespace Georeferencing
  17. {
  18. struct GeoReferenceLevelConfig : public AZ::ComponentConfig
  19. {
  20. AZ_RTTI(GeoReferenceLevelConfig, GeoReferenceLevelConfigTypeId, AZ::ComponentConfig);
  21. static void Reflect(AZ::ReflectContext* context);
  22. AZ::EntityId m_enuOriginLocationEntityId; //!< EntityId of the entity that lays in the origin of the ENU coordinate system
  23. WGS::WGS84Coordinate m_originLocation; //!< Location of the entity that lays in the origin of the ENU coordinate system
  24. };
  25. class GeoReferenceLevelController
  26. : private GeoreferenceRequestsBus::Handler
  27. , private GeoreferenceConfigurationRequestsBus::Handler
  28. , private AZ::EntityBus::Handler
  29. , private AZ::TransformNotificationBus::Handler
  30. {
  31. public:
  32. AZ_TYPE_INFO(GeoReferenceLevelController, "{60b22daa-c241-49d2-ba83-dca380c179b1}");
  33. static void Reflect(AZ::ReflectContext* context);
  34. GeoReferenceLevelController() = default;
  35. GeoReferenceLevelController(const GeoReferenceLevelConfig& config);
  36. // Controller component ...
  37. void Init();
  38. void Activate(AZ::EntityId entityId);
  39. void Deactivate();
  40. void SetConfiguration(const GeoReferenceLevelConfig& config);
  41. const GeoReferenceLevelConfig& GetConfiguration() const;
  42. private:
  43. // EntityBus overrides ...
  44. void OnEntityActivated(const AZ::EntityId& entityId) override;
  45. // GeoreferenceRequestsBus::Handler overrides ...
  46. WGS::WGS84Coordinate ConvertFromLevelToWGS84(const AZ::Vector3& xyz) override;
  47. AZ::Vector3 ConvertFromWGS84ToLevel(const WGS::WGS84Coordinate& latLon) override;
  48. AZ::Quaternion GetRotationFromLevelToENU() override;
  49. // ConfigurationRequestsBus::Handler overrides ...
  50. void SetOriginEntity(const AZ::EntityId& entityId) override;
  51. void SetOriginCoordinates(const WGS::WGS84Coordinate& origin) override;
  52. AZ::EntityId GetOriginEntity() override;
  53. WGS::WGS84Coordinate GetOriginCoordinates() override;
  54. // TransformNotificationBus::Handler overrides ...
  55. void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
  56. void ApplyOriginTransform(const AZ::Transform& worldTransform);
  57. GeoReferenceLevelConfig m_config;
  58. AZ::Transform m_enuOriginTransform; //!< Transform of the entity that lays in the origin of the ENU coordinate system
  59. };
  60. using GeoReferenceLevelComponentBase = AzFramework::Components::ComponentAdapter<GeoReferenceLevelController, GeoReferenceLevelConfig>;
  61. class GeoReferenceLevelComponent : public GeoReferenceLevelComponentBase
  62. {
  63. public:
  64. AZ_COMPONENT(GeoReferenceLevelComponent, GeoReferenceLevelComponentTypeId, AZ::Component);
  65. static void Reflect(AZ::ReflectContext* context);
  66. GeoReferenceLevelComponent(const GeoReferenceLevelConfig& config);
  67. GeoReferenceLevelComponent() = default;
  68. ~GeoReferenceLevelComponent() = default;
  69. // Component overrides...
  70. void Activate() override;
  71. void Deactivate() override;
  72. };
  73. } // namespace Georeferencing