Skip to content

Commit

Permalink
Merge pull request #5133 from AnalyticalGraphicsInc/primitive-boundin…
Browse files Browse the repository at this point in the history
…g-spheres

Fix ellipsoid tracking
  • Loading branch information
emackey authored Mar 28, 2017
2 parents 9db4cfb + bb33c66 commit 482956b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Change Log
* Added support for an orthographic projection in 3D and Columbus view.
* Set `projectionPicker` to `true` in the options when creating a `Viewer` to add a widget that will switch projections. [#5021](https://github.com/AnalyticalGraphicsInc/cesium/pull/5021)
* Call `switchToOrthographicFrustum` or `switchToPerspectiveFrustum` on `Camera` to change projections.
* Fixed an issue with camera tracking of dynamic ellipsoids. [#5133](https://github.com/AnalyticalGraphicsInc/cesium/pull/5133)
* Fix billboard, point and label clustering in 2D and Columbus view. [#5136](https://github.com/AnalyticalGraphicsInc/cesium/pull/5136)
* Fixed issues with imagerySplitPosition and the international date line in 2D mode. [#5151](https://github.com/AnalyticalGraphicsInc/cesium/pull/5151)
* Fixed an issue with `TileBoundingBox` that caused the terrain to disappear in certain places [4032](https://github.com/AnalyticalGraphicsInc/cesium/issues/4032)
Expand Down
36 changes: 20 additions & 16 deletions Source/Scene/Primitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,10 +1165,11 @@ define([
var scratchBoundingSphereCenterEncoded = new EncodedCartesian3();
var scratchBoundingSphereCartographic = new Cartographic();
var scratchBoundingSphereCenter2D = new Cartesian3();
var scratchBoundingSphere = new BoundingSphere();

function updateBatchTableBoundingSpheres(primitive, frameState) {
var hasDistanceDisplayCondition = defined(primitive._batchTableAttributeIndices.distanceDisplayCondition);
if (!hasDistanceDisplayCondition && primitive._batchTableBoundingSpheresUpdated) {
if (!hasDistanceDisplayCondition || primitive._batchTableBoundingSpheresUpdated) {
return;
}

Expand All @@ -1194,24 +1195,22 @@ define([

var modelMatrix = primitive.modelMatrix;
if (defined(modelMatrix)) {
boundingSphere = BoundingSphere.transform(boundingSphere, modelMatrix, boundingSphere);
boundingSphere = BoundingSphere.transform(boundingSphere, modelMatrix, scratchBoundingSphere);
}

if (hasDistanceDisplayCondition) {
var center = boundingSphere.center;
var radius = boundingSphere.radius;
var center = boundingSphere.center;
var radius = boundingSphere.radius;

var encodedCenter = EncodedCartesian3.fromCartesian(center, scratchBoundingSphereCenterEncoded);
batchTable.setBatchedAttribute(i, center3DHighIndex, encodedCenter.high);
batchTable.setBatchedAttribute(i, center3DLowIndex, encodedCenter.low);
var encodedCenter = EncodedCartesian3.fromCartesian(center, scratchBoundingSphereCenterEncoded);
batchTable.setBatchedAttribute(i, center3DHighIndex, encodedCenter.high);
batchTable.setBatchedAttribute(i, center3DLowIndex, encodedCenter.low);

var cartographic = ellipsoid.cartesianToCartographic(center, scratchBoundingSphereCartographic);
var center2D = projection.project(cartographic, scratchBoundingSphereCenter2D);
encodedCenter = EncodedCartesian3.fromCartesian(center2D, scratchBoundingSphereCenterEncoded);
batchTable.setBatchedAttribute(i, center2DHighIndex, encodedCenter.high);
batchTable.setBatchedAttribute(i, center2DLowIndex, encodedCenter.low);
batchTable.setBatchedAttribute(i, radiusIndex, radius);
}
var cartographic = ellipsoid.cartesianToCartographic(center, scratchBoundingSphereCartographic);
var center2D = projection.project(cartographic, scratchBoundingSphereCenter2D);
encodedCenter = EncodedCartesian3.fromCartesian(center2D, scratchBoundingSphereCenterEncoded);
batchTable.setBatchedAttribute(i, center2DHighIndex, encodedCenter.high);
batchTable.setBatchedAttribute(i, center2DLowIndex, encodedCenter.low);
batchTable.setBatchedAttribute(i, radiusIndex, radius);
}

primitive._batchTableBoundingSpheresUpdated = true;
Expand Down Expand Up @@ -1684,7 +1683,12 @@ define([
function createBoundingSphereProperties(primitive, properties, index) {
properties.boundingSphere = {
get : function() {
return primitive._instanceBoundingSpheres[index];
var boundingSphere = primitive._instanceBoundingSpheres[index];
var modelMatrix = primitive.modelMatrix;
if (defined(modelMatrix) && defined(boundingSphere)) {
boundingSphere = BoundingSphere.transform(boundingSphere, modelMatrix);
}
return boundingSphere;
}
};
properties.boundingSphereCV = {
Expand Down

0 comments on commit 482956b

Please sign in to comment.