diff options
Diffstat (limited to 'src/mbgl/map/transform_state.hpp')
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 152 |
1 files changed, 137 insertions, 15 deletions
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index 10a92187d5..edc7f3b9cf 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -19,32 +19,123 @@ namespace mbgl { class UnwrappedTileID; class TileCoordinate; -class TransformState { - friend class Transform; - friend class RendererState; +struct TransformStateProperties { + TransformStateProperties& withX(const optional<double>& val) { + x = val; + return *this; + } + TransformStateProperties& withY(const optional<double>& val) { + y = val; + return *this; + } + TransformStateProperties& withScale(const optional<double>& val) { + scale = val; + return *this; + } + TransformStateProperties& withBearing(const optional<double>& val) { + bearing = val; + return *this; + } + TransformStateProperties& withPitch(const optional<double>& val) { + pitch = val; + return *this; + } + TransformStateProperties& withXSkew(const optional<double>& val) { + xSkew = val; + return *this; + } + TransformStateProperties& withYSkew(const optional<double>& val) { + ySkew = val; + return *this; + } + TransformStateProperties& withAxonometric(const optional<bool>& val) { + axonometric = val; + return *this; + } + TransformStateProperties& withPanningInProgress(const optional<bool>& val) { + panning = val; + return *this; + } + TransformStateProperties& withScalingInProgress(const optional<bool>& val) { + scaling = val; + return *this; + } + TransformStateProperties& withRotatingInProgress(const optional<bool>& val) { + rotating = val; + return *this; + } + TransformStateProperties& withEdgeInsets(const optional<EdgeInsets>& val) { + edgeInsets = val; + return *this; + } + TransformStateProperties& withSize(const optional<Size>& val) { + size = val; + return *this; + } + TransformStateProperties& withConstrainMode(const optional<ConstrainMode>& val) { + constrain = val; + return *this; + } + TransformStateProperties& withNorthOrientation(const optional<NorthOrientation>& val) { + northOrientation = val; + return *this; + } + TransformStateProperties& withViewportMode(const optional<ViewportMode>& val) { + viewPortMode = val; + return *this; + } + + optional<double> x; + optional<double> y; + optional<double> bearing; + optional<double> scale; + optional<double> pitch; + optional<double> xSkew; + optional<double> ySkew; + optional<bool> axonometric; + optional<bool> panning; + optional<bool> scaling; + optional<bool> rotating; + optional<EdgeInsets> edgeInsets; + optional<Size> size; + optional<ConstrainMode> constrain; + optional<NorthOrientation> northOrientation; + optional<ViewportMode> viewPortMode; +}; +class TransformState { public: TransformState(ConstrainMode = ConstrainMode::HeightOnly, ViewportMode = ViewportMode::Default); + void setProperties(const TransformStateProperties& properties); + // Matrix void matrixFor(mat4&, const UnwrappedTileID&) const; void getProjMatrix(mat4& matrix, uint16_t nearZ = 1, bool aligned = false) const; // Dimensions Size getSize() const; + void setSize(const Size& size_); // North Orientation NorthOrientation getNorthOrientation() const; double getNorthOrientationAngle() const; + void setNorthOrientation(const NorthOrientation); // Constrain mode ConstrainMode getConstrainMode() const; + void setConstrainMode(const ConstrainMode); // Viewport mode ViewportMode getViewportMode() const; + void setViewportMode(ViewportMode val); CameraOptions getCameraOptions(optional<EdgeInsets>) const; + // EdgeInsects + EdgeInsets getEdgeInsets() const { return edgeInsets; } + void setEdgeInsets(const EdgeInsets&); + // Position LatLng getLatLng(LatLng::WrapMode = LatLng::Unwrapped) const; double pixel_x() const; @@ -56,7 +147,14 @@ public: double getZoomFraction() const; // Scale - double getScale() const { return scale; } + double getScale() const; + void setScale(double); + + // Positions + double getX() const; + void setX(double); + double getY() const; + void setY(double); // Bounds void setLatLngBounds(LatLngBounds); @@ -67,17 +165,30 @@ public: double getMaxZoom() const; // Rotation - float getBearing() const; + double getBearing() const; + void setBearing(double); float getFieldOfView() const; float getCameraToCenterDistance() const; - float getPitch() const; + double getPitch() const; + void setPitch(double); + + double getXSkew() const; + void setXSkew(double); + double getYSkew() const; + void setYSkew(double); + bool getAxonometric() const; + void setAxonometric(bool); // State bool isChanging() const; bool isRotating() const; + void setRotatingInProgress(bool val) { rotating = val; } bool isScaling() const; + void setScalingInProgress(bool val) { scaling = val; } bool isPanning() const; + void setPanningInProgress(bool val) { panning = val; } bool isGestureInProgress() const; + void setGestureInProgress(bool val) { gestureInProgress = val; } // Conversion ScreenCoordinate latLngToScreenCoordinate(const LatLng&) const; @@ -88,16 +199,20 @@ public: double zoomScale(double zoom) const; double scaleZoom(double scale) const; - bool valid() const { - return !size.isEmpty() && (scale >= min_scale && scale <= max_scale); - } + bool valid() const { return !size.isEmpty() && (scale >= min_scale && scale <= max_scale); } float getCameraToTileDistance(const UnwrappedTileID&) const; float maxPitchScaleFactor() const; + /** Recenter the map so that the given coordinate is located at the given + point on screen. */ + void moveLatLng(const LatLng&, const ScreenCoordinate&); + void setLatLngZoom(const LatLng& latLng, double zoom); + + void constrain(double& scale, double& x, double& y) const; + private: bool rotatedNorth() const; - void constrain(double& scale, double& x, double& y) const; // Viewport center offset, from [size.width / 2, size.height / 2], defined // by |edgeInsets| in screen coordinates, with top left origin. @@ -114,15 +229,17 @@ private: // logical dimensions Size size; - mat4 coordinatePointMatrix() const; + mat4 coordinatePointMatrix(const mat4& projMatrix) const; mat4 getPixelMatrix() const; - /** Recenter the map so that the given coordinate is located at the given - point on screen. */ - void moveLatLng(const LatLng&, const ScreenCoordinate&); - void setLatLngZoom(const LatLng &latLng, double zoom); void setScalePoint(const double scale, const ScreenCoordinate& point); + void updateMatricesIfNeeded() const; + bool needsMatricesUpdate() const { return requestMatricesUpdate; } + const mat4& getProjectionMatrix() const; + const mat4& getCoordMatrix() const; + const mat4& getInvertedMatrix() const; + private: ConstrainMode constrainMode; ViewportMode viewportMode; @@ -152,6 +269,11 @@ private: // cache values for spherical mercator math double Bc = Projection::worldSize(scale) / util::DEGREES_MAX; double Cc = Projection::worldSize(scale) / util::M2PI; + + mutable bool requestMatricesUpdate{true}; + mutable mat4 projectionMatrix; + mutable mat4 coordMatrix; + mutable mat4 invertedMatrix; }; } // namespace mbgl |