Gents,
In our app we need several “automated camera” modes. A bit more complex than what EntityView does.
When user tries to manipulate the camera herself we need to switch back to manual camera control.
When automating, our GE code updates the camera each frame and saves values set. Next frame it checks if actual camera position differs from what was set and if so, it decides that the change was caused by user manipulation and “releases” the camera.
Now, I’m trying to do the same in Cesium. I took what seemed relevant part from EntityView and put into clock.onTick.
Like EntityView it does control the camera. Unlike EntityView it doesn’t allow for user interaction at all.
Is clock.onTick a wrong place for camera manipulation? How does EntityView both control the camera itself and, at the same time, allow for user manipulations too?
Is there a better approach than detecting unexpected camera changes? For example, something like camera.controller.onChange.
Thank you.
var point = { lon: -2.137, lat: 0.66 }
var czm = new Cesium.Viewer(‘cesiumContainer’);
var C3 = Cesium.Cartesian3
// add a test model
var czml = new Cesium.CzmlDataSource()
czml.load([{ id: “document”, version: “1.0” }, {
position: { cartographicRadians: [point.lon, point.lat, 0] }
, model: { gltf: ‘…/…/SampleData/models/CesiumAir/Cesium_Air.gltf’ }
}])
czm.dataSources.add(czml)
czm.camera.flyTo({
destination: C3.fromRadians(point.lon, point.lat, 100)
, duration: 0
})
// take control of the camera when an entity is selected
czm.clock.onTick.addEventListener(function(clock) {
if (czm.selectedEntity) {
Cesium.Transforms.eastNorthUpToFixedFrame(
czm.selectedEntity.position.getValue(clock.currentTime)
, czm.scene.ellipsoid
, czm.camera.transform
)
czm.camera.lookAt(new C3(0, 200, 20), C3.ZERO, C3.UNIT_Z)
} else {
czm.camera.setTransform(Cesium.Matrix4.IDENTITY)
}
})