Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up HeadingPitchRoll API #4498

Merged
merged 18 commits into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Apps/Sandcastle/gallery/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
var heading = Cesium.Math.toRadians(135);
var pitch = 0;
var roll = 0;
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, heading, pitch, roll);
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

var entity = viewer.entities.add({
name : url,
Expand Down
3 changes: 2 additions & 1 deletion Apps/Sandcastle/gallery/Distance Display Conditions.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@

var position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883, 0.0);
var heading = Cesium.Math.toRadians(135);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, heading, 0.0, 0.0);
var hpr = new Cesium.HeadingPitchRoll(heading, 0.0, 0.0);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

viewer.entities.add({
position : position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,8 @@
var scene = viewer.scene;

var height = 250000.0;
var heading = 0.0;
var pitch = 0.0;
var roll = 0.0;
var origin = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, heading, pitch, roll);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, new Cesium.HeadingPitchRoll());

var model = scene.primitives.add(Cesium.Model.fromGltf({
url : modelUrl,
Expand Down
3 changes: 2 additions & 1 deletion Apps/Sandcastle/gallery/development/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
heading = Cesium.defaultValue(heading, 0.0);
pitch = Cesium.defaultValue(pitch, 0.0);
roll = Cesium.defaultValue(roll, 0.0);
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);

var origin = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, heading, pitch, roll);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, hpr);

scene.primitives.removeAll(); // Remove previous model
var model = scene.primitives.add(Cesium.Model.fromGltf({
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/development/HeadingPitchRoll.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h1>Loading...</h1>

var planePrimitive = scene.primitives.add(Cesium.Model.fromGltf({
url : '../../SampleData/models/CesiumAir/Cesium_Air.glb',
modelMatrix : Cesium.Transforms.aircraftHeadingPitchRollToFixedFrame(position, hpRoll),
modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll),
minimumPixelSize : 128
}));

Expand Down Expand Up @@ -208,7 +208,7 @@ <h1>Loading...</h1>
speedVector = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.UNIT_X, speed / 10, speedVector);
position = Cesium.Matrix4.multiplyByPoint(planePrimitive.modelMatrix, speedVector, position);
pathPosition.addSample(Cesium.JulianDate.now(), position);
Cesium.Transforms.aircraftHeadingPitchRollToFixedFrame(position, hpRoll, undefined, planePrimitive.modelMatrix);
Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, undefined, planePrimitive.modelMatrix);

