Skip to content

Commit

Permalink
Merge pull request CesiumGS#3521 from AnalyticalGraphicsInc/morph
Browse files Browse the repository at this point in the history
Keep camera position during a morph when duration is 0.0
  • Loading branch information
mramato committed Mar 11, 2016
2 parents c1a4d6c + b0e3a13 commit 3e34ba2
Show file tree
Hide file tree
Showing 7 changed files with 503 additions and 402 deletions.
804 changes: 468 additions & 336 deletions Source/Scene/SceneTransitioner.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Source/Shaders/GlobeVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ vec4 getPositionMorphingMode(vec3 position, float height, vec2 textureCoordinate
// This is unlikely to be noticeable, though.
vec3 position3DWC = position + u_center3D;
float yPositionFraction = get2DYPositionFraction(textureCoordinates);
vec4 position2DWC = vec4(0.0, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0);
vec4 position2DWC = vec4(height, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0);
vec4 morphPosition = czm_columbusViewMorph(position2DWC, vec4(position3DWC, 1.0), czm_morphTime);
return czm_modelViewProjection * morphPosition;
}
Expand Down
6 changes: 6 additions & 0 deletions Specs/Scene/BillboardCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defineSuite([
'Core/loadImage',
'Core/Math',
'Core/NearFarScalar',
'Core/Rectangle',
'Renderer/ContextLimits',
'Scene/HeightReference',
'Scene/HorizontalOrigin',
Expand All @@ -32,6 +33,7 @@ defineSuite([
loadImage,
CesiumMath,
NearFarScalar,
Rectangle,
ContextLimits,
HeightReference,
HorizontalOrigin,
Expand Down Expand Up @@ -1196,6 +1198,10 @@ defineSuite([
orthoFrustum.near = 0.01 * maxRadii;
orthoFrustum.far = 60.0 * maxRadii;

camera.setView({
destination : Rectangle.fromDegrees(-60.0, -60.0, -40.0, 60.0)
});

// Update scene state
scene.morphTo2D(0);
scene.renderForSpecs();
Expand Down
16 changes: 5 additions & 11 deletions Specs/Scene/LabelCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defineSuite([
'Core/Ellipsoid',
'Core/Math',
'Core/NearFarScalar',
'Core/Rectangle',
'Renderer/ContextLimits',
'Scene/HeightReference',
'Scene/HorizontalOrigin',
Expand All @@ -26,6 +27,7 @@ defineSuite([
Ellipsoid,
CesiumMath,
NearFarScalar,
Rectangle,
ContextLimits,
HeightReference,
HorizontalOrigin,
Expand Down Expand Up @@ -1447,21 +1449,13 @@ defineSuite([
text : 'two'
});

var maxRadii = ellipsoid.maximumRadius;
var orthoFrustum = new OrthographicFrustum();
orthoFrustum.right = maxRadii * Math.PI;
orthoFrustum.left = -orthoFrustum.right;
orthoFrustum.top = orthoFrustum.right;
orthoFrustum.bottom = -orthoFrustum.top;
orthoFrustum.near = 0.01 * maxRadii;
orthoFrustum.far = 60.0 * maxRadii;
camera.setView({
destination : Rectangle.fromDegrees(-60.0, -60.0, -40.0, 60.0)
});

// Update scene state
scene.morphTo2D(0);
scene.renderForSpecs();

camera.frustum = orthoFrustum;

scene.renderForSpecs();
var actual = scene.frameState.commandList[0].boundingVolume;

Expand Down
55 changes: 12 additions & 43 deletions Specs/Scene/PickSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ defineSuite([
var scene;
var primitives;
var camera;
var primitiveRectangle = Rectangle.fromDegrees(-50.0, -50.0, 50.0, 50.0);

beforeAll(function() {
scene = createScene();
Expand Down Expand Up @@ -76,7 +77,7 @@ defineSuite([
var e = new Primitive({
geometryInstances: new GeometryInstance({
geometry: new RectangleGeometry({
rectangle: Rectangle.fromDegrees(-50.0, -50.0, 50.0, 50.0),
rectangle: primitiveRectangle,
vertexFormat: EllipsoidSurfaceAppearance.VERTEX_FORMAT,
ellipsoid: ellipsoid,
granularity: CesiumMath.toRadians(20.0)
Expand Down Expand Up @@ -320,58 +321,26 @@ defineSuite([
});

it('picks in 2D', function() {
var ellipsoid = scene.mapProjection.ellipsoid;
var maxRadii = ellipsoid.maximumRadius;

camera.position = new Cartesian3(0.0, 0.0, 2.0 * maxRadii);
Cartesian3.clone(Cartesian3.UNIT_Z, camera.direction);
Cartesian3.negate(camera.direction, camera.direction);
Cartesian3.negate(Cartesian3.UNIT_X, camera.up);
Cartesian3.clone(Cartesian3.UNIT_Y, camera.right);

var frustum = new OrthographicFrustum();
frustum.right = maxRadii * Math.PI;
frustum.left = -frustum.right;
frustum.top = frustum.right * (scene.drawingBufferHeight / scene.drawingBufferWidth);
frustum.bottom = -frustum.top;
frustum.near = 0.01 * maxRadii;
frustum.far = 60.0 * maxRadii;
camera.frustum = frustum;

scene.mode = SceneMode.SCENE2D;
scene.morphTime = SceneMode.getMorphTime(scene.mode);

camera.setView({
destination : primitiveRectangle
});
scene.morphTo2D(0.0);
var rectangle = createRectangle();
scene.initializeFrame();
var pickedObject = scene.pick(new Cartesian2(0, 0));
expect(pickedObject.primitive).toEqual(rectangle);
scene.morphTo3D(0.0);
});

it('picks in 2D when rotated', function() {
var ellipsoid = scene.mapProjection.ellipsoid;
var maxRadii = ellipsoid.maximumRadius;

camera.position = new Cartesian3(0.0, 0.0, 2.0 * maxRadii);
Cartesian3.clone(Cartesian3.UNIT_Z, camera.direction);
Cartesian3.negate(camera.direction, camera.direction);
Cartesian3.negate(Cartesian3.UNIT_X, camera.up);
Cartesian3.clone(Cartesian3.UNIT_Y, camera.right);

var frustum = new OrthographicFrustum();
frustum.right = maxRadii * Math.PI;
frustum.left = -frustum.right;
frustum.top = frustum.right * (scene.drawingBufferHeight / scene.drawingBufferWidth);
frustum.bottom = -frustum.top;
frustum.near = 0.01 * maxRadii;
frustum.far = 60.0 * maxRadii;
camera.frustum = frustum;

scene.mode = SceneMode.SCENE2D;
scene.morphTime = SceneMode.getMorphTime(scene.mode);

camera.setView({
destination : primitiveRectangle
});
scene.morphTo2D(0.0);
var rectangle = createRectangle();
scene.initializeFrame();
var pickedObject = scene.pick(new Cartesian2(0.0, 0.0));
expect(pickedObject.primitive).toEqual(rectangle);
scene.morphTo3D(0.0);
});
}, 'WebGL');
16 changes: 5 additions & 11 deletions Specs/Scene/PointPrimitiveCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defineSuite([
'Core/Color',
'Core/Math',
'Core/NearFarScalar',
'Core/Rectangle',
'Scene/OrthographicFrustum',
'Specs/createScene'
], function(
Expand All @@ -17,6 +18,7 @@ defineSuite([
Color,
CesiumMath,
NearFarScalar,
Rectangle,
OrthographicFrustum,
createScene) {
'use strict';
Expand Down Expand Up @@ -781,21 +783,13 @@ defineSuite([
position : Cartesian3.fromDegrees(-50.0, 50.0)
});

var maxRadii = ellipsoid.maximumRadius;
var orthoFrustum = new OrthographicFrustum();
orthoFrustum.right = maxRadii * Math.PI;
orthoFrustum.left = -orthoFrustum.right;
orthoFrustum.top = orthoFrustum.right;
orthoFrustum.bottom = -orthoFrustum.top;
orthoFrustum.near = 0.01 * maxRadii;
orthoFrustum.far = 60.0 * maxRadii;
camera.setView({
destination : Rectangle.fromDegrees(-60.0, -60.0, -40.0, 60.0)
});

// Update scene state
scene.morphTo2D(0);
scene.renderForSpecs();

camera.frustum = orthoFrustum;

scene.renderForSpecs();
var actual = scene.frameState.commandList[0].boundingVolume;

Expand Down
6 changes: 6 additions & 0 deletions Specs/Scene/SceneTransformsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defineSuite([
'Core/Cartesian3',
'Core/Ellipsoid',
'Core/Math',
'Core/Rectangle',
'Scene/Camera',
'Specs/createScene'
], function(
Expand All @@ -13,6 +14,7 @@ defineSuite([
Cartesian3,
Ellipsoid,
CesiumMath,
Rectangle,
Camera,
createScene) {
'use strict';
Expand Down Expand Up @@ -158,6 +160,10 @@ defineSuite([
});

it('returns correct window position in 2D', function() {
scene.camera.setView({
destination : Rectangle.fromDegrees(-0.000001, -0.000001, 0.000001, 0.000001)
});

// Update scene state
scene.morphTo2D(0);
scene.initializeFrame();
Expand Down

0 comments on commit 3e34ba2

Please sign in to comment.