diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2018-04-16 11:24:50 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2018-04-16 11:24:50 -0700 |
commit | e8d8d80a022ad5801ed57e7275380da7f1d1ca27 (patch) | |
tree | b4eb61f2577cdae4b4df9f432ca4056813c08b33 | |
parent | d9211a4329f7d7b95ac812ab68831fe14de4089a (diff) | |
download | qtlocation-mapboxgl-e8d8d80a022ad5801ed57e7275380da7f1d1ca27.tar.gz |
[iOS, macOS] Use MGLMatrix4 a 4x4 double matrix for MGLOpenGLStyleLayer projection matrix.
-rw-r--r-- | platform/darwin/src/MGLGeometry.h | 12 | ||||
-rw-r--r-- | platform/darwin/src/MGLGeometry.mm | 8 | ||||
-rw-r--r-- | platform/darwin/src/MGLGeometry_Private.h | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLOpenGLStyleLayer.h | 3 | ||||
-rw-r--r-- | platform/darwin/src/MGLOpenGLStyleLayer.mm | 14 |
5 files changed, 26 insertions, 13 deletions
diff --git a/platform/darwin/src/MGLGeometry.h b/platform/darwin/src/MGLGeometry.h index 6d1a373cca..d971f895bb 100644 --- a/platform/darwin/src/MGLGeometry.h +++ b/platform/darwin/src/MGLGeometry.h @@ -24,6 +24,18 @@ typedef struct __attribute__((objc_boxable)) MGLMapPoint { CGFloat zoomLevel; } MGLMapPoint; +union __attribute__((aligned(16))) _MGLMatrix4 { + struct + { + double m00, m01, m02, m03; + double m10, m11, m12, m13; + double m20, m21, m22, m23; + double m30, m31, m32, m33; + }; + double m[16]; +}; +typedef union _MGLMatrix4 MGLMatrix4; + /** Creates a new `MGLCoordinateSpan` from the given latitudinal and longitudinal deltas. diff --git a/platform/darwin/src/MGLGeometry.mm b/platform/darwin/src/MGLGeometry.mm index 0b044f7521..e43c7b7b05 100644 --- a/platform/darwin/src/MGLGeometry.mm +++ b/platform/darwin/src/MGLGeometry.mm @@ -111,3 +111,11 @@ MGLMapPoint MGLMapPointForCoordinate(CLLocationCoordinate2D coordinate, double z mbgl::Point<double> projectedCoordinate = mbgl::Projection::project(MGLLatLngFromLocationCoordinate2D(coordinate), std::pow(2.0, zoomLevel)); return MGLMapPointMake(projectedCoordinate.x, projectedCoordinate.y, zoomLevel); } + +MGLMatrix4 MGLMatrix4Make(std::array<double, 16> array) { + MGLMatrix4 mat4; + for(uint8_t i = 0; i< 16; i++) { + mat4.m[i] = array[i]; + } + return mat4; +} diff --git a/platform/darwin/src/MGLGeometry_Private.h b/platform/darwin/src/MGLGeometry_Private.h index 8b9c6c2327..0bff9b09f5 100644 --- a/platform/darwin/src/MGLGeometry_Private.h +++ b/platform/darwin/src/MGLGeometry_Private.h @@ -128,3 +128,5 @@ MGLRadianCoordinate2D MGLRadianCoordinateAtDistanceFacingDirection(MGLRadianCoor CLLocationDirection MGLDirectionBetweenCoordinates(CLLocationCoordinate2D firstCoordinate, CLLocationCoordinate2D secondCoordinate); CGPoint MGLPointRounded(CGPoint point); + +MGLMatrix4 MGLMatrix4Make(std::array<double, 16> mat); diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.h b/platform/darwin/src/MGLOpenGLStyleLayer.h index 50d226457f..df8d2c5365 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.h +++ b/platform/darwin/src/MGLOpenGLStyleLayer.h @@ -5,6 +5,7 @@ #import "MGLFoundation.h" #import "MGLStyleValue.h" #import "MGLStyleLayer.h" +#import "MGLGeometry.h" NS_ASSUME_NONNULL_BEGIN @@ -18,7 +19,7 @@ typedef struct MGLStyleLayerDrawingContext { CLLocationDirection direction; CGFloat pitch; CGFloat fieldOfView; - CATransform3D projectionMatrix; + MGLMatrix4 projectionMatrix; } MGLStyleLayerDrawingContext; MGL_EXPORT diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.mm b/platform/darwin/src/MGLOpenGLStyleLayer.mm index 6d132ac00e..d89fbc80c3 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.mm +++ b/platform/darwin/src/MGLOpenGLStyleLayer.mm @@ -3,21 +3,11 @@ #import "MGLMapView_Private.h" #import "MGLStyle_Private.h" #import "MGLStyleLayer_Private.h" +#import "MGLGeometry_Private.h" #include <mbgl/style/layers/custom_layer.hpp> #include <mbgl/math/wrap.hpp> - -CATransform3D CATransform3DMake(std::array<double, 16> array) { - CATransform3D t = { - .m11 = static_cast<CGFloat>(array[0]), .m12 = static_cast<CGFloat>(array[1]), .m13 = static_cast<CGFloat>(array[2]), .m14 = static_cast<CGFloat>(array[3]), - .m21 = static_cast<CGFloat>(array[4]), .m22 = static_cast<CGFloat>(array[5]), .m23 = static_cast<CGFloat>(array[6]), .m24 = static_cast<CGFloat>(array[7]), - .m31 = static_cast<CGFloat>(array[8]), .m32 = static_cast<CGFloat>(array[9]), .m33 = static_cast<CGFloat>(array[10]), .m34 = static_cast<CGFloat>(array[11]), - .m41 = static_cast<CGFloat>(array[12]), .m42 = static_cast<CGFloat>(array[13]), .m43 = static_cast<CGFloat>(array[14]), .m44 = static_cast<CGFloat>(array[15]) - }; - return t; -} - class MGLOpenGLLayerHost : public mbgl::style::CustomLayerHost { public: MGLOpenGLLayerHost(MGLOpenGLStyleLayer *styleLayer) { @@ -42,7 +32,7 @@ public: .direction = mbgl::util::wrap(params.bearing, 0., 360.), .pitch = static_cast<CGFloat>(params.pitch), .fieldOfView = static_cast<CGFloat>(params.fieldOfView), - .projectionMatrix = CATransform3DMake(params.projectionMatrix) + .projectionMatrix = MGLMatrix4Make(params.projectionMatrix) }; [layer drawInMapView:layer.style.mapView withContext:drawingContext]; } |