diff --git a/Source/DataSources/EntityView.js b/Source/DataSources/EntityView.js index 10ce4422c855..1fc33689fcaf 100644 --- a/Source/DataSources/EntityView.js +++ b/Source/DataSources/EntityView.js @@ -12,6 +12,7 @@ define([ '../Core/Matrix3', '../Core/Matrix4', '../Core/Transforms', + '../Scene/HeadingPitchRange', '../Scene/SceneMode' ], function( BoundingSphere, @@ -26,6 +27,7 @@ define([ Matrix3, Matrix4, Transforms, + HeadingPitchRange, SceneMode) { "use strict"; @@ -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); @@ -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. @@ -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)); } } }); @@ -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); } diff --git a/Source/Scene/HeadingPitchRange.js b/Source/Scene/HeadingPitchRange.js index a43ec7f7c917..e183f6e263c2 100644 --- a/Source/Scene/HeadingPitchRange.js +++ b/Source/Scene/HeadingPitchRange.js @@ -1,5 +1,9 @@ /*global define*/ -define(['../Core/defaultValue'], function(defaultValue) { +define(['../Core/defaultValue', + '../Core/defined'], + function( + defaultValue, + defined) { "use strict"; /** @@ -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; }); diff --git a/Specs/Scene/HeadingPitchRangeSpec.js b/Specs/Scene/HeadingPitchRangeSpec.js new file mode 100644 index 000000000000..db0458c0fb6e --- /dev/null +++ b/Specs/Scene/HeadingPitchRangeSpec.js @@ -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); + }); + +}); \ No newline at end of file