if (fromBehind.checked) {
// Zoom to model
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/development/Multiple Shadows.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

var model = scene.primitives.add(Cesium.Model.fromGltf({
url : '../../SampleData/models/ShadowTester/Shadow_Tester_Point.gltf',
modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(center, heading, 0.0, 0.0)
modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(center, new Cesium.HeadingPitchRoll(heading, 0.0, 0.0))
}));

model.readyPromise.then(function(model) {
Expand Down
8 changes: 4 additions & 4 deletions Apps/Sandcastle/gallery/development/Shadows.html
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
}

function createModel(url, origin) {
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, 0.0, 0.0, 0.0);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, new Cesium.HeadingPitchRoll());

var model = scene.primitives.add(Cesium.Model.fromGltf({
url : url,
Expand All @@ -606,7 +606,7 @@
}

function createBoxRTC(origin) {
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, 0.0, 0.0, 0.0);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, new Cesium.HeadingPitchRoll());

var boxGeometry = Cesium.BoxGeometry.createGeometry(Cesium.BoxGeometry.fromDimensions({
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
Expand Down Expand Up @@ -645,7 +645,7 @@
}

function createBox(origin) {
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, 0.0, 0.0, 0.0);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, new Cesium.HeadingPitchRoll());

var box = new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
Expand All @@ -670,7 +670,7 @@
}

function createSphere(origin) {
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, 0.0, 0.0, 0.0);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, new Cesium.HeadingPitchRoll());

var sphere = new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
Expand Down
3 changes: 1 addition & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ Change Log
* Removed an unnecessary reprojection of Web Mercator imagery tiles to the Geographic projection on load. This should improve both visual quality and load performance slightly.
* Fix a issue where a billboard entity would not render after toggling the show propery. [#4408](https://github.com/AnalyticalGraphicsInc/cesium/issues/4408)
* Added `Transforms.northUpEastToFixedFrame` to compute a 4x4 local transformation matrix from a reference frame with an north-west-up axes.
* Added `Transforms.aircraftHeadingPitchRollToFixedFrame` to create a local frame from a position and heading/pitch/roll angles. The local frame is north-west-up axed.
* Added `Transforms.aircraftHeadingPitchRollQuaternion` which is the quaternion rotation from `Transforms.aircraftHeadingPitchRollToFixedFrame`.
* Added `HeadingPitchRoll` :
* `HeadingPitchRoll.fromQuaternion` function for retrieving heading-pitch-roll angles from a quaternion.
* `HeadingPitchRoll.fromDegrees` function that returns a new HeadingPitchRoll instance from angles given in degrees.
* `HeadingPitchRoll.clone` function to duplicate HeadingPitchRoll instance.
* `HeadingPitchRoll.equals` and `HeadingPitchRoll.equalsEpsilon` functions for comparing two instances.
* Added `Matrix3.fromHeadingPitchRoll` Computes a 3x3 rotation matrix from the provided headingPitchRoll.
* `Transforms.headingPitchRollToFixedFrame` and `Transforms.headingPitchRollQuaternion` now take a `HeadingPitchRoll` object in addition to separate heading, pitch, and roll values. Separate values will be deprecated in 1.30.

### 1.26 - 2016-10-03

Expand Down
112 changes: 35 additions & 77 deletions Source/Core/Transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define([
'./Cartographic',
'./defaultValue',
'./defined',
'./deprecationWarning',
'./DeveloperError',
'./EarthOrientationParameters',
'./EarthOrientationParametersSample',
Expand All @@ -28,6 +29,7 @@ define([
Cartographic,
defaultValue,
defined,
deprecationWarning,
DeveloperError,
EarthOrientationParameters,
EarthOrientationParametersSample,
Expand Down Expand Up @@ -457,9 +459,7 @@ define([
* are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.
*
* @param {Cartesian3} origin The center point of the local reference frame.
* @param {Number} heading The heading angle in radians.
* @param {Number} pitch The pitch angle in radians.
* @param {Number} roll The roll angle in radians.
* @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
* @param {Matrix4} [result] The object onto which to store the result.
* @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
Expand All @@ -472,51 +472,27 @@ define([
* var roll = 0.0;
* var transform = Cesium.Transforms.headingPitchRollToFixedFrame(center, heading, pitch, roll);
*/
Transforms.headingPitchRollToFixedFrame = function(origin, heading, pitch, roll, ellipsoid, result) {
Transforms.headingPitchRollToFixedFrame = function(origin, headingPitchRoll, pitch, roll, ellipsoid, result) {
var heading;
if (typeof headingPitchRoll === 'object') {
// Shift arguments using assignments to encourage JIT optimization.
ellipsoid = pitch;
result = roll;
heading = headingPitchRoll.heading;
pitch = headingPitchRoll.pitch;
roll = headingPitchRoll.roll;
} else {
deprecationWarning('headingPitchRollToFixedFrame', 'headingPitchRollToFixedFrame with separate heading, pitch, and roll arguments was deprecated in 1.27. It will be removed in 1.30. Use a HeadingPitchRoll object.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submit an issue to remove this deprecated feature.

heading = headingPitchRoll;
}
// checks for required parameters happen in the called functions
var hprQuaternion = Quaternion.fromHeadingPitchRoll(heading, pitch, roll, scratchHPRQuaternion);
var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4);
result = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, result);
return Matrix4.multiply(result, hprMatrix, result);
};

/**
* Computes a 4x4 transformation matrix from a reference frame with axes computed from the heading-pitch-roll angles
* centered at the provided origin to the provided ellipsoid's fixed reference frame. Heading is the rotation from the local north
* direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles
* are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.
*
* @param {Cartesian3} origin The center point of the local reference frame.
* @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, roll angles to apply.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
* @param {Matrix4} [result] The object onto which to store the result.
* @returns {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided.
*
* @example
* // Get the transform from local heading-pitch-roll at cartographic (0.0, 0.0) to Earth's fixed frame.
* var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
* var hpr = new HeadingPitchRoll(0.0, 0.0, 0.0);
* var hpr.heading = -Cesium.Math.PI_OVER_TWO;
* var hpr.pitch = Cesium.Math.PI_OVER_FOUR;
* var hpr.roll = 0.0;
* var transform = Cesium.Transforms.aircraftHeadingPitchRollToFixedFrame(center, hpr);
*/
Transforms.aircraftHeadingPitchRollToFixedFrame = function(origin, headingPitchRoll, ellipsoid, result) {
// checks for required parameters happen in the called functions
//>>includeStart('debug', pragmas.debug);
if (!defined(origin)) {
throw new DeveloperError('origin is required.');
}
if (!defined(headingPitchRoll)) {
throw new DeveloperError('headingPitchRoll is required.');
}
//>>includeEnd('debug');
var hprQuaternion = Quaternion.fromHeadingPitchRoll(headingPitchRoll.heading, headingPitchRoll.pitch, headingPitchRoll.roll, scratchHPRQuaternion);
var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4);
result = Transforms.northWestUpToFixedFrame(origin, ellipsoid, result);
return Matrix4.multiply(result, hprMatrix, result);
};

var scratchHPR = new HeadingPitchRoll();
var scratchENUMatrix4 = new Matrix4();
var scratchHPRMatrix3 = new Matrix3();

Expand All @@ -527,9 +503,7 @@ define([
* are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.
*
* @param {Cartesian3} origin The center point of the local reference frame.
* @param {Number} heading The heading angle in radians.
* @param {Number} pitch The pitch angle in radians.
* @param {Number} roll The roll angle in radians.
* @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
* @param {Quaternion} [result] The object onto which to store the result.
* @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.
Expand All @@ -540,41 +514,25 @@ define([
* var heading = -Cesium.Math.PI_OVER_TWO;
* var pitch = Cesium.Math.PI_OVER_FOUR;
* var roll = 0.0;
* var quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, heading, pitch, roll);
*/
Transforms.headingPitchRollQuaternion = function(origin, heading, pitch, roll, ellipsoid, result) {
// checks for required parameters happen in the called functions
var transform = Transforms.headingPitchRollToFixedFrame(origin, heading, pitch, roll, ellipsoid, scratchENUMatrix4);
var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3);
return Quaternion.fromRotationMatrix(rotation, result);
};

/**
* Computes a quaternion from a reference frame with axes computed from the heading-pitch-roll angles
* centered at the provided origin. Heading is the rotation from the local north
* direction where a positive angle is increasing eastward. Pitch is the rotation from the local east-north plane. Positive pitch angles
* are above the plane. Negative pitch angles are below the plane. Roll is the first rotation applied about the local east axis.
*
* @param {Cartesian3} origin The center point of the local reference frame.
* @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, roll angles to apply.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation.
* @param {Quaternion} [result] The object onto which to store the result.
* @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.
*
* @example
* // Get the quaternion from local heading-pitch-roll at cartographic (0.0, 0.0) to Earth's fixed frame.
* var center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
* var hpr = new HeadingPitchRoll(0.0, 0.0, 0.0);
* var hpr.heading = -Cesium.Math.PI_OVER_TWO;
* var hpr.pitch = Cesium.Math.PI_OVER_FOUR;
* var hpr.roll = 0.0;
* var quaternion = Cesium.Transforms.aircraftHeadingPitchRollQuaternion(center, hpr);
*
*
* var hpr = new HeadingPitchRoll(heading, pitch, roll);
* var quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr);
*/
Transforms.aircraftHeadingPitchRollQuaternion = function(origin, headingPitchRoll, ellipsoid, result) {
Transforms.headingPitchRollQuaternion = function(origin, headingPitchRoll, pitch, roll, ellipsoid, result) {
var hpr;
if (typeof headingPitchRoll === 'object') {
// Shift arguments using assignment to encourage JIT optimization.
hpr = headingPitchRoll;
ellipsoid = pitch;
result = roll;
} else {
deprecationWarning('headingPitchRollQuaternion', 'headingPitchRollQuaternion with separate heading, pitch, and roll arguments was deprecated in 1.27. It will be removed in 1.30. Use a HeadingPitchRoll object.');
scratchHPR.heading = headingPitchRoll;
scratchHPR.pitch = pitch;
scratchHPR.roll = roll;
hpr = scratchHPR;
}
// checks for required parameters happen in the called functions
var transform = Transforms.aircraftHeadingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, scratchENUMatrix4);
var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid, scratchENUMatrix4);
var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3);
return Quaternion.fromRotationMatrix(rotation, result);
};
Expand Down
Loading