Skip to content

Commit

Permalink
Merge pull request #2445 from AnalyticalGraphicsInc/entity-zoom-2d
Browse files Browse the repository at this point in the history
EntityView 2D rotation
  • Loading branch information
mramato committed Jan 30, 2015
2 parents 1eef93a + b6a02d7 commit 9c45a71
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
24 changes: 13 additions & 11 deletions Source/DataSources/EntityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define([
'../Core/Matrix3',
'../Core/Matrix4',
'../Core/Transforms',
'../Scene/HeadingPitchRange',
'../Scene/SceneMode'
], function(
BoundingSphere,
Expand All @@ -26,6 +27,7 @@ define([
Matrix3,
Matrix4,
Transforms,
HeadingPitchRange,
SceneMode) {
"use strict";

Expand Down Expand Up @@ -160,9 +162,11 @@ define([
Transforms.eastNorthUpToFixedFrame(cartesian, ellipsoid, transform);
}

var offset = mode === SceneMode.SCENE2D ? that._offset2D : that._offset3D;
if (Cartesian3.equals(offset, Cartesian3.ZERO)) {
var offset;
if ((mode === SceneMode.SCENE2D && that._offset2D.range === 0.0) || (mode !== SceneMode.SCENE2D && Cartesian3.equals(that._offset3D, Cartesian3.ZERO))) {
offset = undefined;
} else {
offset = mode === SceneMode.SCENE2D ? that._offset2D : that._offset3D;
}

camera.lookAtTransform(transform, offset);
Expand Down Expand Up @@ -220,9 +224,7 @@ define([
this._lastCartesian = new Cartesian3();

this._offset3D = new Cartesian3();
this._up3D = new Cartesian3();
this._offset2D = new Cartesian3();
this._up2D = new Cartesian3();
this._offset2D = new HeadingPitchRange();
};

// STATIC properties defined here, not per-instance.
Expand All @@ -239,7 +241,7 @@ define([
},
set : function(vector) {
this._defaultOffset3D = Cartesian3.clone(vector, new Cartesian3());
this._defaultOffset2D = new Cartesian3(0.0, 0.0, Cartesian3.magnitude(this._defaultOffset3D));
this._defaultOffset2D = new HeadingPitchRange(0.0, 0.0, Cartesian3.magnitude(this._defaultOffset3D));
}
}
});
Expand Down Expand Up @@ -296,16 +298,16 @@ define([
this._boundingSphereOffset = Cartesian3.subtract(sphere.center, entity.position.getValue(time), new Cartesian3());
updateLookAt = false;
} else if (!defined(viewFromProperty) || !defined(viewFromProperty.getValue(time, offset3D))) {
Cartesian3.clone(EntityView._defaultOffset2D, offset2D);
HeadingPitchRange.clone(EntityView._defaultOffset2D, offset2D);
Cartesian3.clone(EntityView._defaultOffset3D, offset3D);
} else {
var mag = Cartesian3.magnitude(offset3D);
Cartesian3.fromElements(0.0, 0.0, mag, offset2D);
offset2D.heading = 0.0;
offset2D.range = Cartesian3.magnitude(offset3D);
}
} else if (!sceneModeChanged && scene.mode !== SceneMode.MORPHING) {
if (this._mode === SceneMode.SCENE2D) {
var distance = Math.max(camera.frustum.right - camera.frustum.left, camera.frustum.top - camera.frustum.bottom) * 0.5;
Cartesian3.fromElements(0.0, 0.0, distance, offset2D);
offset2D.heading = camera.heading;
offset2D.range = Math.max(camera.frustum.right - camera.frustum.left, camera.frustum.top - camera.frustum.bottom) * 0.5;
} else if (this._mode === SceneMode.SCENE3D || this._mode === SceneMode.COLUMBUS_VIEW) {
Cartesian3.clone(camera.position, offset3D);
}
Expand Down
27 changes: 26 additions & 1 deletion Source/Scene/HeadingPitchRange.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/*global define*/
define(['../Core/defaultValue'], function(defaultValue) {
define(['../Core/defaultValue',
'../Core/defined'],
function(
defaultValue,
defined) {
"use strict";

/**
Expand Down Expand Up @@ -35,5 +39,26 @@ define(['../Core/defaultValue'], function(defaultValue) {
this.range = defaultValue(range, 0.0);
};

/**
* Duplicates a HeadingPitchRange instance.
*
* @param {HeadingPitchRange} hpr The HeadingPitchRange to duplicate.
* @param {HeadingPitchRange} [result] The object onto which to store the result.
* @returns {HeadingPitchRange} The modified result parameter or a new HeadingPitchRange instance if one was not provided. (Returns undefined if hpr is undefined)
*/
HeadingPitchRange.clone = function(hpr, result) {
if (!defined(hpr)) {
return undefined;
}
if (!defined(result)) {
result = new HeadingPitchRange();
}

result.heading = hpr.heading;
result.pitch = hpr.pitch;
result.range = hpr.range;
return result;
};

return HeadingPitchRange;
});
35 changes: 35 additions & 0 deletions Specs/Scene/HeadingPitchRangeSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*global defineSuite*/
defineSuite(['Scene/HeadingPitchRange'], function(HeadingPitchRange) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/

it('construct with default values', function() {
var hpr = new HeadingPitchRange();
expect(hpr.heading).toEqual(0.0);
expect(hpr.pitch).toEqual(0.0);
expect(hpr.range).toEqual(0.0);
});

it('construct with all values', function() {
var hpr = new HeadingPitchRange(1.0, 2.0, 3.0);
expect(hpr.heading).toEqual(1.0);
expect(hpr.pitch).toEqual(2.0);
expect(hpr.range).toEqual(3.0);
});

it('clone with a result parameter', function() {
var hpr = new HeadingPitchRange(1.0, 2.0, 3.0);
var result = new HeadingPitchRange();
var returnedResult = HeadingPitchRange.clone(hpr, result);
expect(hpr).toNotBe(result);
expect(result).toBe(returnedResult);
expect(hpr).toEqual(result);
});

it('clone works with a result parameter that is an input parameter', function() {
var hpr = new HeadingPitchRange(1.0, 2.0, 3.0);
var returnedResult = HeadingPitchRange.clone(hpr, hpr);
expect(hpr).toBe(returnedResult);
});

});

0 comments on commit 9c45a71

Please sign in to comment.