Skip to content

Commit

Permalink
Merge pull request #1817 from AnalyticalGraphicsInc/camera-terrain
Browse files Browse the repository at this point in the history
Camera-Terrain interaction
  • Loading branch information
pjcozzi committed Jul 18, 2014
2 parents 383c942 + 3add858 commit 9a320fc
Show file tree
Hide file tree
Showing 26 changed files with 1,875 additions and 484 deletions.
2 changes: 0 additions & 2 deletions Apps/Sandcastle/gallery/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
camera.transform = transform;
camera.constrainedAxis = Cesium.Cartesian3.UNIT_Y;
var controller = scene.screenSpaceCameraController;
controller.ellipsoid = Cesium.Ellipsoid.UNIT_SPHERE;
controller.enableTilt = false;
var r = 1.25 * Math.max(model.boundingSphere.radius, camera.frustum.near);
controller.minimumZoomDistance = r * 0.25;
camera.lookAt(new Cesium.Cartesian3(r, r, r), Cesium.Cartesian3.ZERO, Cesium.Cartesian3.UNIT_Y);
Expand Down
8 changes: 0 additions & 8 deletions Apps/Sandcastle/gallery/Camera.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
scene.primitives.removeAll();
scene.tweens.removeAll();

var controller = scene.screenSpaceCameraController;
controller.ellipsoid = scene.globe.ellipsoid;
controller.enableTilt = true;

scene.camera.setTransform(Cesium.Matrix4.IDENTITY);

clock.multiplier = 1.0;
Expand Down Expand Up @@ -135,10 +131,6 @@
Cesium.Matrix4.clone(transform, camera.transform);
camera.constrainedAxis = Cesium.Cartesian3.UNIT_Z;

var controller = scene.screenSpaceCameraController;
controller.ellipsoid = Cesium.Ellipsoid.UNIT_SPHERE;
controller.enableTilt = false;

