How to answer the question "Can the camera see point (X,Y,Z) right now?"

I’ve spent an entire day looking through examples, source and the forum and I can’t figure out how to answer this question.

I have a surface route composed of points in ellipsoid coordinates (X,Y,Z). I have broken the route down into segments and I have picked strategic camera positions that guarantee line of sight to all the points of a segment (this is all done outside of Cesium). I am going to animate a target along this route, and I want the appropriate camera to follow it. This is done and working.

What I don’t like about my prototype is the visual effect of constantly panning as the target moves. I would much rather leave the camera alone as my target is moving across the view, and only turn it when the target is about to go off the viewport. In other words, I want the camera to do lazy following. Unfortunately, I can’t see an easy way to translate ellipsoid coordinates to window (viewport) coordinates. Am I missing something really obvious (perhaps because I’m too tired)? Is there a different way to accomplish this?

I’d like to take this opportunity to thank you all for helping me so far. I can finally see the light at the end of the tunnel for my project and it’s all because of Cesium and the tremendous work you’ve done.

Happy New Year!

Peter

Hi Peter,

Testing if a point is visible to the camera has two parts. First, you need to determine if the point is inside the camera’s view frustum. The easiest way to do that is to use the cullingVolume property of the FrameState that is passed to update functions. The CullingVolume’s getVisibility method takes a bounding volume, so to test a single point you can construct a BoundingSphere with a zero radius:

var cullingVolume = frameState.cullingVolume;
if (cullingVolume.getVisibility(new BoundingSphere(target, 0.0)) === Intersect.INSIDE) {
// target point is inside the culling volume
}

Second, you need to determine whether or not the point is occluded by other objects in the scene. This is tricky in the general case, but if you’re only concerned with occlusion by the ellipsoidal Earth itself - in other words, you want to test if the point is below the horizon - you can use EllipsoidalOccluder and its isPointVisible method. You may not even need to worry about occlusion testing because you’ve already determined that all your points are visible from the camera’s chosen location.

If you want to pan the camera before the point reaches the extreme edges of the camera’s view, you can construct a CullingVolume based on a smaller field-of-view and use the smaller volume in the test above.

I hope this helps,

Kevin

Thanks, Kevin, that did the trick. I ended up using a bounding sphere with a radius > 0, so it helps keep the target well within the screen.

Since my distances are fairly short (no segment or camera distance is longer than 5km) I don’t have to worry about ellipsoid occlusion, just terrain occlusion. So I did viewshed analysis outside of Cesium to pick camera positions.

Best,

Peter