Skip to content

Commit

Permalink
Spin3d should fallback to old behavior when globe is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed May 10, 2023
1 parent 1b5c133 commit 46042ef
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/engine/Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1926,9 +1926,9 @@ function spin3D(controller, startPosition, movement) {
const globe = controller._globe;

if (defined(globe) && height < controller._minimumPickingTerrainHeight) {
const mousePos = pickPosition(
controller,
const mousePos = camera.pickEllipsoid(
movement.startPosition,
controller._ellipsoid,
scratchMousePos
);
if (defined(mousePos)) {
Expand Down Expand Up @@ -2090,7 +2090,7 @@ function pan3D(controller, startPosition, movement, ellipsoid) {

// Use the last picked world position unless we're starting a new drag
if (
!scene.globe &&
!defined(controller._globe) &&
!Cartesian2.equalsEpsilon(
startMousePosition,
controller._panLastMousePosition
Expand All @@ -2099,7 +2099,7 @@ function pan3D(controller, startPosition, movement, ellipsoid) {
p0 = pickPosition(controller, startMousePosition, pan3DP0);
}

if (!scene.globe && defined(p0)) {
if (!defined(controller._globe) && defined(p0)) {
const toCenter = Cartesian3.subtract(p0, camera.positionWC, pan3DTemp1);
const toCenterProj = Cartesian3.multiplyByScalar(
camera.directionWC,
Expand Down Expand Up @@ -2141,13 +2141,15 @@ function pan3D(controller, startPosition, movement, ellipsoid) {
pan3DTemp2
);
const angle = Cartesian3.angleBetween(endPickProj, camera.directionWC);
const forward = Math.max(Math.tan(angle), 0.1); // Clamp so we don't make this value infinitely large when the angle is small
let forward = 1.0;
if (defined(camera.frustum.fov)) {
forward = Math.max(Math.tan(angle), 0.1); // Clamp so we don't make the magnitude infinitely large when the angle is small
}
let dot = Math.abs(
Cartesian3.dot(camera.directionWC, cameraPositionNormal)
);
const magnitude =
((-dragDelta.y * pixelDimensions.y) / Math.sqrt(forward)) *
2 *
((-dragDelta.y * pixelDimensions.y * 2.0) / Math.sqrt(forward)) *
(1.0 - dot);
const direction = Cartesian3.multiplyByScalar(
endPickDirection,
Expand Down

0 comments on commit 46042ef

Please sign in to comment.