From 67675aab4975dbf49bcf04e509b83850dd2845d5 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 25 Feb 2015 15:14:01 -0500 Subject: [PATCH 1/5] Fix determining whether a corridor changes direction at a vertex. --- Source/Core/CorridorGeometryLibrary.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Source/Core/CorridorGeometryLibrary.js b/Source/Core/CorridorGeometryLibrary.js index e20fd4392c45..1c78ec60eb18 100644 --- a/Source/Core/CorridorGeometryLibrary.js +++ b/Source/Core/CorridorGeometryLibrary.js @@ -1,6 +1,7 @@ /*global define*/ define([ './Cartesian3', + './Cartographic', './CornerType', './defined', './isArray', @@ -11,6 +12,7 @@ define([ './Quaternion' ], function( Cartesian3, + Cartographic, CornerType, defined, isArray, @@ -160,6 +162,10 @@ define([ return positions; } + var scratchPrevCartographic = new Cartographic(); + var scratchPosCartographic = new Cartographic(); + var scratchNextCartographic = new Cartographic(); + /** * @private */ @@ -207,7 +213,21 @@ define([ nextPosition = positions[i + 1]; forward = Cartesian3.normalize(Cartesian3.subtract(nextPosition, position, forward), forward); cornerDirection = Cartesian3.normalize(Cartesian3.add(forward, backward, cornerDirection), cornerDirection); - var doCorner = !Cartesian3.equalsEpsilon(Cartesian3.negate(cornerDirection, scratch1), normal, CesiumMath.EPSILON2); + + var positionCartographic = ellipsoid.cartesianToCartographic(position, scratchPosCartographic); + var prevPositionCartographic = ellipsoid.cartesianToCartographic(previousPos, scratchPrevCartographic); + var nextPositionCartographic = ellipsoid.cartesianToCartographic(nextPosition, scratchNextCartographic); + + var cartographicEpsilon = CesiumMath.EPSILON14; + var prevLongitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.longitude, prevPositionCartographic.longitude, cartographicEpsilon); + var prevLatitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.latitude, prevPositionCartographic.latitude, cartographicEpsilon); + var nextLongitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.longitude, nextPositionCartographic.longitude, cartographicEpsilon); + var nextLatitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.latitude, nextPositionCartographic.latitude, cartographicEpsilon); + + var longitudeEquality = prevLongitudeEquality && nextLongitudeEquality; + var latitudeEquality = prevLatitudeEquality && nextLatitudeEquality; + var doCorner = !longitudeEquality && !latitudeEquality; + if (doCorner) { cornerDirection = Cartesian3.cross(cornerDirection, normal, cornerDirection); cornerDirection = Cartesian3.cross(normal, cornerDirection, cornerDirection); From 6b354ea1f8b690d6f09e9a180f30f8fdf42d0966 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Wed, 25 Feb 2015 15:36:51 -0500 Subject: [PATCH 2/5] Fix the same issue with PolylineVolume. --- Source/Core/PolylineVolumeGeometryLibrary.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/Core/PolylineVolumeGeometryLibrary.js b/Source/Core/PolylineVolumeGeometryLibrary.js index 53ae79aa0bf9..08b9e029e297 100644 --- a/Source/Core/PolylineVolumeGeometryLibrary.js +++ b/Source/Core/PolylineVolumeGeometryLibrary.js @@ -290,6 +290,10 @@ define([ return cleanedPositions; }; + var scratchPrevCartographic = new Cartographic(); + var scratchPosCartographic = new Cartographic(); + var scratchNextCartographic = new Cartographic(); + PolylineVolumeGeometryLibrary.computePositions = function(positions, shape2D, boundingRectangle, geometry, duplicatePoints) { var ellipsoid = geometry._ellipsoid; var heights = scaleToSurface(positions, ellipsoid); @@ -338,7 +342,21 @@ define([ cornerDirection = Cartesian3.add(forward, backward, cornerDirection); cornerDirection = Cartesian3.normalize(cornerDirection, cornerDirection); surfaceNormal = ellipsoid.geodeticSurfaceNormal(position, surfaceNormal); - var doCorner = !Cartesian3.equalsEpsilon(Cartesian3.negate(cornerDirection, scratch1), surfaceNormal, CesiumMath.EPSILON2); + + var positionCartographic = ellipsoid.cartesianToCartographic(position, scratchPosCartographic); + var prevPositionCartographic = ellipsoid.cartesianToCartographic(previousPosition, scratchPrevCartographic); + var nextPositionCartographic = ellipsoid.cartesianToCartographic(nextPosition, scratchNextCartographic); + + var cartographicEpsilon = CesiumMath.EPSILON14; + var prevLongitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.longitude, prevPositionCartographic.longitude, cartographicEpsilon); + var prevLatitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.latitude, prevPositionCartographic.latitude, cartographicEpsilon); + var nextLongitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.longitude, nextPositionCartographic.longitude, cartographicEpsilon); + var nextLatitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.latitude, nextPositionCartographic.latitude, cartographicEpsilon); + + var longitudeEquality = prevLongitudeEquality && nextLongitudeEquality; + var latitudeEquality = prevLatitudeEquality && nextLatitudeEquality; + var doCorner = !longitudeEquality && !latitudeEquality; + if (doCorner) { cornerDirection = Cartesian3.cross(cornerDirection, surfaceNormal, cornerDirection); cornerDirection = Cartesian3.cross(surfaceNormal, cornerDirection, cornerDirection); From c9bbf56e1606cb23bee45c47c95319465e34ed87 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 26 Feb 2015 18:57:42 -0500 Subject: [PATCH 3/5] Use better solution for determing if the corridor geometry is straight at a point. --- Source/Core/CorridorGeometryLibrary.js | 25 +++++++------------- Source/Core/PolylineVolumeGeometryLibrary.js | 23 +++++++----------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/Source/Core/CorridorGeometryLibrary.js b/Source/Core/CorridorGeometryLibrary.js index 1c78ec60eb18..d937443a23c1 100644 --- a/Source/Core/CorridorGeometryLibrary.js +++ b/Source/Core/CorridorGeometryLibrary.js @@ -1,7 +1,6 @@ /*global define*/ define([ './Cartesian3', - './Cartographic', './CornerType', './defined', './isArray', @@ -12,7 +11,6 @@ define([ './Quaternion' ], function( Cartesian3, - Cartographic, CornerType, defined, isArray, @@ -162,9 +160,8 @@ define([ return positions; } - var scratchPrevCartographic = new Cartographic(); - var scratchPosCartographic = new Cartographic(); - var scratchNextCartographic = new Cartographic(); + var scratchForwardProjection = new Cartesian3(); + var scratchBackwardProjection = new Cartesian3(); /** * @private @@ -214,19 +211,15 @@ define([ forward = Cartesian3.normalize(Cartesian3.subtract(nextPosition, position, forward), forward); cornerDirection = Cartesian3.normalize(Cartesian3.add(forward, backward, cornerDirection), cornerDirection); - var positionCartographic = ellipsoid.cartesianToCartographic(position, scratchPosCartographic); - var prevPositionCartographic = ellipsoid.cartesianToCartographic(previousPos, scratchPrevCartographic); - var nextPositionCartographic = ellipsoid.cartesianToCartographic(nextPosition, scratchNextCartographic); + var forwardProjection = Cartesian3.multiplyByScalar(normal, Cartesian3.dot(forward, normal), scratchForwardProjection); + Cartesian3.subtract(forward, forwardProjection, forwardProjection); + Cartesian3.normalize(forwardProjection, forwardProjection); - var cartographicEpsilon = CesiumMath.EPSILON14; - var prevLongitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.longitude, prevPositionCartographic.longitude, cartographicEpsilon); - var prevLatitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.latitude, prevPositionCartographic.latitude, cartographicEpsilon); - var nextLongitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.longitude, nextPositionCartographic.longitude, cartographicEpsilon); - var nextLatitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.latitude, nextPositionCartographic.latitude, cartographicEpsilon); + var backwardProjection = Cartesian3.multiplyByScalar(normal, Cartesian3.dot(backward, normal), scratchBackwardProjection); + Cartesian3.subtract(backward, backwardProjection, backwardProjection); + Cartesian3.normalize(backwardProjection, backwardProjection); - var longitudeEquality = prevLongitudeEquality && nextLongitudeEquality; - var latitudeEquality = prevLatitudeEquality && nextLatitudeEquality; - var doCorner = !longitudeEquality && !latitudeEquality; + var doCorner = !CesiumMath.equalsEpsilon(Math.abs(Cartesian3.dot(forwardProjection, backwardProjection)), 1.0, CesiumMath.EPSILON1); if (doCorner) { cornerDirection = Cartesian3.cross(cornerDirection, normal, cornerDirection); diff --git a/Source/Core/PolylineVolumeGeometryLibrary.js b/Source/Core/PolylineVolumeGeometryLibrary.js index 08b9e029e297..9df76e151611 100644 --- a/Source/Core/PolylineVolumeGeometryLibrary.js +++ b/Source/Core/PolylineVolumeGeometryLibrary.js @@ -290,9 +290,8 @@ define([ return cleanedPositions; }; - var scratchPrevCartographic = new Cartographic(); - var scratchPosCartographic = new Cartographic(); - var scratchNextCartographic = new Cartographic(); + var scratchForwardProjection = new Cartesian3(); + var scratchBackwardProjection = new Cartesian3(); PolylineVolumeGeometryLibrary.computePositions = function(positions, shape2D, boundingRectangle, geometry, duplicatePoints) { var ellipsoid = geometry._ellipsoid; @@ -343,19 +342,15 @@ define([ cornerDirection = Cartesian3.normalize(cornerDirection, cornerDirection); surfaceNormal = ellipsoid.geodeticSurfaceNormal(position, surfaceNormal); - var positionCartographic = ellipsoid.cartesianToCartographic(position, scratchPosCartographic); - var prevPositionCartographic = ellipsoid.cartesianToCartographic(previousPosition, scratchPrevCartographic); - var nextPositionCartographic = ellipsoid.cartesianToCartographic(nextPosition, scratchNextCartographic); + var forwardProjection = Cartesian3.multiplyByScalar(surfaceNormal, Cartesian3.dot(forward, surfaceNormal), scratchForwardProjection); + Cartesian3.subtract(forward, forwardProjection, forwardProjection); + Cartesian3.normalize(forwardProjection, forwardProjection); - var cartographicEpsilon = CesiumMath.EPSILON14; - var prevLongitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.longitude, prevPositionCartographic.longitude, cartographicEpsilon); - var prevLatitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.latitude, prevPositionCartographic.latitude, cartographicEpsilon); - var nextLongitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.longitude, nextPositionCartographic.longitude, cartographicEpsilon); - var nextLatitudeEquality = CesiumMath.equalsEpsilon(positionCartographic.latitude, nextPositionCartographic.latitude, cartographicEpsilon); + var backwardProjection = Cartesian3.multiplyByScalar(surfaceNormal, Cartesian3.dot(backward, surfaceNormal), scratchBackwardProjection); + Cartesian3.subtract(backward, backwardProjection, backwardProjection); + Cartesian3.normalize(backwardProjection, backwardProjection); - var longitudeEquality = prevLongitudeEquality && nextLongitudeEquality; - var latitudeEquality = prevLatitudeEquality && nextLatitudeEquality; - var doCorner = !longitudeEquality && !latitudeEquality; + var doCorner = !CesiumMath.equalsEpsilon(Math.abs(Cartesian3.dot(forwardProjection, backwardProjection)), 1.0, CesiumMath.EPSILON1); if (doCorner) { cornerDirection = Cartesian3.cross(cornerDirection, surfaceNormal, cornerDirection); From 05d356c27ca093b13ef8a56832fc8542e2dacc59 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Thu, 26 Feb 2015 20:07:22 -0500 Subject: [PATCH 4/5] Add tests. --- Specs/Core/CorridorGeometrySpec.js | 17 +++++++++++++++++ Specs/Core/PolylineVolumeGeometrySpec.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Specs/Core/CorridorGeometrySpec.js b/Specs/Core/CorridorGeometrySpec.js index d283bda6076e..1a6a3bdea42a 100644 --- a/Specs/Core/CorridorGeometrySpec.js +++ b/Specs/Core/CorridorGeometrySpec.js @@ -180,6 +180,23 @@ defineSuite([ expect(m.indices.length).toEqual(3 * 8); }); + it('computes straight corridors', function() { + var m = CorridorGeometry.createGeometry(new CorridorGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + positions : Cartesian3.fromDegreesArray([ + -67.655, 0.0, + -67.655, 15.0, + -67.655, 20.0 + ]), + cornerType: CornerType.BEVELED, + width : 400000, + granularity : Math.PI / 6.0 + })); + + expect(m.attributes.position.values.length).toEqual(3 * 4); + expect(m.indices.length).toEqual(3 * 2); + }); + var positions = Cartesian3.fromDegreesArray([ 90.0, -30.0, 90.0, -31.0 diff --git a/Specs/Core/PolylineVolumeGeometrySpec.js b/Specs/Core/PolylineVolumeGeometrySpec.js index 1bae1ed4d866..973d03065ba5 100644 --- a/Specs/Core/PolylineVolumeGeometrySpec.js +++ b/Specs/Core/PolylineVolumeGeometrySpec.js @@ -169,6 +169,23 @@ defineSuite([ expect(m.indices.length).toEqual(3 * (8 * 2 + 4 * 7 * 2 + 4)); }); + it('computes straight volume', function() { + var m = PolylineVolumeGeometry.createGeometry(new PolylineVolumeGeometry({ + vertexFormat : VertexFormat.POSITION_ONLY, + polylinePositions : Cartesian3.fromDegreesArray([ + -67.655, 0.0, + -67.655, 15.0, + -67.655, 20.0 + ]), + cornerType: CornerType.BEVELED, + shapePositions: shape, + granularity : Math.PI / 6.0 + })); + + expect(m.attributes.position.values.length).toEqual(3 * 32); + expect(m.indices.length).toEqual(3 * 20); + }); + var positions = [new Cartesian3(1.0, 0.0, 0.0), new Cartesian3(0.0, 1.0, 0.0), new Cartesian3(0.0, 0.0, 1.0)]; var volumeShape = [new Cartesian2(0.0, 0.0), new Cartesian2(1.0, 0.0), new Cartesian2(0.0, 1.0)]; var volume = new PolylineVolumeGeometry({ From 200042c6ef26c5449995efbf55ca92b748052574 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Fri, 27 Feb 2015 11:21:34 -0500 Subject: [PATCH 5/5] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index a7cd37ccf261..40441451e1b3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Change Log * Removed `Camera.heading` and `Camera.tilt`. They were deprecated in Cesium 1.6. Use `Camera.setView`. * Removed `Camera.setPositionCartographic`, which was was deprecated in Cesium 1.6. Use `Camera.setView`. * Fixed incorrect ellipse texture coordinates. [#2363](https://github.com/AnalyticalGraphicsInc/cesium/issues/2363) and [#2465](https://github.com/AnalyticalGraphicsInc/cesium/issues/2465) +* Fixed a bug that would cause incorrect geometry for long Corridors and Polyline Volumes. [#2513](https://github.com/AnalyticalGraphicsInc/cesium/issues/2513) * Fixed a bug in imagery loading that could cause some or all of the globe to be missing when using an imagery layer that does not cover the entire globe. * Added support for rendering a water effect on Quantized-Mesh terrain tiles. * Added `pack` and `unpack` functions to `Matrix2` and `Matrix3`.