Skip to content

Commit

Permalink
Merge pull request #2118 from AnalyticalGraphicsInc/default-entityView
Browse files Browse the repository at this point in the history
Add a function to set the default EntityView vector.
  • Loading branch information
mramato committed Sep 15, 2014
2 parents b03beb0 + 5ff15b5 commit 77515a4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
44 changes: 33 additions & 11 deletions Source/DataSources/EntityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ define([
'../Core/Cartesian3',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
'../Core/DeveloperError',
'../Core/Ellipsoid',
'../Core/JulianDate',
Expand All @@ -14,6 +15,7 @@ define([
Cartesian3,
defaultValue,
defined,
defineProperties,
DeveloperError,
Ellipsoid,
JulianDate,
Expand Down Expand Up @@ -191,19 +193,39 @@ define([
//Re-usable objects to be used for retrieving position.
this._lastCartesian = new Cartesian3();

this._defaultOffset3D = new Cartesian3(-10000, 2500, 2500);
this._defaultUp3D = Cartesian3.cross(this._defaultOffset3D, Cartesian3.cross(Cartesian3.UNIT_Z, this._defaultOffset3D, offset3DCrossScratch), new Cartesian3());
Cartesian3.normalize(this._defaultUp3D, this._defaultUp3D);

this._defaultOffset2D = new Cartesian3(0.0, 0.0, Cartesian3.magnitude(this._defaultOffset3D));
this._defaultUp2D = Cartesian3.clone(Cartesian3.UNIT_Y);

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

// STATIC properties defined here, not per-instance.
defineProperties(EntityView, {
/**
* Gets or sets a camera offset that will be used to
* initialize subsequent EntityViews.
* @memberof EntityView
* @type {Cartesian3}
*/
defaultOffset3D : {
get : function() {
return this._defaultOffset3D;
},
set : function(vector) {
this._defaultOffset3D = Cartesian3.clone(vector, new Cartesian3());
this._defaultUp3D = Cartesian3.cross(this._defaultOffset3D, Cartesian3.cross(Cartesian3.UNIT_Z,
this._defaultOffset3D, offset3DCrossScratch), new Cartesian3());
Cartesian3.normalize(this._defaultUp3D, this._defaultUp3D);

this._defaultOffset2D = new Cartesian3(0.0, 0.0, Cartesian3.magnitude(this._defaultOffset3D));
this._defaultUp2D = Cartesian3.clone(Cartesian3.UNIT_Y);
}
}
});

// Initialize the static property.
EntityView.defaultOffset3D = new Cartesian3(-14000, 3500, 3500);

/**
* Should be called each animation frame to update the camera
* to the latest settings.
Expand Down Expand Up @@ -246,10 +268,10 @@ define([
if (objectChanged) {
var viewFromProperty = entity.viewFrom;
if (!defined(viewFromProperty) || !defined(viewFromProperty.getValue(time, offset3D))) {
Cartesian3.clone(this._defaultOffset2D, offset2D);
Cartesian3.clone(this._defaultUp2D, up2D);
Cartesian3.clone(this._defaultOffset3D, offset3D);
Cartesian3.clone(this._defaultUp3D, up3D);
Cartesian3.clone(EntityView._defaultOffset2D, offset2D);
Cartesian3.clone(EntityView._defaultUp2D, up2D);
Cartesian3.clone(EntityView._defaultOffset3D, offset3D);
Cartesian3.clone(EntityView._defaultUp3D, up3D);
} else {
Cartesian3.cross(Cartesian3.UNIT_Z, offset3D, up3D);
Cartesian3.cross(offset3D, up3D, up3D);
Expand Down
11 changes: 11 additions & 0 deletions Specs/DataSources/EntityViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ defineSuite([
expect(view.ellipsoid).toBe(Ellipsoid.UNIT_SPHERE);
});

it('can set and get defaultOffset3D', function() {
var sampleOffset = new Cartesian3(1, 2, 3);
EntityView.defaultOffset3D = sampleOffset;
var entity = new Entity();
entity.position = new ConstantPositionProperty(Cartesian3.ZERO);
var view = new EntityView(entity, scene);
view.update(JulianDate.now());
expect(Cartesian3.equalsEpsilon(EntityView.defaultOffset3D, sampleOffset, 1e-10)).toBe(true);
expect(Cartesian3.equalsEpsilon(view.scene.camera.position, sampleOffset, 1e-10)).toBe(true);
});

it('update throws without time parameter', function() {
var entity = new Entity();
entity.position = new ConstantPositionProperty(Cartesian3.ZERO);
Expand Down

0 comments on commit 77515a4

Please sign in to comment.