diff --git a/CHANGES.md b/CHANGES.md index 900440b2f9f8..5af76e8a45d8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Beta Releases * Improved the quality of imagery near the poles when the imagery source uses a `GeographicTilingScheme`. * `CesiumTerrainProvider` now supports mesh-based terrain like the tiles created by STK Terrain Server. * Added `Intersections2D` class containing operations on 2D triangles. +* Fixed viewing an extent. [#1431](https://github.com/AnalyticalGraphicsInc/cesium/issues/1431) * Use `performance.now()` instead of `Date.now()`, when available, to limit time spent loading terrain and imagery tiles. This results in more consistent frame rates while loading tiles on some systems. * Added the ability for imagery providers to specify view-dependent attribution to be display in the `CreditDisplay`. * View-dependent imagery source attribution is now added to the `CreditDisplay` by the `BingMapsImageryProvider`. diff --git a/Source/Scene/CameraController.js b/Source/Scene/CameraController.js index 5178369ea7f1..dc85bdeee682 100644 --- a/Source/Scene/CameraController.js +++ b/Source/Scene/CameraController.js @@ -979,28 +979,24 @@ define([ Cartesian3.multiplyByScalar(center, 0.5, center); Cartesian3.add(southWest, center, center); + var mag = Cartesian3.magnitude(center); + if (mag < CesiumMath.EPSILON6) { + cart.longitude = (east + west) * 0.5; + cart.latitude = (north + south) * 0.5; + ellipsoid.cartographicToCartesian(cart, center); + } + Cartesian3.subtract(northWest, center, northWest); Cartesian3.subtract(southEast, center, southEast); Cartesian3.subtract(northEast, center, northEast); Cartesian3.subtract(southWest, center, southWest); - cart.longitude = east; - cart.latitude = (north + south) * 0.5; - var midEast = ellipsoid.cartographicToCartesian(cart, cameraRF.direction); - cart.longitude = west; - var right = ellipsoid.cartographicToCartesian(cart, cameraRF.right); - Cartesian3.subtract(midEast, right, right); + var direction = ellipsoid.geodeticSurfaceNormal(center, cameraRF.direction); + Cartesian3.negate(direction, direction); + Cartesian3.normalize(direction, direction); + var right = Cartesian3.cross(direction, Cartesian3.UNIT_Z, cameraRF.right); Cartesian3.normalize(right, right); - - cart.longitude = (east + west) * 0.5; - cart.latitude = north; - var midNorth = ellipsoid.cartographicToCartesian(cart, cameraRF.direction); - cart.latitude = south; - var up = ellipsoid.cartographicToCartesian(cart, cameraRF.up); - Cartesian3.subtract(midNorth, up, up); - Cartesian3.normalize(up, up); - - var direction = Cartesian3.cross(up, right, cameraRF.direction); + var up = Cartesian3.cross(right, direction, cameraRF.up); var height = Math.max( Math.abs(Cartesian3.dot(up, northWest)), @@ -1019,22 +1015,8 @@ define([ var tanTheta = camera.frustum.aspectRatio * tanPhi; var d = Math.max(width / tanTheta, height / tanPhi); - if (!defined(result)) { - result = new Cartesian3(); - } - - var mag = Cartesian3.magnitude(center); var scalar = mag + d; - - if (mag < CesiumMath.EPSILON6) { - cart.longitude = (east + west) * 0.5; - cart.latitude = (north + south) * 0.5; - ellipsoid.cartographicToCartesian(cart, center); - Cartesian3.normalize(center, center); - } else { - Cartesian3.normalize(center, center); - } - + Cartesian3.normalize(center, center); return Cartesian3.multiplyByScalar(center, scalar, result); } diff --git a/Specs/Scene/CameraControllerSpec.js b/Specs/Scene/CameraControllerSpec.js index 86e98385bf63..f7c781a47cca 100644 --- a/Specs/Scene/CameraControllerSpec.js +++ b/Specs/Scene/CameraControllerSpec.js @@ -541,7 +541,7 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('views extent in 3D', function() { + it('views extent in 3D (1)', function() { var extent = new Extent( -Math.PI, -CesiumMath.PI_OVER_TWO, @@ -554,6 +554,32 @@ defineSuite([ expect(camera.right).toEqualEpsilon(Cartesian3.UNIT_Y, CesiumMath.EPSILON10); }); + it('views extent in 3D (2)', function() { + var extent = new Extent( + CesiumMath.toRadians(21.25), + CesiumMath.toRadians(41.23), + CesiumMath.toRadians(21.51), + CesiumMath.toRadians(41.38)); + controller.viewExtent(extent, Ellipsoid.WGS84); + expect(camera.position).toEqualEpsilon(new Cartesian3(4478207.335705587, 1753173.8165311918, 4197410.895448539), CesiumMath.EPSILON6); + expect(camera.direction).toEqualEpsilon(new Cartesian3(-0.6995107725362416, -0.2738515389883838, -0.6600681886740524), CesiumMath.EPSILON10); + expect(camera.up).toEqualEpsilon(new Cartesian3(-0.6146449843355883, -0.24062742347984528, 0.7512056884106748), CesiumMath.EPSILON10); + expect(camera.right).toEqualEpsilon(new Cartesian3(-0.36454934142973716, 0.9311840729217532, 0.0), CesiumMath.EPSILON10); + }); + + it('views extent in 3D (3)', function() { + var extent = new Extent( + CesiumMath.toRadians(90.0), + CesiumMath.toRadians(-50.0), + CesiumMath.toRadians(157.0), + CesiumMath.toRadians(0.0)); + controller.viewExtent(extent); + expect(camera.position).toEqualEpsilon(new Cartesian3(-6141929.663019788, 6904446.963087202, -5087100.779249599), CesiumMath.EPSILON6); + expect(camera.direction).toEqualEpsilon(new Cartesian3(0.5813363216621468, -0.6535089167170689, 0.48474135050314004), CesiumMath.EPSILON10); + expect(camera.up).toEqualEpsilon(new Cartesian3(-0.3221806693208934, 0.3621792280122498, 0.8746575461930182), CesiumMath.EPSILON10); + expect(camera.right).toEqualEpsilon(new Cartesian3(-0.7471597536218517, -0.6646444933705039, 0.0), CesiumMath.EPSILON10); + }); + it('views extent in 3D across IDL', function() { var extent = new Extent( 0.1,