how can I prevent that camera goes under terrain or calculate if cameraposition is under or above terrain ?
See the following two screenshots:
- starting pos
- rotate around the “cross” in the middle
My use case is thefollowing:
I look at a point in the middle of the screen. Using Buttons I place the camera around the middle on a sphere and look at themiddle point. In the above situation the camera on the sphere moves under the terrain.
We use a routine to look from camera to point
heading: Cesium.Math.TWO_PI, // east, default value is 0.0 (north)
pitch: -1 * Cesium.Math.PI_OVER_TWO, // default value (looking down)
var camera = viewer.scene.camera;
var cameraPosition = camera.positionWC.clone();
var direction = Cesium.Cartesian3.subtract(
direction = Cesium.Cartesian3.normalize(direction, direction);
camera.direction = direction;
// get an “approximate” up vector, which in this case we want to be something like the geodetic surface normal.
var approxUp = Cesium.Cartesian3.normalize(
// cross viewdir with approxUp to get a right normal
var right = Cesium.Cartesian3.cross(
right = Cesium.Cartesian3.normalize(right, right);
camera.right = right;
// cross right with view dir to get an orthonormal up
var up = Cesium.Cartesian3.cross(
up = Cesium.Cartesian3.normalize(up, up);
camera.up = up;