// Zoom in
camera.lookAt(
new Cesium.Cartesian3(-120000.0, -120000.0, 120000.0),
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Change Log
* `Rectangle.getCenter` -> `Rectangle.center`
* `CullingVolume.getVisibility` -> `CullingVolume.computeVisibility`
* `SimplePolylineGeometry` and `PolylineGeometry` positions curve to follow the ellipsoid surface by default. To disable this behavior, set the option `followSurface=false`.
* Removed `ScreenSpaceCameraController.ellipsoid`. The behavior that depended on the ellipsoid is now determined based on the scene state.
* Sandcastle examples now automatically wrap the example code in RequireJS boilerplate. To upgrade any custom examples, copy the code into an existing example (such as Hello World) and save a new file.
* Replaced `PerspectiveFrustum.fovy` with `PerspectiveFrustum.fov` which will change the field of view angle in either the x or y direction depending on the aspect ratio.
* Added northUpEast transform to help support display of glTF models because Y is their up axis.
Expand All @@ -86,6 +87,10 @@ Change Log
* Added `Primitive.ready`.
* Prevent primitives from flashing off and on when modifying static DataSources.
* Added `scene3DOnly` options to `Viewer`, `CesiumWidget`, and `Scene` constructors. This setting optimizes memory usage and performance for 3D mode at the cost of losing the ability to use 2D or Columbus View.
* Added the following methods to `IntersectionTests`: `rayTriangle`, `lineSegmentTriangle`, `raySphere`, and `lineSegmentSphere`.
* Added `Globe.getHeight` and `Globe.pick` for finding the terrain height at a given Cartographic coordinate and picking the terrain with a ray.
* Modified the default camera tilt mouse behavior to tilt about the point clicked.
* Added camera collision detection with terrain to the default mouse interaction.
* Matrix types now have `add` and `subtract` functions.
* `Matrix3` type now has a `fromCrossProduct` function.

Expand Down
83 changes: 51 additions & 32 deletions Source/Core/Ellipsoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,7 @@ define([
CesiumMath) {
"use strict";

/**
* A quadratic surface defined in Cartesian coordinates by the equation
* <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used
* by Cesium to represent the shape of planetary bodies.
*
* Rather than constructing this object directly, one of the provided
* constants is normally used.
* @alias Ellipsoid
* @constructor
*
* @param {Number} [x=0] The radius in the x direction.
* @param {Number} [y=0] The radius in the y direction.
* @param {Number} [z=0] The radius in the z direction.
*
* @exception {DeveloperError} All radii components must be greater than or equal to zero.
*
* @see Ellipsoid.fromCartesian3
* @see Ellipsoid.WGS84
* @see Ellipsoid.UNIT_SPHERE
*/
var Ellipsoid = function(x, y, z) {
function initialize(ellipsoid, x, y, z) {
x = defaultValue(x, 0.0);
y = defaultValue(y, 0.0);
z = defaultValue(z, 0.0);
Expand All @@ -50,29 +30,62 @@ define([
}
//>>includeEnd('debug');

this._radii = new Cartesian3(x, y, z);
ellipsoid._radii = new Cartesian3(x, y, z);

this._radiiSquared = new Cartesian3(x * x,
ellipsoid._radiiSquared = new Cartesian3(x * x,
y * y,
z * z);

this._radiiToTheFourth = new Cartesian3(x * x * x * x,
ellipsoid._radiiToTheFourth = new Cartesian3(x * x * x * x,
y * y * y * y,
z * z * z * z);

this._oneOverRadii = new Cartesian3(x === 0.0 ? 0.0 : 1.0 / x,
ellipsoid._oneOverRadii = new Cartesian3(x === 0.0 ? 0.0 : 1.0 / x,
y === 0.0 ? 0.0 : 1.0 / y,
z === 0.0 ? 0.0 : 1.0 / z);

this._oneOverRadiiSquared = new Cartesian3(x === 0.0 ? 0.0 : 1.0 / (x * x),
ellipsoid._oneOverRadiiSquared = new Cartesian3(x === 0.0 ? 0.0 : 1.0 / (x * x),
y === 0.0 ? 0.0 : 1.0 / (y * y),
z === 0.0 ? 0.0 : 1.0 / (z * z));

this._minimumRadius = Math.min(x, y, z);
ellipsoid._minimumRadius = Math.min(x, y, z);

this._maximumRadius = Math.max(x, y, z);
ellipsoid._maximumRadius = Math.max(x, y, z);

this._centerToleranceSquared = CesiumMath.EPSILON1;
ellipsoid._centerToleranceSquared = CesiumMath.EPSILON1;
}

/**
* A quadratic surface defined in Cartesian coordinates by the equation
* <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used
* by Cesium to represent the shape of planetary bodies.
*
* Rather than constructing this object directly, one of the provided
* constants is normally used.
* @alias Ellipsoid
* @constructor
*
* @param {Number} [x=0] The radius in the x direction.
* @param {Number} [y=0] The radius in the y direction.
* @param {Number} [z=0] The radius in the z direction.
*
* @exception {DeveloperError} All radii components must be greater than or equal to zero.
*
* @see Ellipsoid.fromCartesian3
* @see Ellipsoid.WGS84
* @see Ellipsoid.UNIT_SPHERE
*/
var Ellipsoid = function(x, y, z) {
this._radii = undefined;
this._radiiSquared = undefined;
this._radiiToTheFourth = undefined;
this._oneOverRadii = undefined;
this._oneOverRadiiSquared = undefined;
this._minimumRadius = undefined;
this._maximumRadius = undefined;
this._centerToleranceSquared = undefined;

initialize(this, x, y, z);
};

defineProperties(Ellipsoid.prototype, {
Expand Down Expand Up @@ -189,11 +202,17 @@ define([
* @see Ellipsoid.WGS84
* @see Ellipsoid.UNIT_SPHERE
*/
Ellipsoid.fromCartesian3 = function(cartesian) {
Ellipsoid.fromCartesian3 = function(cartesian, result) {
if (!defined(result)) {
result = new Ellipsoid();
}

if (!defined(cartesian)) {
return new Ellipsoid();
return result;
}
return new Ellipsoid(cartesian.x, cartesian.y, cartesian.z);

initialize(result, cartesian.x, cartesian.y, cartesian.z);
return result;
};

/**
Expand Down
Loading

0 comments on commit 9a320fc

Please sign in to comment.