CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.93k stars 3.49k forks source link

computeViewRectangle not working in oblique or non-north-up views #9516

Open malaretv opened 3 years ago

malaretv commented 3 years ago

camera.computeViewRectangle works well in the usual case of looking straight down at the sphere with north towards the top of the screen. However, when the camera is rotated to look southwards or down at an angle the results become unreliable.

The below example loads with a view out facing south over the Caribbean and a rectangle entity representing the computed view rectangle for that position. You'll notice you have to move the camera backwards to see what was returned as the view rectangle.

Sandcastle example: https://sandcastle.cesium.com/#c=pZJNj5swEIb/ipUTSHSAQj5ISdQ27a1VpWzVExcHZhOrxqa2IUpX+e+1cTb7qb3UFzy233fmGWagigwMj6jIigg8kg1q1rfwazwLqkk9xhspDGUCVTWJyB1RKBpUW/zTozbfZYNLYlSP5Bx+qMRgLWvaoqLW0nuDj+1lJfwWOqmZYVI8TbuhytgdFVmQFbM8KSBN5xF5N51nWbJIYJ7MIpK/z4v5tIBFNnP5LoYNU1i/6ZhAlhYRSSCdptYzgSKbhld9370lzPOLYjF+kywPHYxjRWGYOT2wjjFDDbRpgrtKELtcaVTsOZIluRy5VUupGiaoTWQvnvQKatl2vUH3I7b36uDyRNcoEPZc7hCQc9ZpyZowejBuraVilC+vNJJLBduvX+DIzOET7w7UYYVecq7EeeQhN1Q0NdWGoyv/p5R8R9Xn3hgp7DBsfE3EFUWuVbmZuO2Fb34QekDfFbiCw2PW1X+z2hTjsE2iSanNieP6Hv4jazupDOkVDwBig23HXdJ419e/0UCttRO6p2X8WFo2bCCsWb0y86TmVGt7c9tzfsP+WuR1Gdv3L6RcUgu5/zGg4vTknh3S9Td/CABlbMPXlcb3+pnzPw

Browser: Chrome

Operating System: Ubuntu

ebogo1 commented 3 years ago

I can confirm this behavior on macOS in chrome... @lilleyse this looks like a bug to me, though it's hard to manually find a camera angle where the rectangle is noticeably misaligned. Any ideas about this one?

lilleyse commented 3 years ago

I don't have any good suggestions here, but just echoing that camera.computeViewRectangle attempts to find the rectangle by picking the ellipsoid at the four corners of the screen, which will lead to inaccurate results for oblique views since some corners won't pick the ellipsoid.

though it's hard to manually find a camera angle where the rectangle is noticeably misaligned

I see some pretty bad misalignment with the provided Sandcastle

Selection_709

malaretv commented 3 years ago

Thanks for taking a look!

@lilleyse if not all points pick the ellipsoid it does seem to try to grab points using this computeHorizonQuad() and while i don't understand the details here it does seem to work well, for the most part, if the camera is oriented north.

If it turns out there are some hard limitations as to what can be done to fix this it'd be nice to make clear in the docs what is "reasonable" behavior to expect and/or warning users away from cases where it shouldn't be expected to work.

cavencj commented 1 year ago

the version 1.107.0 still has this issue