Help with Cameras

HI all

First off wanted to say a big thanks to the Cesium team. It really is an amazing bit of software.

I have an issue with cameras, the issue is totally down to my lack of understanding and am looking for some pointers in the right direction.

I have developed a web based satellite tracking application and I am trying to implement a feature in the 3d view, which is where Cesium is used, that allows you to follow a satellite either from your location or the satellite. So for example in the following from home view the camera is placed at your location and points at the satellite, the reverse being true for the follow from satellite

The current implementation can be seen at the url below. Please give the page a little time to load and once loaded accept the cookies and allow the browser to use your location.

http://www.agsattrack.com/?view=3d (Please only use Firefox/Chrome or Safari)

Find a satellite that is above the horizon at your location, clicking on a satellite will show its orbit and any passes at your location during the current orbit.

Ensure the satellite is selected by clicking on it and then click on the 'From Home' icon in the toolbar. You should now be following the satellite from your location.

The 'From Satellite' doesn't work at all, it seems to point into space all of the time.

The code that is altering the camera is as follows, this code is run every time the satellite positions are updated which by default is every 5 seconds.

            if (_followFromObserver) {
                eye = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(observer.getLon(), observer.getLat(), 100));
                target = new Cesium.Cartesian3(following.get('x'), following.get('y'), following.get('z'));
                target = target.multiplyByScalar(1000);
                up = Cesium.Cartesian3.UNIT_X;
            } else {
                target = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(observer.getLon(), observer.getLat(), 100));
                eye = new Cesium.Cartesian3(following.get('x'), following.get('y'), following.get('z'));
                eye = target.multiplyByScalar(1000);
                up = Cesium.Cartesian3.UNIT_X;
            }
            scene.getCamera().controller.lookAt(eye, target, up);

The theory behind this is that the eye and target are set depending upon which following option is selected. The lookat method on the camera controller is then used to position the camera.

So there are three problems here

1) The follow from home works some of the time !
2) The follow from satellite doesn't work at all.
3) I would like to orientate the camera so that when following from the observers location the camera is orientated with the horizon.

I am obviously doing something wrong here and I am sure its just due to my total lack of understanding.

Any pointers in the right direction would be greatly appreciated.

Many Thanks

Alex

Just a quick hint for orienting the camera with the horizon: Use the normalized camera position as the ‘up’ parameter:

Peter

scene.getCamera().controller.lookAt(eye, target, eye.normalize());

Many thanks Pete

Thats helped sort the horizon out.

Now just some pointers on the other camera issues

Alex

For the view from satellite, it looks like the camera is staring off into space because the camera position is really, really far away. Everything ends up being clipped by the far plane. if you want to be 1000.0 meters above the target try:

var magnitude = target.magnitude() + 1000.0;

eye = target.normalize().multiplyByScalar(magnitude);

But if you want the camera to be positioned at the satellite, I see you have

eye = new Cesium.Cartesian3(following.get(‘x’), following.get(‘y’), following.get(‘z’));

I stepped through the code and found that the magnitude of the target was greater than the magnitude of the eye when it should be the opposite for a satellite looking down at the earth. This leads me to believe that the satellite is in a different reference frame than the camera. All of the arguments to lookAt must be in the same reference frame of the camera. When I stepped through your app, it was in world coordinates, but I saw that the camera transform was set in some places in the code.

Thanks for that Daniel

I will have another look at the code when my brain doesn’t hurt quite so much :wink:

Alex

Daniel

I think I have it working now so many thanks for the input. The satellite was indeed in the wrong reference frame.

Alex