How to get intersection of a ray from the camera and 3d terrain?

1. A concise explanation of the problem you’re experiencing.

I need to get the intersection point of a ray from the camera to 3d terrain.

Cesium.IntersectionTest() seem to use only the ellipsoid,

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

var intersectionPoint = function(){

var ellipsoid = viewer.scene.mapProjection.ellipsoid;

var windowCoordinates = new Cesium.Cartesian2(elmnt.offsetHeight / 2, elmnt.offsetWidth / 2);

var ray = viewer.camera.getPickRay(windowCoordinates);

var intersection = Cesium.IntersectionTests.rayEllipsoid(ray, ellipsoid);

return Cesium.Ray.getPoint(ray, intersection.start);

}

This function return a Cartesian3 with height (from 3d terrain), but not picked in the center of the window.

What I need is to trace a ray from the camera and get the very first intersection with the 3d terrain.

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I need to rotate the camera around the 1st picked intersection of a ray from the camera (from the center of the window) and the 3d terrain

4. The Cesium version you’re using, your operating system and browser.

1.60

1 Like

This is the solution:

var intersectionPoint = viewer.scene.globe.pick(ray, viewer.scene);

2 Likes

@Daniele_Suppo
var windowCoordinates = new Cesium.Cartesian2(elmnt.offsetHeight / 2, elmnt.offsetWidth / 2);
Can you please tell me how you are getting elmnt.offsetHeight in the above line.