Skip to content

Commit

Permalink
Fixes for CV
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed May 27, 2020
1 parent 43a2d8b commit a952848
Showing 1 changed file with 75 additions and 26 deletions.
101 changes: 75 additions & 26 deletions Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,14 +1179,29 @@ function getZoomDistanceUnderground(controller, ray, height) {

var scratchCartographic = new Cartographic();

function getDistanceFromClosestSurface(controller, position) {
function getHeight(controller) {
var ellipsoid = controller._ellipsoid;
var cartographic = ellipsoid.cartesianToCartographic(
position,
scratchCartographic
);
var height = cartographic.height;
var scene = controller._scene;
var camera = scene.camera;
var mode = scene.mode;

var height = 0.0;
if (mode === SceneMode.SCENE3D) {
var cartographic = ellipsoid.cartesianToCartographic(
camera.position,
scratchCartographic
);
if (defined(cartographic)) {
height = cartographic.height;
}
} else {
height = camera.position.z;
}
return height;
}

function getDistanceFromClosestSurface(controller) {
var height = getHeight(controller);
var globeHeight = defaultValue(controller._globeHeight, 0.0);
var distanceFromSurface = Math.abs(height - globeHeight);
var distanceFromUndergroundSurface = Math.abs(
Expand Down Expand Up @@ -1243,6 +1258,7 @@ function translateCV(controller, startPosition, movement) {

var scene = controller._scene;
var camera = scene.camera;
var cameraUnderground = controller._cameraUnderground;
var startMouse = Cartesian2.clone(
movement.startPosition,
translateCVStartMouse
Expand All @@ -1261,7 +1277,18 @@ function translateCV(controller, startPosition, movement) {
}
}

if (origin.x > camera.position.z && defined(globePos)) {
if (
(cameraUnderground || origin.x > camera.position.z) &&
defined(globePos)
) {
if (cameraUnderground) {
getStrafeStartPositionUnderground(
controller,
startRay,
globePos,
globePos
);
}
Cartesian2.clone(startPosition, controller._strafeMousePosition);
Cartesian2.clone(startPosition, controller._strafeEndMousePosition);
Cartesian3.clone(globePos, controller._strafeStartPosition);
Expand Down Expand Up @@ -1420,6 +1447,7 @@ function rotateCVOnPlane(controller, startPosition, movement) {
function rotateCVOnTerrain(controller, startPosition, movement) {
var scene = controller._scene;
var camera = scene.camera;
var cameraUnderground = controller._cameraUnderground;

var center;
var ray;
Expand Down Expand Up @@ -1454,6 +1482,13 @@ function rotateCVOnTerrain(controller, startPosition, movement) {
Cartesian3.add(position, center, center);
}

if (controller._cameraUnderground) {
if (!defined(ray)) {
ray = camera.getPickRay(startPosition, rotateCVWindowRay);
}
getTiltCenterUnderground(controller, ray, center, center);
}

Cartesian2.clone(startPosition, controller._tiltCenterMousePosition);
Cartesian3.clone(center, controller._tiltCenter);
}
Expand Down Expand Up @@ -1531,7 +1566,11 @@ function rotateCVOnTerrain(controller, startPosition, movement) {

camera._setTransform(verticalTransform);
if (dot < 0.0) {
if (movement.startPosition.y > movement.endPosition.y) {
var movementDelta = movement.startPosition.y - movement.endPosition.y;
if (
(cameraUnderground && movementDelta < 0.0) ||
(!cameraUnderground && movementDelta > 0.0)
) {
constrainedAxis = undefined;
}

Expand Down Expand Up @@ -1654,10 +1693,6 @@ function zoomCV(controller, startPosition, movement) {
var distance;
if (defined(intersection)) {
distance = Cartesian3.distance(position, intersection);
} else {
var normal = Cartesian3.UNIT_X;
distance =
-Cartesian3.dot(normal, position) / Cartesian3.dot(normal, direction);
}

if (cameraUnderground) {
Expand All @@ -1666,7 +1701,17 @@ function zoomCV(controller, startPosition, movement) {
ray,
height
);
distance = Math.min(distance, distanceUnderground);
if (defined(distance)) {
distance = Math.min(distance, distanceUnderground);
} else {
distance = distanceUnderground;
}
}

if (!defined(distance)) {
var normal = Cartesian3.UNIT_X;
distance =
-Cartesian3.dot(normal, position) / Cartesian3.dot(normal, direction);
}

handleZoom(
Expand Down Expand Up @@ -1796,17 +1841,18 @@ function strafe(controller, movement, strafeStartPosition) {
Cartesian3.add(camera.position, direction, camera.position);
}

var scratchCartographic = new Cartographic();
var scratchRadii = new Cartesian3();
var scratchEllipsoid = new Ellipsoid();
var scratchIntersectionPoint = new Cartesian3();

function getClosestPickDistance(controller, ray, pickedPosition) {
var ellipsoid = controller._ellipsoid;
var origin = ray.origin;

var distance = Cartesian3.distance(origin, pickedPosition);

if (controller._scene.mode !== SceneMode.SCENE3D) {
return distance;
}

var ellipsoid = controller._ellipsoid;
var heightDelta = controller.undergroundSurfaceHeight;
var innerRadii = Cartesian3.fromElements(
ellipsoid.radii.x + heightDelta,
Expand Down Expand Up @@ -1842,7 +1888,7 @@ function getStrafeStartPositionUnderground(
// If the picked position is too far away set the strafe speed based on the
// camera's height from the closest surface (closest surface being either
// the globe surface or the underground invisible surface)
distance = getDistanceFromClosestSurface(controller, ray.origin);
distance = getDistanceFromClosestSurface(controller);
}
return Ray.getPoint(ray, distance, result);
}
Expand Down Expand Up @@ -2179,8 +2225,6 @@ function zoom3D(controller, startPosition, movement) {
var distance;
if (defined(intersection)) {
distance = Cartesian3.distance(ray.origin, intersection);
} else {
distance = height;
}

if (cameraUnderground) {
Expand All @@ -2189,7 +2233,15 @@ function zoom3D(controller, startPosition, movement) {
ray,
height
);
distance = Math.min(distance, distanceUnderground);
if (defined(distance)) {
distance = Math.min(distance, distanceUnderground);
} else {
distance = distanceUnderground;
}
}

if (!defined(distance)) {
distance = height;
}

var unitPosition = Cartesian3.normalize(camera.position, zoom3DUnitPosition);
Expand Down Expand Up @@ -2343,10 +2395,7 @@ function tilt3DOnEllipsoid(controller, startPosition, movement) {
}

function getTiltCenterUnderground(controller, ray, pickedPosition, result) {
var distanceFromClosestSurface = getDistanceFromClosestSurface(
controller,
ray.origin
);
var distanceFromClosestSurface = getDistanceFromClosestSurface(controller);

var maximumDistance = CesiumMath.clamp(
distanceFromClosestSurface * 5.0,
Expand Down Expand Up @@ -2402,7 +2451,7 @@ function tilt3DOnTerrain(controller, startPosition, movement) {
center = Ray.getPoint(ray, intersection.start, tilt3DCenter);
}

if (controller._cameraUnderground) {
if (cameraUnderground) {
if (!defined(ray)) {
ray = camera.getPickRay(startPosition, tilt3DRay);
}
Expand Down

0 comments on commit a952848

Please sign in to comment.