Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix camera go througth building in zoom #11108

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/engine/Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ function ScreenSpaceCameraController(scene) {
*/
this.minimumPickingTerrainHeight = 150000.0;
this._minimumPickingTerrainHeight = this.minimumPickingTerrainHeight;
/**
* The minimum distance the camera must be before testing for collision with terrain when zoom with inertia.
* @type {number}
* @default 4000.0
*/
this.minimumPickingTerrainDistanceWithInertia = 4000.0;
/**
* The minimum height the camera must be before testing for collision with terrain.
* @type {number}
Expand Down Expand Up @@ -2158,6 +2164,8 @@ function pan3D(controller, startPosition, movement, ellipsoid) {
const zoom3DUnitPosition = new Cartesian3();
const zoom3DCartographic = new Cartographic();

let preIntersectionDistance = 0;

function zoom3D(controller, startPosition, movement) {
if (defined(movement.distance)) {
movement = movement.distance;
Expand Down Expand Up @@ -2189,10 +2197,12 @@ function zoom3D(controller, startPosition, movement) {
zoom3DCartographic
).height;

const inertiaMovementApproachingGround = Math.abs(height) < 50;
const approachingCollision =
Math.abs(preIntersectionDistance) <
controller.minimumPickingTerrainDistanceWithInertia;

const needPickGlobe = inertiaMovement
? inertiaMovementApproachingGround
? approachingCollision
: height < controller._minimumPickingTerrainHeight;
if (needPickGlobe) {
intersection = pickGlobe(controller, windowPosition, zoomCVIntersection);
Expand All @@ -2201,6 +2211,7 @@ function zoom3D(controller, startPosition, movement) {
let distance;
if (defined(intersection)) {
distance = Cartesian3.distance(ray.origin, intersection);
preIntersectionDistance = distance;
}

if (cameraUnderground) {
Expand Down