Skip to content

Commit

Permalink
Merge pull request #4388 from AnalyticalGraphicsInc/morph-2d-to-3d
Browse files Browse the repository at this point in the history
Fix morphing from 2D to 3D
  • Loading branch information
pjcozzi authored Oct 19, 2016
2 parents 28703a7 + 4da4375 commit 11f2aa5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Change Log
* Fixed a glTF transparency bug where `blendFuncSeparate` parameters were loaded in the wrong order. [#4435](https://github.com/AnalyticalGraphicsInc/cesium/pull/4435)
* Fixed a bug where creating a custom geometry with attributes and indices that have values that are not a typed array would cause a crash. [#4419](https://github.com/AnalyticalGraphicsInc/cesium/pull/4419)
* Fixed a bug with rotated, textured rectangles. [#4430](https://github.com/AnalyticalGraphicsInc/cesium/pull/4430)
* Fixed a bug when morphing from 2D to 3D. [#4388](https://github.com/AnalyticalGraphicsInc/cesium/pull/4388)

### 1.26 - 2016-10-03

Expand Down
4 changes: 3 additions & 1 deletion Source/Scene/QuadtreePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ define([
*/
QuadtreePrimitive.prototype.endFrame = function(frameState) {
var passes = frameState.passes;
if (!passes.render) {
if (!passes.render || frameState.mode === SceneMode.MORPHING) {
// Only process the load queue for a single pass.
// Don't process the load queue or update heights during the morph flights.
return;
}

Expand Down
58 changes: 53 additions & 5 deletions Source/Scene/SceneTransitioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,10 @@ define([
var scratch2DTo3DFrustum = new PerspectiveFrustum();

function morphFrom2DTo3D(transitioner, duration, ellipsoid) {
duration *= 0.5;
duration /= 3.0;

var scene = transitioner._scene;
var camera = scene.camera;
var frustum = scratch2DTo3DFrustum;
frustum.aspectRatio = scene.drawingBufferWidth / scene.drawingBufferHeight;
frustum.fov = CesiumMath.toRadians(60.0);
Expand All @@ -373,7 +374,6 @@ define([
Cartesian3.normalize(camera3D.direction, camera3D.direction);
Cartesian3.clone(Cartesian3.UNIT_Z, camera3D.up);
} else {
var camera = scene.camera;
camera.position.z = camera.frustum.right - camera.frustum.left;

camera3D = getColumbusViewTo3DCamera(transitioner, ellipsoid);
Expand All @@ -384,9 +384,57 @@ define([
var complete = complete3DCallback(camera3D);
createMorphHandler(transitioner, complete);

morphOrthographicToPerspective(transitioner, duration, camera3D, function() {
morphFromColumbusViewTo3D(transitioner, duration, camera3D, complete);
});
var startPos = Cartesian3.clone(camera.position, scratch3DToCVStartPos);
var startDir = Cartesian3.clone(camera.direction, scratch3DToCVStartDir);
var startUp = Cartesian3.clone(camera.up, scratch3DToCVStartUp);

var endPos = Cartesian3.fromElements(0.0, 0.0, 5.0 * ellipsoid.maximumRadius, scratch3DToCVEndPos);
var endDir = Cartesian3.negate(Cartesian3.UNIT_Z, scratch3DToCVEndDir);
var endUp = Cartesian3.clone(Cartesian3.UNIT_Y, scratch3DToCVEndUp);

var startRight = camera.frustum.right;
var endRight = endPos.z * 0.5;

function update(value) {
columbusViewMorph(startPos, endPos, value.time, camera.position);
columbusViewMorph(startDir, endDir, value.time, camera.direction);
columbusViewMorph(startUp, endUp, value.time, camera.up);
Cartesian3.cross(camera.direction, camera.up, camera.right);
Cartesian3.normalize(camera.right, camera.right);

var frustum = camera.frustum;
frustum.right = CesiumMath.lerp(startRight, endRight, value.time);
frustum.left = -frustum.right;
frustum.top = frustum.right * (scene.drawingBufferHeight / scene.drawingBufferWidth);
frustum.bottom = -frustum.top;

camera.position.z = 2.0 * scene.mapProjection.ellipsoid.maximumRadius;
}

if (duration > 0.0) {
var tween = scene.tweens.add({
duration : duration,
easingFunction : EasingFunction.QUARTIC_OUT,
startObject : {
time : 0.0
},
stopObject : {
time : 1.0
},
update : update,
complete : function() {
scene._mode = SceneMode.MORPHING;
morphOrthographicToPerspective(transitioner, duration, camera3D, function() {
morphFromColumbusViewTo3D(transitioner, duration, camera3D, complete);
});
}
});
transitioner._currentTweens.push(tween);
} else {
morphOrthographicToPerspective(transitioner, duration, camera3D, function() {
morphFromColumbusViewTo3D(transitioner, duration, camera3D, complete);
});
}
}

function columbusViewMorph(startPosition, endPosition, time, result) {
Expand Down

0 comments on commit 11f2aa5

Please sign in to comment.