Hello! I had a Ellipsoid Primitive. After initialization, I want to rotate it. How can I do that? Thank you in advance.
PS I am use Cesium.EllipsoidGeometry.
Hello! I had a Ellipsoid Primitive. After initialization, I want to rotate it. How can I do that? Thank you in advance.
PS I am use Cesium.EllipsoidGeometry.
Hello,
Here is an example I wrote a while ago for rotating a CylinderGeometry. You should be able to use the same method for rotating an EllipsoidGeometry:
var viewer = new Cesium.CesiumWidget('cesiumContainer');
var scene = viewer.scene;
var primitives = scene.primitives;
var ellipsoid = viewer.scene.globe.ellipsoid;
var length = 400000.0;
var positionEllipsoid = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-105.0, 40.0));
//Create Geometry
var coneGeometry = new Cesium.CylinderGeometry({
length: length,
topRadius: 0.0,
bottomRadius: 200000.0,
vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
});
//Create Geometry Instance
var coneGeometryInstance = new Cesium.GeometryInstance({
id: 'RedCone',
geometry: coneGeometry,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED)
}
});
//Add geometry to scene
var primitive;
primitives.add(primitive = new Cesium.Primitive({
geometryInstances: coneGeometryInstance,
appearance: new Cesium.PerInstanceColorAppearance({
closed: true,
translucent: false
})
}));
var counter = 90;
setInterval(function () {
if (counter >= 360) {
counter = 0;
}
var angleRad = 3.14 * counter / 180;
var rotMatrix = new Cesium.Matrix3.fromRotationY(angleRad);
var modelMatrix = Cesium.Matrix4.multiply(
Cesium.Transforms.eastNorthUpToFixedFrame(positionEllipsoid),
Cesium.Matrix4.fromRotationTranslation(rotMatrix, new Cesium.Cartesian3(0.0, 0.0, length * 0.5)),
new Cesium.Matrix4());
primitive.modelMatrix = modelMatrix;
counter += 5;
}, 100);
``
Best,
Hannah