Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix view extent #1433

Merged
merged 5 commits into from
Feb 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
44 changes: 13 additions & 31 deletions Source/Scene/CameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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);
}

Expand Down
28 changes: 27 additions & 1 deletion Specs/Scene/CameraControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down