Hi everyone,
My project needs to determine if given degree coordinates (on the globe surface) are visible by the camera. The following code has been written for that purpose:
const viewer = new Cesium.Viewer("cesiumContainer"); // for instance
// set the camera over the pacific ocean
viewer.camera.position = new Cesium.Cartesian3(-33517534.12007907, -10816522.975550467, 2121682.0018882686);
viewer.camera.direction = new Cesium.Cartesian3(0.949949844026326, 0.30656056846902546, -0.06013245125809427);
let ellipsoid = viewer.scene.globe.ellipsoid;
let cameraPosition = viewer.scene.camera.position;
let bs = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);
let occluder = new Cesium.Occluder(bs, cameraPosition);
let point = Cesium.Cartesian3.fromDegrees(180, 0, 0.001);
let isPointVisible = occluder.isPointVisible(point);
console.log(isPointVisible);
For these coordinates (180, 0, 0.001), true
is returned in the Cesium SandCastle, which seems OK.
However, I cannot manage to get this working for latitudes different from 0. For example, (180, -1, 0.001) returns false
.
I guess the problem here is the altitude, so I have tried to get the right altitude by casting a Ray by following the instructions on this topic.
However I could not manage to make this work either.
I do not know much about Cesium yet, and maybe I am missing something trivial here. Would anyone be willing to point me any mistake I could have made, please?
Thank you all!
Cesium version: 1.94.3