Sandcastle.addToolbarButton('View Aircraft', function() { viewer.trackedEntity = undefined; viewer.clock.onTick.addEventListener(function (clock) { var direction = entity.orientation.getValue(clock.currentTime); //console.log("d "+direction); var angle = Cesium.Quaternion.computeAngle(direction); console.log("a "+angle/Math.PI*180); var pitch = -Cesium.Math.toRadians(10.0); var range = Cesium.Cartesian3.magnitude(new Cesium.Cartesian3(30.0, 0.0, 10.0)); var offset = new Cesium.HeadingPitchRange(angle, pitch, range); console.log("h "+offset.heading/Math.PI*180); //console.log("p "+offset.pitch/Math.PI*180); //console.log("r "+offset.range); viewer.scene.camera.lookAt(entity.position.getValue(clock.currentTime), offset); console.log("ch "+viewer.scene.camera.heading/Math.PI*180); }); }); //Add button to View Aircraft at a Fixed Angle relative to aircraftSandcastle.addToolbarButton('View Aircraft Fixed Angle', function() { viewer.trackedEntity = undefined; viewer.clock.onTick.addEventListener(function (clock) {
//get 2 positions close together timewisevar CC3=Cesium.Cartesian3;var position1 = entity.position.getValue(clock.currentTime, new CC3());var position2 = entity.position.getValue(Cesium.JulianDate.addSeconds(clock.currentTime, 1/60, new Cesium.JulianDate()), new CC3());
//velocity in terms of Earth Fixed var Wvelocity = CC3.subtract(position2, position1, new CC3());CC3.normalize(Wvelocity, Wvelocity);var Wup = new CC3();var Weast = new CC3();var Wnorth = new CC3();Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(position1, Wup);CC3.cross({x:0,y:0,z:1},Wup,Weast);CC3.cross(Wup,Weast,Wnorth);
//velocity in terms of local ENUvar Lvelocity=new CC3();Lvelocity.x=CC3.dot(Wvelocity,Weast);Lvelocity.y=CC3.dot(Wvelocity,Wnorth);Lvelocity.z=CC3.dot(Wvelocity,Wup);
//angle of travelvar Lup = new CC3(0,0,1);var Least = new CC3(1,0,0);var Lnorth = new CC3(0,1,0);var x = CC3.dot(Lvelocity,Least);var y = CC3.dot(Lvelocity,Lnorth);var z = CC3.dot(Lvelocity,Lup);var angle = Math.atan2(x,y);//math: y b4 x, heading: x b4 yvar pitch = Math.asin(z);//make sure Lvelocity is unitized //angles offsetsangle+=0/180*Math.PI;pitch+=-20/180*Math.PI; var range = 80; var offset = new Cesium.HeadingPitchRange(angle, pitch, range);viewer.scene.camera.lookAt(entity.position.getValue(clock.currentTime), offset); }); //end event listener}); //end button//Add button to View Aircraft at a Fixed Angle relative to aircraftSandcastle.addToolbarButton('View Aircraft w/Aircraft transform', function() { viewer.trackedEntity = undefined; viewer.clock.onTick.addEventListener(function (clock) {
//get 2 positions close together timewisevar CC3=Cesium.Cartesian3;var position1 = entity.position.getValue(clock.currentTime, new CC3());var position2 = entity.position.getValue(Cesium.JulianDate.addSeconds(clock.currentTime, 1/600, new Cesium.JulianDate()), new CC3());
//velocity in terms of Earth Fixed var Wvelocity = CC3.subtract(position2, position1, new CC3());CC3.normalize(Wvelocity, Wvelocity);
//ENU in terms of Earth Fixedvar Wup = new CC3();var Weast = new CC3();var Wnorth = new CC3();Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(position1, Wup);CC3.cross({x:0,y:0,z:1},Wup,Weast);CC3.cross(Wup,Weast,Wnorth);
//aircraft transform in terms of Earth Fixedvar Aright = new CC3();var Adir = new CC3();var Aup = new CC3();Adir = CC3.clone(Wvelocity);CC3.cross(Wvelocity,Wup,Aright);CC3.cross(Aright,Adir,Aup);var transform;/* this approximation causes drifting, so just tap into private primitivestransform = new Cesium.Matrix4( Aright.x,Adir.x,Aup.x,position1.x, Aright.y,Adir.y,Aup.y,position1.y, Aright.z,Adir.z,Aup.z,position1.z, 0,0,0,1);*/transform = viewer.scene.primitives._primitives[0].modelMatrix.clone();
//transform setvar offset = viewer.scene.camera.position.clone();viewer.scene.camera.lookAtTransform(transform,offset); if (trackCar) {
.... your code
}I tried to copy your code to the Cesium Sandcastle. The new button 'View Aircraft w/Aircraft transform' is added, but when I clicked on it, I got this runtime error:
An error occurred while rendering. Rendering has stopped.
undefined
TypeError: Cannot read property 'clone' of undefined
TypeError: Cannot read property 'clone' of undefined
at <anonymous>:171:64
at Event.raiseEvent (https://cesiumjs.org/Cesium/Build/CesiumUnminified/Cesium.js:3113:30)
at Clock.tick (https://cesiumjs.org/Cesium/Build/CesiumUnminified/Cesium.js:45308:21)
at CesiumWidget.render (https://cesiumjs.org/Cesium/Build/CesiumUnminified/Cesium.js:251951:43)
at render (https://cesiumjs.org/Cesium/Build/CesiumUnminified/Cesium.js:251333:32)
Please help!
Thanks!