Skip to content

Commit

Permalink
Merge pull request #3764 from AnalyticalGraphicsInc/models-2D
Browse files Browse the repository at this point in the history
Models 2D/CV support
  • Loading branch information
pjcozzi committed May 26, 2016
2 parents d929f97 + ad1f72c commit d8244f1
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 142 deletions.
1 change: 0 additions & 1 deletion Apps/Sandcastle/gallery/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {
scene3DOnly: true,
infoBox : false,
selectionIndicator : false
});
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Change Log
* Added `debugShowShadowVolume` to `GroundPrimitive`.
* Fixed issue where `Matrix4.fromCamera` was taking eye/target instead of position/direction. [#3927](https://github.com/AnalyticalGraphicsInc/cesium/issues/3927)
* Fixed a bug that would cause a crash is the camera was on the IDL in 2D. [#3951](https://github.com/AnalyticalGraphicsInc/cesium/issues/3951)
* Added `Scene.nearToFarDistance2D` that determines the size of each frustum of the multifrustum in 2D.
* Added support for rendering models in 2D and Columbus view.

### 1.21 - 2016-05-02

Expand Down
77 changes: 77 additions & 0 deletions Source/Core/Transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ define([
'./Cartesian2',
'./Cartesian3',
'./Cartesian4',
'./Cartographic',
'./defaultValue',
'./defined',
'./DeveloperError',
Expand All @@ -23,6 +24,7 @@ define([
Cartesian2,
Cartesian3,
Cartesian4,
Cartographic,
defaultValue,
defined,
DeveloperError,
Expand Down Expand Up @@ -820,5 +822,80 @@ define([
return result;
};

var scratchCartographic = new Cartographic();
var scratchCartesian3Projection = new Cartesian3();
var scratchCartesian3 = new Cartesian3();
var scratchCartesian4Origin = new Cartesian4();
var scratchCartesian4NewOrigin = new Cartesian4();
var scratchCartesian4NewXAxis = new Cartesian4();
var scratchCartesian4NewYAxis = new Cartesian4();
var scratchCartesian4NewZAxis = new Cartesian4();
var scratchFromENU = new Matrix4();
var scratchToENU = new Matrix4();

/**
* @private
*/
Transforms.basisTo2D = function(projection, matrix, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(projection)) {
throw new DeveloperError('projection is required.');
}
if (!defined(matrix)) {
throw new DeveloperError('matrix is required.');
}
if (!defined(result)) {
throw new DeveloperError('result is required.');
}
//>>includeEnd('debug');

var ellipsoid = projection.ellipsoid;

var origin = Matrix4.getColumn(matrix, 3, scratchCartesian4Origin);
var cartographic = ellipsoid.cartesianToCartographic(origin, scratchCartographic);

var fromENU = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, scratchFromENU);
var toENU = Matrix4.inverseTransformation(fromENU, scratchToENU);

var projectedPosition = projection.project(cartographic, scratchCartesian3Projection);
var newOrigin = scratchCartesian4NewOrigin;
newOrigin.x = projectedPosition.z;
newOrigin.y = projectedPosition.x;
newOrigin.z = projectedPosition.y;
newOrigin.w = 1.0;

var xAxis = Matrix4.getColumn(matrix, 0, scratchCartesian3);
var xScale = Cartesian3.magnitude(xAxis);
var newXAxis = Matrix4.multiplyByVector(toENU, xAxis, scratchCartesian4NewXAxis);
Cartesian4.fromElements(newXAxis.z, newXAxis.x, newXAxis.y, 0.0, newXAxis);

var yAxis = Matrix4.getColumn(matrix, 1, scratchCartesian3);
var yScale = Cartesian3.magnitude(yAxis);
var newYAxis = Matrix4.multiplyByVector(toENU, yAxis, scratchCartesian4NewYAxis);
Cartesian4.fromElements(newYAxis.z, newYAxis.x, newYAxis.y, 0.0, newYAxis);

var zAxis = Matrix4.getColumn(matrix, 2, scratchCartesian3);
var zScale = Cartesian3.magnitude(zAxis);

var newZAxis = scratchCartesian4NewZAxis;
Cartesian3.cross(newXAxis, newYAxis, newZAxis);
Cartesian3.normalize(newZAxis, newZAxis);
Cartesian3.cross(newYAxis, newZAxis, newXAxis);
Cartesian3.normalize(newXAxis, newXAxis);
Cartesian3.cross(newZAxis, newXAxis, newYAxis);
Cartesian3.normalize(newYAxis, newYAxis);

Cartesian3.multiplyByScalar(newXAxis, xScale, newXAxis);
Cartesian3.multiplyByScalar(newYAxis, yScale, newYAxis);
Cartesian3.multiplyByScalar(newZAxis, zScale, newZAxis);

Matrix4.setColumn(result, 0, newXAxis, result);
Matrix4.setColumn(result, 1, newYAxis, result);
Matrix4.setColumn(result, 2, newZAxis, result);
Matrix4.setColumn(result, 3, newOrigin, result);

return result;
};

return Transforms;
});
56 changes: 4 additions & 52 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ define([
Matrix4.inverseTransformation(camera._viewMatrix, camera._invViewMatrix);
}

function convertTransformForColumbusView(camera) {
Transforms.basisTo2D(camera._projection, camera._transform, camera._actualTransform);
}

var scratchCartographic = new Cartographic();
var scratchCartesian3Projection = new Cartesian3();
var scratchCartesian3 = new Cartesian3();
Expand All @@ -287,58 +291,6 @@ define([
var scratchCartesian4NewYAxis = new Cartesian4();
var scratchCartesian4NewZAxis = new Cartesian4();

function convertTransformForColumbusView(camera) {
var projection = camera._projection;
var ellipsoid = projection.ellipsoid;

var origin = Matrix4.getColumn(camera._transform, 3, scratchCartesian4Origin);
var cartographic = ellipsoid.cartesianToCartographic(origin, scratchCartographic);

var projectedPosition = projection.project(cartographic, scratchCartesian3Projection);
var newOrigin = scratchCartesian4NewOrigin;
newOrigin.x = projectedPosition.z;
newOrigin.y = projectedPosition.x;
newOrigin.z = projectedPosition.y;
newOrigin.w = 1.0;

var xAxis = Cartesian4.add(Matrix4.getColumn(camera._transform, 0, scratchCartesian3), origin, scratchCartesian3);
ellipsoid.cartesianToCartographic(xAxis, cartographic);

projection.project(cartographic, projectedPosition);
var newXAxis = scratchCartesian4NewXAxis;
newXAxis.x = projectedPosition.z;
newXAxis.y = projectedPosition.x;
newXAxis.z = projectedPosition.y;
newXAxis.w = 0.0;

Cartesian3.subtract(newXAxis, newOrigin, newXAxis);

var yAxis = Cartesian4.add(Matrix4.getColumn(camera._transform, 1, scratchCartesian3), origin, scratchCartesian3);
ellipsoid.cartesianToCartographic(yAxis, cartographic);

projection.project(cartographic, projectedPosition);
var newYAxis = scratchCartesian4NewYAxis;
newYAxis.x = projectedPosition.z;
newYAxis.y = projectedPosition.x;
newYAxis.z = projectedPosition.y;
newYAxis.w = 0.0;

Cartesian3.subtract(newYAxis, newOrigin, newYAxis);

var newZAxis = scratchCartesian4NewZAxis;
Cartesian3.cross(newXAxis, newYAxis, newZAxis);
Cartesian3.normalize(newZAxis, newZAxis);
Cartesian3.cross(newYAxis, newZAxis, newXAxis);
Cartesian3.normalize(newXAxis, newXAxis);
Cartesian3.cross(newZAxis, newXAxis, newYAxis);
Cartesian3.normalize(newYAxis, newYAxis);

Matrix4.setColumn(camera._actualTransform, 0, newXAxis, camera._actualTransform);
Matrix4.setColumn(camera._actualTransform, 1, newYAxis, camera._actualTransform);
Matrix4.setColumn(camera._actualTransform, 2, newZAxis, camera._actualTransform);
Matrix4.setColumn(camera._actualTransform, 3, newOrigin, camera._actualTransform);
}

function convertTransformFor2D(camera) {
var projection = camera._projection;
var ellipsoid = projection.ellipsoid;
Expand Down
Loading

0 comments on commit d8244f1

Please sign in to comment.