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

Camera Fix #3810

Merged
merged 5 commits into from
Apr 6, 2016
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 @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this line because it wasn't actually doing anything. It only passed before because (0,0,-0.999999) did not equal (0,0,-1.0). Or maybe it should be checking .toEqual instead of .not.toEqual?

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