Skip to content

Commit 887701f

Browse files
authored
Merge pull request #11108 from jiangheng90/improvement-of-smooth-zoom
fix camera go througth building in zoom
2 parents 789cc9e + 456f01c commit 887701f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/engine/Source/Scene/ScreenSpaceCameraController.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ function ScreenSpaceCameraController(scene) {
223223
*/
224224
this.minimumPickingTerrainHeight = 150000.0;
225225
this._minimumPickingTerrainHeight = this.minimumPickingTerrainHeight;
226+
/**
227+
* The minimum distance the camera must be before testing for collision with terrain when zoom with inertia.
228+
* @type {number}
229+
* @default 4000.0
230+
*/
231+
this.minimumPickingTerrainDistanceWithInertia = 4000.0;
226232
/**
227233
* The minimum height the camera must be before testing for collision with terrain.
228234
* @type {number}
@@ -2158,6 +2164,8 @@ function pan3D(controller, startPosition, movement, ellipsoid) {
21582164
const zoom3DUnitPosition = new Cartesian3();
21592165
const zoom3DCartographic = new Cartographic();
21602166

2167+
let preIntersectionDistance = 0;
2168+
21612169
function zoom3D(controller, startPosition, movement) {
21622170
if (defined(movement.distance)) {
21632171
movement = movement.distance;
@@ -2189,10 +2197,12 @@ function zoom3D(controller, startPosition, movement) {
21892197
zoom3DCartographic
21902198
).height;
21912199

2192-
const inertiaMovementApproachingGround = Math.abs(height) < 50;
2200+
const approachingCollision =
2201+
Math.abs(preIntersectionDistance) <
2202+
controller.minimumPickingTerrainDistanceWithInertia;
21932203

21942204
const needPickGlobe = inertiaMovement
2195-
? inertiaMovementApproachingGround
2205+
? approachingCollision
21962206
: height < controller._minimumPickingTerrainHeight;
21972207
if (needPickGlobe) {
21982208
intersection = pickGlobe(controller, windowPosition, zoomCVIntersection);
@@ -2201,6 +2211,7 @@ function zoom3D(controller, startPosition, movement) {
22012211
let distance;
22022212
if (defined(intersection)) {
22032213
distance = Cartesian3.distance(ray.origin, intersection);
2214+
preIntersectionDistance = distance;
22042215
}
22052216

22062217
if (cameraUnderground) {

0 commit comments

Comments
 (0)