Gents,
I need to automate the camera until the user takes control (tries to manipulate it herself).
I’d like to operate the camera using target and HeadingPitchRange offset.
-
flyToBoundingSphere positions the camera imprecisely, so I got weird animation (run below code)
-
lookAt changes reference frame so that when the user tries to tilt the camera with middle mouse button camera stays unchanged and I fail to detect user interaction (un-comment line 27)
Please advise.
Thank you.
var C = Cesium
var viewer = new C.Viewer(‘cesiumContainer’);
var camera = viewer.camera
var a = { lon: -117.25, lat: 32.71 }
var b = { lon: -117.00, lat: 32.71 }
var duration = 3000
function position(time) {
var t = C.JulianDate.toDate(time).valueOf() / 1e3 % duration
return C.Cartesian3.fromDegrees(
C.LinearApproximation.interpolateOrderZero(t, [0, duration], [a.lon, b.lon], 1)
, C.LinearApproximation.interpolateOrderZero(t, [0, duration], [a.lat, b.lat], 1)
)
}
var automate = true
var offset = new C.HeadingPitchRange(0, -Math.PI/2*0.99, 100)
var positionSet
var positionGot = camera.position
viewer.clock.onTick.addEventListener(function() {
if (!automate) return
if (camera.position.equals(positionGot)) { // no change => continue automating
positionSet = position(viewer.clock.currentTime)
// imprecise positioning leads to bad animation
camera.flyToBoundingSphere(new C.BoundingSphere(positionSet, 1), { duration: 0, offset: offset })
// locks tilting
// camera.lookAt(positionSet, offset)
positionGot = viewer.camera.position.clone()
} else { // user intruded => stop automating
automate = false
// to “release” the camera - restore reference frame set by camera.lookAt
camera.flyToBoundingSphere(new C.BoundingSphere(positionSet, 1), { duration: 0, offset: offset })
}
})