Skip to content

Commit

Permalink
Merge pull request #3810 from AnalyticalGraphicsInc/camera-fix
Browse files Browse the repository at this point in the history
Camera Fix
  • Loading branch information
bagnell committed Apr 6, 2016
2 parents c9a948f + 54b697a commit fa46306
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Change Log
*
* Fixed issue causing the sun not to render. [#3801](https://github.com/AnalyticalGraphicsInc/cesium/pull/3801)
* Fixed issue where `Camera.flyTo` does not go to the rectangle. [#3688](https://github.com/AnalyticalGraphicsInc/cesium/issues/3688)
* Fixed issue causing the fog to go dark and the atmosphere to flicker when the camera clips the globe. [#3178](https://github.com/AnalyticalGraphicsInc/cesium/issues/3178)

### 1.20 - 2016-04-01

Expand Down
6 changes: 3 additions & 3 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,18 +422,21 @@ define([
var direction = camera._direction;
var directionChanged = !Cartesian3.equals(direction, camera.direction);
if (directionChanged) {
Cartesian3.normalize(camera.direction, camera.direction);
direction = Cartesian3.clone(camera.direction, camera._direction);
}

var up = camera._up;
var upChanged = !Cartesian3.equals(up, camera.up);
if (upChanged) {
Cartesian3.normalize(camera.up, camera.up);
up = Cartesian3.clone(camera.up, camera._up);
}

var right = camera._right;
var rightChanged = !Cartesian3.equals(right, camera.right);
if (rightChanged) {
Cartesian3.normalize(camera.right, camera.right);
right = Cartesian3.clone(camera.right, camera._right);
}

Expand Down Expand Up @@ -491,9 +494,6 @@ define([
var det = Cartesian3.dot(direction, Cartesian3.cross(up, right, scratchCartesian));
if (Math.abs(1.0 - det) > CesiumMath.EPSILON2) {
//orthonormalize axes
direction = Cartesian3.normalize(direction, camera._direction);
Cartesian3.clone(direction, camera.direction);

var invUpMag = 1.0 / Cartesian3.magnitudeSquared(up);
var scalar = Cartesian3.dot(up, direction) * invUpMag;
var w0 = Cartesian3.multiplyByScalar(direction, scalar, scratchCartesian);
Expand Down
18 changes: 18 additions & 0 deletions Specs/Scene/CameraSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ defineSuite([
expect(expected).toEqual(camera.inverseTransform);
});

it('Computes orthonormal direction, up, and right vectors', function() {
camera.direction = new Cartesian3(-0.32297853365047874, 0.9461560708446421, 0.021761351171635013);
camera.up = new Cartesian3(0.9327219113001013, 0.31839266745173644, -2.9874778345595487e-10);
camera.right = new Cartesian3(0.0069286549295528715, -0.020297288960790985, 0.9853344956450351);

expect(Cartesian3.magnitude(camera.right)).not.toEqualEpsilon(1.0, CesiumMath.EPSILON8);
expect(Cartesian3.magnitude(camera.up)).not.toEqualEpsilon(1.0, CesiumMath.EPSILON8);

// Trigger updateMembers which normalizes the axes
var viewMatrix = camera.viewMatrix;
expect(Cartesian3.magnitude(camera.right)).toEqualEpsilon(1.0, CesiumMath.EPSILON8);
expect(Cartesian3.magnitude(camera.up)).toEqualEpsilon(1.0, CesiumMath.EPSILON8);

var inverseAffine = Matrix4.inverseTransformation(viewMatrix, new Matrix4());
var inverse = Matrix4.inverse(viewMatrix, new Matrix4());
expect(inverseAffine).toEqualEpsilon(inverse, CesiumMath.EPSILON8);
});

it('get heading is undefined when morphing', function() {
camera._mode = SceneMode.MORPHING;
expect(camera.heading).not.toBeDefined();
Expand Down
1 change: 0 additions & 1 deletion Specs/Scene/ScreenSpaceCameraControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ defineSuite([
moveMouse(MouseButtons.LEFT, startPosition, endPosition, true);
updateController();
expect(camera.position).toEqual(position);
expect(camera.direction).not.toEqual(Cartesian3.normalize(Cartesian3.negate(camera.position, new Cartesian3()), new Cartesian3()));
expect(Cartesian3.cross(camera.direction, camera.up, new Cartesian3())).toEqualEpsilon(camera.right, CesiumMath.EPSILON12);
expect(Cartesian3.cross(camera.up, camera.right, new Cartesian3())).toEqualEpsilon(camera.direction, CesiumMath.EPSILON12);
expect(Cartesian3.cross(camera.right, camera.direction, new Cartesian3())).toEqualEpsilon(camera.up, CesiumMath.EPSILON12);
Expand Down

0 comments on commit fa46306

Please sign in to comment.