error using flyToBoundingSphere, but can use lookAt correctly, please help spot the problem

316 views
Skip to first unread message

sra...@gmail.com

unread,
May 14, 2018, 4:01:28 AM5/14/18
to cesium-dev
1. A concise explanation of the problem you're experiencing.

I am using a cesium Widget and want to use the flyToBoundingSphere, but the view goes to a strange location instead


2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
var viewer = new Cesium.CesiumWidget('cesiumContainer', {
skyAtmosphere: false,
shouldAnimate : true,
terrainProvider: Cesium.createWorldTerrain()
});

var position = Cesium.Cartesian3.fromRadians(-2.0862979473351286, 0.6586620013036164, 1400.0);
var hpRoll = new Cesium.HeadingPitchRoll();
var hpRange = new Cesium.HeadingPitchRange();
var fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator('east', 'north');
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform);
var model = viewer.scene.primitives.add(Cesium.Model.fromGltf({
url : '../../../../Apps/SampleData/models/CesiumMan/Cesium_Man.glb',
modelMatrix: modelMatrix,
scale: 100.0,
}));

model.readyPromise.then(function(m){
// this does not work correctly
viewer.camera.flyToBoundingSphere(model.boundingSphere);

});

// I can successfully do the following, but I won't necessarily have position
1. viewer.scene.camera.flyTo({
destination: position
});


3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

my actual need is to fly to the location where I can set up heading, pitch, range or heading, pitch, roll, like the following code which works
var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new Cesium.Cartesian3());
//viewer.scene.camera.lookAt(center, new Cesium.HeadingPitchRange(0, 0, model.boundingSphere.radius*2.5));


4. The Cesium version you're using, your operating system and browser.
Cesium version: 1.43
OS - windows 10, chrome 66, updated latest

sra...@gmail.com

unread,
May 14, 2018, 8:34:31 AM5/14/18
to cesium-dev
I have been able to figure out this solution, let me know if I missed something:
essentially don't use the model.boundingSphere directly, create a new one


model.readyPromise.then(function(m){


var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new Cesium.Cartesian3());

var boundingSphere = new Cesium.BoundingSphere(center, model.boundingSphere.radius);
var offset = new Cesium.HeadingPitchRange(0, 0, model.boundingSphere.radius* 2.5);
viewer.camera.flyToBoundingSphere(boundingSphere, {offset: offset});

});

{ it seems to work }

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=hZRrT9swFIb/itUvCVNw0guh7QoasME+DA1RtH2JNLmJQywcO7KdQkH89x3nRsIqllaRL+c8fn38xlui0JbRR6rQCRL0EV1Qzcoc/6rGXCeuuhdSGMIEVY6HXhATqTyXT2iJUsI1Ra8HnyMRiS2gCqmZYVIArAFdEGWgRcQUp0rmtySBtnYPJziYh5PF8WJ2PJ0ejSfz0EMBDo/mYTgJgvE0mIbjcGbHAou38Ky4lZwPdX6nABT3N8zEmZ11e8FE3NMPou10F56yJ5pcKpLTOwX6Uqnytz10QxpzGRNex8nLLueKQm2IkVAwSrSBKjlCKpM5LT6XCeXXxCj2tBebvdtGH+62RfWaCngt4BvnrNCSJfj31XoOxdqzi4ECWLs+bKxjkIwLxXJAb6nGJEncBnttQ6vTuuImdV8igeBhyRI5hDhe3bVPqTiYwMHY7/5nRaH9NckLTr8SQ/xqWe3X5GsimtYfaOJ7vunTejVa9ju9EA3Fp0s0DsAVzfDrQe0++6uSsIJa7m5APdMUm4wKNy1FbAvo5gfNZmxFoAKmsn277Wq1Gc5LbljBd+e7G8mEcWtqX1CtDm9kKeyprYuMKoprntf325v53Upmu/Qwc+jR88Gc21L3LqnANaXuk2Waamr+5/px4KHDAC8WH3I/oRk+6uC1b2LwliI45bs7+U7pkAEXRa1l2WiCW8JyaprvD3zYULmUD2em23Kd1wrYn1IJaS3q+/adUG2YIPbAl92F1Aa8NrhIQGvkjVba7Dg9rae/sLyAz9b62gUvGwo2JnCA/qaMH6jBsa5qvfLbpFXCtvBhnESjd/dkNEIxJ1rDTFpyvmbPNBqdrnyIH6RxWR3Nzy1VnOxsSDY+/VEPYoxXPnT/zTJS8g1RPeJf

Gabby Getz

unread,
May 21, 2018, 10:48:49 AM5/21/18
to cesium-dev
Glad you solved it, that solution looks good to me!
Reply all
Reply to author
Forward
0 new messages