The problem with changing the model matrix in the same way as the dome is that the circle isn’t at the center of its reference frame. The translation to the surface of the earth is “built-in” to the vertex data. If you want to move the circle using a model matrix, you need to first translate it the the center of the reference frame, then to the new center.
Note that this may not be exactly what you expect. When the circle is created at the initial center, all points of the circle are scaled to the surface about the center. When you translate it to a new center, the points may be above or below the surface.
Here’s your modified example:
require([‘Cesium’], function(Cesium) {
“use strict”;
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var scene = viewer.scene;
var primitives = scene.primitives;
var ellipsoid = viewer.centralBody.ellipsoid;
var positionOnEllipsoid = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-100.0, 40.0, 0.0));
var circleGeometry = new Cesium.CircleGeometry({
center : positionOnEllipsoid,
radius : 90000.0
});
var circleInstance = new Cesium.GeometryInstance({
geometry : circleGeometry,
id : ‘circle’,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.4))
}
});
// Add sphere instance to primitives
var circlePrimitive = new Cesium.Primitive({
geometryInstances : circleInstance,
appearance : new Cesium.PerInstanceColorAppearance({
translucent : true
})
});
primitives.add(circlePrimitive);
var inverseModelMatrix = Cesium.Matrix4.inverseTransformation(Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid));
function moveDome(circlePrimitive){
var cartesianPosition = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-102.0, 50.0, 0.0));
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(cartesianPosition);
circlePrimitive.modelMatrix = Cesium.Matrix4.multiply(modelMatrix, inverseModelMatrix);
}
Sandcastle.addToolbarButton(‘moveCircle’, function() {
moveDome(circlePrimitive);
});
Sandcastle.finishedLoading();
});
Regards,
Dan