Hi there, I have tried a few solutions to my question and am a bit embaressed by my lack of knowledge in this field, but so keen to learn. I post below the various attempts I made to solve the problem and would be very grateful if someone could please help me to a) solve my problem and b) educate me a bit by answering my various questions or steering me in the direction of where I could begin to educate myself.... Thanks in advance!
CONTEXT: Tracing the path of moving vehicles. Receive new coordinates for the vehicle every two minutes. Vehicle is represented by a billboard. Am successfully moving the billboard with every new plot.
PROBLEM: Now want to focus on a particular vehicle by drawing a transparent dome on top of it and calculating then when any other vehicles are in the dome's radius. But first issue is HOW to move the dome's position???
ATTEMPTED SOLUTIONS: (working via sandcastle, posted the whole thing to make it easier...)
1. Attempted SphereGeometry --> Geometryinstance --> primitive as follows:
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;
viewer.centralBody.depthTestAgainstTerrain = true;
// Create sphere and position with model matrix
var height = -45000.0;
var positionOnEllipsoid = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-100.0, 40.0));
var spheremodelMatrix = Cesium.Matrix4.multiplyByTranslation(
Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid),
new Cesium.Cartesian3(0.0, 0.0, height)
);
var sphereGeometry = new Cesium.SphereGeometry({
vertexFormat : Cesium.VertexFormat.POSITION_AND_NORMAL,
position : positionOnEllipsoid,
radius : 90000.0
});
var sphereInstance = new Cesium.GeometryInstance({
geometry : sphereGeometry,
modelMatrix : spheremodelMatrix,
id : 'dome',
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.4))
}
});
// Add sphere instance to primitives
var dome = new Cesium.Primitive({
geometryInstances : sphereInstance,
appearance : new Cesium.PerInstanceColorAppearance({
translucent : true//,
//closed : true
})
});
primitives.add(dome);
function moveDome(scene, primitives, height, position, dome){
var picked = scene.pick(position);
if (Cesium.defined(picked)) {
var prim = picked.primitive;
var attributes = prim.getGeometryInstanceAttributes('dome');
attributes.position = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-102.0, 50.0));
} else {
throw new Error('not picked!!.');
}
}
Sandcastle.addToolbarButton('moveDome', function() {
moveDome(scene, primitives, height, positionOnEllipsoid, sphereInstance);
});
Sandcastle.finishedLoading();
});
Nope. get the error: Uncaught Error: not picked!!. (on line 51)
(I am passing through a bunch of parameters to the function because of all the various things I tried).
Still passing in the spereInstance I tried the function as:
function moveDome(scene, primitives, height, position, dome){
var positionOnEllipsoid = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-102.0, 50.0));var spheremodelMatrix = Cesium.Matrix4.multiplyByTranslation(
Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid),
new Cesium.Cartesian3(0.0, 0.0, height)
);
//dome.setPosition(ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-102.0, 50.0)));
dome.setModel(spheremodelMatrix);
}
Nope Error: Uncaught TypeError: Object [object Object] has no method 'setModel' (on line 50)
I tried dome.setModelMatrix(spheremodelMatrix); Nope
Then tried passing in the sphereGeometry - same result.
So then HOW do I get hold of the Vertex position and will changing it move the dome??
2. I did the same as above but using ellipsoids. No diff. HOW can one move it? Surely the position is an aspect of the Instance?
3. Then found Tamy's post on moving object where she used an EllipsoidPrimitive. This seems such a quick and elegant solution but!!: EllipsoidPrimitive doesn't obey the depthTestAgainstTerrain = true injunction ... also I actually also need to add an OutlineGeometry.
4. Then investigated a bit on DynamicObject bu didn't go to sandcastle here yet because couldn't find where DynamicEllipsoid has a position either - same problem as 2??
5. Finally, what about the boundingsphere - this has already methods to calculate distances to other objects but is the boundingSphere visible and can I add outline to it?
Lots of questions. Please excuse my ignorance.
Regards
Rencia