diff options
author | Lauren Budorick <lauren@mapbox.com> | 2017-04-27 15:56:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-27 15:56:55 -0700 |
commit | f6e79d70735361438655f279c8699a786d25458c (patch) | |
tree | cc01ae7aba097bae4aa84beb12ac6b8f34f4d51a /include/mbgl/style/position.hpp | |
parent | 839ad87f37a4880804fb4c79157d998ac59954b5 (diff) | |
download | qtlocation-mapboxgl-f6e79d70735361438655f279c8699a786d25458c.tar.gz |
[core] Render fill-extrusion layers (#8431)
Diffstat (limited to 'include/mbgl/style/position.hpp')
-rw-r--r-- | include/mbgl/style/position.hpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/include/mbgl/style/position.hpp b/include/mbgl/style/position.hpp new file mode 100644 index 0000000000..3be8d1c55e --- /dev/null +++ b/include/mbgl/style/position.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include <mbgl/util/constants.hpp> + +#include <array> + +namespace mbgl { +namespace style { +class Position { +public: + Position() = default; + Position(std::array<float, 3>& position_) + : radial(position_[0]), azimuthal(position_[1]), polar(position_[2]) { + calculateCartesian(); + }; + + friend bool operator==(const Position& lhs, const Position& rhs) { + return lhs.radial == rhs.radial && lhs.azimuthal == rhs.azimuthal && lhs.polar == rhs.polar; + // TODO this doesn't address wrapping, which would be better addressed by comparing cartesian coordinates but being calculated floats are ont to be trusted. + } + + friend bool operator!=(const Position& lhs, const Position& rhs) { + return !(lhs == rhs); + } + + const std::array<float, 3> getCartesian() const { + return { { x, y, z } }; + }; + + const std::array<float, 3> getSpherical() const { + return { { radial, azimuthal, polar } }; + }; + + void set(std::array<float, 3>& position_) { + radial = position_[0]; + azimuthal = position_[1]; + polar = position_[2]; + calculateCartesian(); + }; + + // Utility function to be used only during interpolation; this leaves spherical coordinates undefined. + void setCartesian(std::array<float, 3>& position_) { + x = position_[0]; + y = position_[1]; + z = position_[2]; + } + +private: + float radial; + float azimuthal; + float polar; + float x; + float y; + float z; + + void calculateCartesian() { + // We abstract "north"/"up" (compass-wise) to be 0° when really this is 90° (π/2): we + // correct for that here + const float _a = (azimuthal + 90) * util::DEG2RAD; + const float _p = polar * util::DEG2RAD; + + x = radial * std::cos(_a) * std::sin(_p); + y = radial * std::sin(_a) * std::sin(_p); + z = radial * std::cos(_p); + }; +}; +} // namespace style +} // namespace mbgl |