CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
13.03k stars 3.51k forks source link

Some camera functions seem broken in 2D #2469

Open mramato opened 9 years ago

mramato commented 9 years ago

I was trying to zoom to lla 88, 0, 27e6 in 2D mode and neither of the below calls work (each on their own should accomplish the task.

Doesn't work

viewer.scene.camera.lookAt(Cesium.Cartesian3.fromDegrees(88, 0),
                           new Cesium.HeadingPitchRange(0, -Math.PI, 27e6));
viewer.scene.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);

Does the same thing as above (Doesn't work either)

viewer.scene.camera.setView({
    position : Cesium.Cartesian3.fromDegrees(88, 0, 27e6),
    heading : 0,
    pitch : -Math.PI,
    roll : 0
});
WarpDrive commented 9 years ago

Perhaps range is a typo, should be roll instead? I don't see range anywhere in the setView function. Though pitch and roll in 2D always use defaults looking at the code. However I don't see how having an unused property would cause it not to function at all, or just the orientation is off perhaps?

mramato commented 9 years ago

Yes, range is a typo (which I've now fixed), but it has no bearing on the actual issue, since roll just defaults to 0 anyway when not specified.

WarpDrive commented 9 years ago

There may be a problem with position. I made a sandcastle example to factor out orientation and z position issues (position.z 0 seems to cause clipping issues.)

var viewer = new Cesium.Viewer('cesiumContainer', {
    sceneMode : Cesium.SceneMode.SCENE2D
});
viewer.scene.camera.setView({
    position : Cesium.Cartesian3.fromDegrees(88, 0, 27e6),
});
    var camera = viewer.camera;
    camera.direction.x=0;camera.direction.y=0;camera.direction.z=-1;
    camera.right.x=1;camera.right.y=0;camera.right.z=0;
    camera.up.x=0;camera.up.y=1;camera.up.z=0;
    if(camera.position.z<100){camera.position.z+=100;}

Entering various lon/lat values yields strange results.

WarpDrive commented 9 years ago

It takes time for camera._this mode to change from 3 to 2. Add these lines to the end of the above sandcastle app

console.log(camera._mode);
setTimeout(function(){ console.log(camera._mode); }, 1000);

Here's one where does setView 1 second later, and it functions properly:

var viewer = new Cesium.Viewer('cesiumContainer', {
    sceneMode : Cesium.SceneMode.SCENE2D
});

setTimeout(function(){
viewer.scene.camera.setView({
    position : Cesium.Cartesian3.fromDegrees(88, 0, 27e6)
});
}, 1000);