How to calculate the current camera "lookAt" parameter?

2,754 views
Skip to first unread message

yaozhih...@googlemail.com

unread,
May 26, 2015, 9:32:49 AM5/26/15
to cesiu...@googlegroups.com
Dear Cesium Team,

in Cesium we can zoom to one place by using the function camera.lookAt(target, offset, eye, target, up).

My question is how to get or calculate the "lookAt" parameters (such as latitude, longitude, heading, tilt, range ...) from one arbitrary camera position? (assume the altitude value of the target object is 0)

thanks in advance

Zhihang

cc3dg...@gmail.com

unread,
May 26, 2015, 9:50:11 AM5/26/15
to cesiu...@googlegroups.com, yaozhih...@googlemail.com
I look forward to an answer on this one too!

yaozhih...@googlemail.com

unread,
May 27, 2015, 5:11:03 AM5/27/15
to cesiu...@googlegroups.com
excuse me, could anyone help me to answer this question?

Mike LP

unread,
Jun 1, 2015, 11:35:07 AM6/1/15
to cesiu...@googlegroups.com, yaozhih...@googlemail.com, yaozhih...@googlemail.com
Here is an example of how I've been able to capture all the properties of a camera:

var cameraProperties = {
  position: camera.position.clone(),
  direction: camera.direction.clone(),
  up: camera.up.clone(),
  right: camera.right.clone(),
  transform: camera.transform.clone(),
  frustum: camera.frustum.clone()
};

You can actually store that and reset the camera to that location later.

yaozhih...@googlemail.com

unread,
Jun 1, 2015, 11:54:36 AM6/1/15
to cesiu...@googlegroups.com, yaozhih...@googlemail.com
Hi Mike, thanks very much for your response.
However, I need exactly the "LookAt" Parameters. Is it possible to derive the value of those paramters (latitude, longitude, heading, tilt, range ...) from the cameraProperties in your code?

Mike LP

unread,
Jun 1, 2015, 3:05:03 PM6/1/15
to cesiu...@googlegroups.com, yaozhih...@googlemail.com, yaozhih...@googlemail.com
Use what I posted before to get heading and tilt

Then a slight modification to the Google Earth Altitude example will solve your problem I believe

    var viewer = new Cesium.Viewer('cesiumContainer');
   
var camera = viewer.camera;
   
var canvas = viewer.scene.canvas;

   
function cameraLookingAt() {
       
var ray = camera.getPickRay(new Cesium.Cartesian2(
           
Math.round(canvas.clientWidth / 2),
           
Math.round(canvas.clientHeight / 2)
       
));

       
var position = viewer.scene.globe.pick(ray, viewer.scene);
       
if (Cesium.defined(position)) {
           
var cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
           
var height = cartographic.height;
           
var range = Cesium.Cartesian3.distance(position, camera.position);

            alert
('Lat/Lon: [' +
               
Cesium.Math.toDegrees(cartographic.latitude).toFixed(2) + ',' +
               
Cesium.Math.toDegrees(cartographic.longitude).toFixed(2) + ']'+
               
' height: ' + height.toFixed(2) +
               
' range: ' + range.toFixed(2)
           
);
       
} else {
            console
.log('Looking at space?');
       
}
   
}

yaozhih...@googlemail.com

unread,
Jun 2, 2015, 4:38:42 AM6/2/15
to cesiu...@googlegroups.com, yaozhih...@googlemail.com
Hi Mike,

nice code. it works and solves my problem. thank you very much.

Mike LP

unread,
Jun 2, 2015, 2:22:04 PM6/2/15
to cesiu...@googlegroups.com, yaozhih...@googlemail.com, yaozhih...@googlemail.com
You're very welcome :)

MP

unread,
Jul 22, 2019, 3:21:23 PM7/22/19
to cesium-dev
Thanks for your replies! It was helpful to me.
But I need to make my camera fly and I am using the code below. I could get longitude, latitude and altitude from cloning the camera position. But I am stuck at finding heading and tilt from the camera parameter clones.

var coords = Cesium.Cartesian3.fromDegrees(longitude, latitude, altitude, Cesium.Ellipsoid.WGS84);
var options = {
destination: coords,
duration: 2,
orientation: {
heading: heading,
pitch: tilt,
roll: 0.3
}
};
camera_v.flyTo(options);

Any help is much appreciated!
Thanks in advance.

--
MP

Omar Shehata

unread,
Aug 6, 2019, 12:11:27 PM8/6/19
to cesium-dev
You can get the camera's heading as a property of the camera: https://cesiumjs.org/Cesium/Build/Documentation/Camera.html#heading

This thread also has a code example of syncing two camera's fully: https://groups.google.com/d/msg/cesium-dev/GNK7GYNfWNI/V_UbRAuxBAAJ
Reply all
Reply to author
Forward
0 new messages