Skip to content

Commit

Permalink
make entity model matrix computation public
Browse files Browse the repository at this point in the history
  • Loading branch information
rahwang committed Jul 11, 2017
1 parent 722cc42 commit 7e6edb0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Source/DataSources/BoxGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ define([
return new GeometryInstance({
id : entity,
geometry : BoxGeometry.fromDimensions(this._options),
modelMatrix : entity._getModelMatrix(Iso8601.MINIMUM_VALUE),
modelMatrix : entity.computeModelMatrix(Iso8601.MINIMUM_VALUE),
attributes : attributes
});
};
Expand Down Expand Up @@ -394,7 +394,7 @@ define([
return new GeometryInstance({
id : entity,
geometry : BoxOutlineGeometry.fromDimensions(this._options),
modelMatrix : entity._getModelMatrix(Iso8601.MINIMUM_VALUE),
modelMatrix : entity.computeModelMatrix(Iso8601.MINIMUM_VALUE),
attributes : {
show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
color : ColorGeometryInstanceAttribute.fromColor(outlineColor),
Expand Down Expand Up @@ -555,7 +555,7 @@ define([
}

var options = this._options;
var modelMatrix = entity._getModelMatrix(time);
var modelMatrix = entity.computeModelMatrix(time);
var dimensions = Property.getValueOrUndefined(box.dimensions, time, options.dimensions);
if (!defined(modelMatrix) || !defined(dimensions)) {
return;
Expand Down
6 changes: 3 additions & 3 deletions Source/DataSources/CylinderGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ define([
return new GeometryInstance({
id : entity,
geometry : new CylinderGeometry(this._options),
modelMatrix : entity._getModelMatrix(Iso8601.MINIMUM_VALUE),
modelMatrix : entity.computeModelMatrix(Iso8601.MINIMUM_VALUE),
attributes : attributes
});
};
Expand Down Expand Up @@ -399,7 +399,7 @@ define([
return new GeometryInstance({
id : entity,
geometry : new CylinderOutlineGeometry(this._options),
modelMatrix : entity._getModelMatrix(Iso8601.MINIMUM_VALUE),
modelMatrix : entity.computeModelMatrix(Iso8601.MINIMUM_VALUE),
attributes : {
show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
color : ColorGeometryInstanceAttribute.fromColor(outlineColor),
Expand Down Expand Up @@ -573,7 +573,7 @@ define([
}

var options = this._options;
var modelMatrix = entity._getModelMatrix(time);
var modelMatrix = entity.computeModelMatrix(time);
var length = Property.getValueOrUndefined(cylinder.length, time);
var topRadius = Property.getValueOrUndefined(cylinder.topRadius, time);
var bottomRadius = Property.getValueOrUndefined(cylinder.bottomRadius, time);
Expand Down
6 changes: 3 additions & 3 deletions Source/DataSources/EllipsoidGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ define([
return new GeometryInstance({
id : entity,
geometry : new EllipsoidGeometry(this._options),
modelMatrix : entity._getModelMatrix(Iso8601.MINIMUM_VALUE),
modelMatrix : entity.computeModelMatrix(Iso8601.MINIMUM_VALUE),
attributes : attributes
});
};
Expand Down Expand Up @@ -407,7 +407,7 @@ define([
return new GeometryInstance({
id : entity,
geometry : new EllipsoidOutlineGeometry(this._options),
modelMatrix : entity._getModelMatrix(Iso8601.MINIMUM_VALUE),
modelMatrix : entity.computeModelMatrix(Iso8601.MINIMUM_VALUE),
attributes : {
show : new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time)),
color : ColorGeometryInstanceAttribute.fromColor(outlineColor),
Expand Down Expand Up @@ -589,7 +589,7 @@ define([
}

var radii = Property.getValueOrUndefined(ellipsoid.radii, time, radiiScratch);
var modelMatrix = entity._getModelMatrix(time, this._modelMatrix);
var modelMatrix = entity.computeModelMatrix(time, this._modelMatrix);
if (!defined(modelMatrix) || !defined(radii)) {
if (defined(this._primitive)) {
this._primitive.show = false;
Expand Down
9 changes: 7 additions & 2 deletions Source/DataSources/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,14 @@ define([
var orientationScratch = new Quaternion();

/**
* @private
* Computes the model matrix for the entity's transform at specified time.
*
* @param {JulianDate} time The time to retrieve model matrix for.
* @param {Matrix4} [result] The object onto which to store the result.
*
* @returns {Matrix4} The modified result parameter or a new Matrix4 instance if one was not provided.
*/
Entity.prototype._getModelMatrix = function(time, result) {
Entity.prototype.computeModelMatrix = function(time, result) {
var position = Property.getValueOrUndefined(this._position, time, positionScratch);
if (!defined(position)) {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/ModelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ define([

var modelMatrix;
if (show) {
modelMatrix = entity._getModelMatrix(time, modelMatrixScratch);
modelMatrix = entity.computeModelMatrix(time, modelMatrixScratch);
uri = Property.getValueOrUndefined(modelGraphics._uri, time);
show = defined(modelMatrix) && defined(uri);
}
Expand Down
16 changes: 8 additions & 8 deletions Specs/DataSources/EntitySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ defineSuite([
}).toThrowDeveloperError();
});

it('_getModelMatrix returns undefined when position is undefined.', function() {
it('computeModelMatrix returns undefined when position is undefined.', function() {
var entity = new Entity();
entity.orientation = new ConstantProperty(Quaternion.IDENTITY);
expect(entity._getModelMatrix(new JulianDate())).toBeUndefined();
expect(entity.computeModelMatrix(new JulianDate())).toBeUndefined();
});

it('_getModelMatrix returns correct value.', function() {
it('computeModelMatrix returns correct value.', function() {
var entity = new Entity();

var position = new Cartesian3(123456, 654321, 123456);
Expand All @@ -257,28 +257,28 @@ defineSuite([
entity.position = new ConstantProperty(position);
entity.orientation = new ConstantProperty(orientation);

var modelMatrix = entity._getModelMatrix(new JulianDate());
var modelMatrix = entity.computeModelMatrix(new JulianDate());
var expected = Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(orientation), position);
expect(modelMatrix).toEqual(expected);
});

it('_getModelMatrix returns ENU when quaternion is undefined.', function() {
it('computeModelMatrix returns ENU when quaternion is undefined.', function() {
var entity = new Entity();
var position = new Cartesian3(123456, 654321, 123456);
entity.position = new ConstantProperty(position);

var modelMatrix = entity._getModelMatrix(new JulianDate());
var modelMatrix = entity.computeModelMatrix(new JulianDate());
var expected = Transforms.eastNorthUpToFixedFrame(position);
expect(modelMatrix).toEqual(expected);
});

it('_getModelMatrix works with result parameter.', function() {
it('computeModelMatrix works with result parameter.', function() {
var entity = new Entity();
var position = new Cartesian3(123456, 654321, 123456);
entity.position = new ConstantProperty(position);

var result = new Matrix4();
var modelMatrix = entity._getModelMatrix(new JulianDate(), result);
var modelMatrix = entity.computeModelMatrix(new JulianDate(), result);
var expected = Transforms.eastNorthUpToFixedFrame(position);
expect(modelMatrix).toBe(result);
expect(modelMatrix).toEqual(expected);
Expand Down

0 comments on commit 7e6edb0

Please sign in to comment.