GeoreferenceStructures.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "GeoreferencingTypeIds.h"
  11. #include <AzCore/Math/MathUtils.h>
  12. #include <AzCore/Math/Vector3.h>
  13. #include <AzCore/RTTI/RTTI.h>
  14. namespace Georeferencing::WGS
  15. {
  16. //! WGS84Coordinate is a 3D vector with double precision.
  17. //! It is used to represent coordinates in WGS84 coordinate system.
  18. struct WGS84Coordinate
  19. {
  20. AZ_RTTI(WGS84Coordinate, WGS84CoordinateTypeId);
  21. static void Reflect(AZ::ReflectContext* context);
  22. WGS84Coordinate() = default;
  23. virtual ~WGS84Coordinate() = default;
  24. WGS84Coordinate(double latitude, double longitude, double altitude)
  25. : m_latitude(latitude)
  26. , m_longitude(longitude)
  27. , m_altitude(altitude)
  28. {
  29. }
  30. explicit WGS84Coordinate(const AZ::Vector3& latLonAlt)
  31. : m_latitude(latLonAlt.GetX())
  32. , m_longitude(latLonAlt.GetY())
  33. , m_altitude(latLonAlt.GetZ())
  34. {
  35. }
  36. void FromVector3f(const AZ::Vector3& latLonAlt)
  37. {
  38. m_latitude = latLonAlt.GetX();
  39. m_longitude = latLonAlt.GetY();
  40. m_altitude = latLonAlt.GetZ();
  41. }
  42. //! Converts WGS84Coordinate to Vector3f, where x is latitude, y is longitude
  43. //! and z is altitude. Expect accuracy loss due to float conversion.
  44. AZ::Vector3 ToVector3f() const
  45. {
  46. return AZ::Vector3(static_cast<float>(m_latitude), static_cast<float>(m_longitude), static_cast<float>(m_altitude));
  47. }
  48. bool operator==(const WGS84Coordinate& rhs) const
  49. {
  50. return AZ::IsClose(m_latitude, rhs.m_latitude) && AZ::IsClose(m_longitude, rhs.m_longitude) &&
  51. AZ::IsClose(m_altitude, rhs.m_altitude);
  52. }
  53. void SetLatitude(double latitude)
  54. {
  55. m_latitude = latitude;
  56. }
  57. void SetLongitude(double longitude)
  58. {
  59. m_longitude = longitude;
  60. }
  61. void SetAltitude(double altitude)
  62. {
  63. m_altitude = altitude;
  64. }
  65. double GetLatitude() const
  66. {
  67. return m_latitude;
  68. }
  69. double GetLongitude() const
  70. {
  71. return m_longitude;
  72. }
  73. double GetAltitude() const
  74. {
  75. return m_altitude;
  76. }
  77. double m_latitude = 0.0; //!< Latitude in degrees.
  78. double m_longitude = 0.0; //!< Longitude in degrees.
  79. double m_altitude = 0.0; //!< Altitude in meters.
  80. };
  81. } // namespace Georeferencing::WGS