Skip to content

Commit

Permalink
Updated depecated headingPitchRoll functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed Sep 26, 2017
1 parent 16cd536 commit 09e76ce
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/3D Models Coloring.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
var pitch = 0;
var roll = 0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr, undefined, undefined, undefined, true);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

entity = viewer.entities.add({
name : url,
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@
}
</script>
</body>
</html>
</html>
6 changes: 3 additions & 3 deletions Apps/Sandcastle/gallery/Classification.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

var center = new Cesium.Cartesian3(1216378.730451297, -4736275.917774027, 4081266.871000864);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-2.619728786416368, 0.0, 0.0), undefined, true);
var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-2.619728786416368, 0.0, 0.0));
var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.0, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

Expand Down Expand Up @@ -91,7 +91,7 @@

var center = new Cesium.Cartesian3(1216398.6054139996, -4736204.533089285, 4081338.6585485404);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0), undefined, true);
var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0));
var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.4, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

Expand All @@ -111,7 +111,7 @@

center = new Cesium.Cartesian3(1216394.3346955755, -4736207.431365568, 4081336.7768881875);
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0), undefined, true);
hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0));
hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(-0.25, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Distance Display Conditions.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
var position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883, 0.0);
var heading = Cesium.Math.toRadians(135);
var hpr = new Cesium.HeadingPitchRoll(-heading, 0.0, 0.0);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr, undefined, undefined, undefined, true);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

viewer.entities.add({
position : position,
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/HeadingPitchRoll.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h1>Loading...</h1>

var planePrimitive = scene.primitives.add(Cesium.Model.fromGltf({
url : '../../SampleData/models/CesiumAir/Cesium_Air.glb',
modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, undefined, true),
modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform),
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.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, planePrimitive.modelMatrix, true);
Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, planePrimitive.modelMatrix);

if (fromBehind.checked) {
// Zoom to model
Expand Down
6 changes: 3 additions & 3 deletions Apps/Sandcastle/gallery/LocalToFixedFrame.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ <h1>Loading...</h1>
var comments = localFrames[i].comments;
var planePrimitive = scene.primitives.add(Cesium.Model.fromGltf({
url : '../../SampleData/models/CesiumAir/Cesium_Air.glb',
modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, undefined, true),
modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter),
minimumPixelSize : 128
}));

primitives.push({primitive : planePrimitive, converter : converter, position : position});
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(position, hprRollZero, Cesium.Ellipsoid.WGS84, converter, undefined, true);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(position, hprRollZero, Cesium.Ellipsoid.WGS84, converter);
scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
modelMatrix : modelMatrix,
length : 300.0,
Expand Down Expand Up @@ -221,7 +221,7 @@ <h1>Loading...</h1>
var primitive = primitives[i].primitive;
var converter = primitives[i].converter;
var position = primitives[i].position;
Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, primitive.modelMatrix, true);
Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, primitive.modelMatrix);
}
});
//Sandcastle_End
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Projection.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 0.0);
var hpr = new Cesium.HeadingPitchRoll(-Cesium.Math.toRadians(135), 0.0, 0.0);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr, undefined, undefined, undefined, true);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

var entity = viewer.entities.add({
position : position,
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/development/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);

var origin = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, hpr, undefined, undefined, undefined, true);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, hpr);

scene.primitives.removeAll(); // Remove previous model
model = scene.primitives.add(Cesium.Model.fromGltf({
Expand Down
22 changes: 8 additions & 14 deletions Source/Core/HeadingPitchRoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,32 @@ define([
/**
* Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
*
* @deprecated since V1.38. An optional boolean flag can be supplied to this function that, if true, uses the classical orientation of heading and pitch calculated counter-clockwise. The flag will be removed and the new behavior made default in 1.40
* @param {Quaternion} quaternion The quaternion from which to retrieve heading, pitch, and roll, all expressed in radians.
* @param {HeadingPitchRoll} [result] The object in which to store the result. If not provided, a new instance is created and returned.
* @param {Boolean} [false] Indicates if the function uses the classical orientation of heading and pitch (counter-clockwise).
* @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided.
*/
HeadingPitchRoll.fromQuaternion = function(quaternion, result, classical) {
HeadingPitchRoll.fromQuaternion = function(quaternion, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(quaternion)) {
throw new DeveloperError('quaternion is required');
}
//>>includeEnd('debug');

deprecationWarning('HeadingPitchRoll.fromQuaternion', 'This function now uses a counter-clockwise orientation as per mathematical conventions. This deprecation warning will be removed in Cesium 1.40.');

if (!defined(result)) {
result = new HeadingPitchRoll();
}
classical = defaultValue(classical, false);

var test = 2 * (quaternion.w * quaternion.y - quaternion.z * quaternion.x);
var denominatorRoll = 1 - 2 * (quaternion.x * quaternion.x + quaternion.y * quaternion.y);
var numeratorRoll = 2 * (quaternion.w * quaternion.x + quaternion.y * quaternion.z);
var denominatorHeading = 1 - 2 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z);
var numeratorHeading = 2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y);

if(classical === true){
result.heading = Math.atan2(numeratorHeading, denominatorHeading);
result.roll = Math.atan2(numeratorRoll, denominatorRoll);
result.pitch = Math.asin(test);
} else {
deprecationWarning('HeadingPitchRoll.fromQuaternion', 'This HeadingPitchRoll.fromQuaternion works in the Cesium legacy fashion which means that heading and pitch is opposite of the classical interpretation used in mathematics. This behavior will be corrected in 1.40 in order to be classical. The new behavior can be evaluate using parameter classical setted to true');
result.heading = -Math.atan2(numeratorHeading, denominatorHeading);
result.roll = Math.atan2(numeratorRoll, denominatorRoll);
result.pitch = -Math.asin(test);
}
result.heading = -Math.atan2(numeratorHeading, denominatorHeading);
result.roll = Math.atan2(numeratorRoll, denominatorRoll);
result.pitch = -Math.asin(test);

return result;
};
Expand Down
29 changes: 9 additions & 20 deletions Source/Core/Matrix3.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,16 @@ define([
/**
* Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
*
* @deprecated since V1.38. An optional boolean flag can be supplied to this function that, if true, uses the classical orientation of heading and pitch calculated counter-clockwise. The flag will be removed and the new behavior made default in 1.40
* @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.
* @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
* @param {Boolean} [false] Indicates if the function uses the classical orientation of heading and pitch (counter-clockwise).
* @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll.
*/
Matrix3.fromHeadingPitchRoll = function(headingPitchRoll, result, classical) {
Matrix3.fromHeadingPitchRoll = function(headingPitchRoll, result) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object('headingPitchRoll', headingPitchRoll);
//>>includeEnd('debug');
classical = defaultValue(classical, false);

deprecationWarning('Matrix3.fromHeadingPitchRoll', 'This function now uses a counter-clockwise orientation as per mathematical conventions. This deprecation warning will be removed in Cesium 1.40.');

var cosTheta;
var cosPsi;
Expand All @@ -316,22 +315,12 @@ define([
var sinPsi;
var sinPhi;

if(classical === true){
cosTheta = Math.cos(headingPitchRoll.pitch);
cosPsi = Math.cos(headingPitchRoll.heading);
cosPhi = Math.cos(headingPitchRoll.roll);
sinTheta = Math.sin(headingPitchRoll.pitch);
sinPsi = Math.sin(headingPitchRoll.heading);
sinPhi = Math.sin(headingPitchRoll.roll);
} else {
deprecationWarning('Matrix3.fromHeadingPitchRoll', 'This Matrix3.fromHeadingPitchRoll works in the Cesium legacy fashion which means that heading and pitch is opposite of the classical interpretation used in mathematics. This behavior will be corrected in 1.40 in order to be classical. The new behavior can be evaluate using parameter classical setted to true');
cosTheta = Math.cos(-headingPitchRoll.pitch);
cosPsi = Math.cos(-headingPitchRoll.heading);
cosPhi = Math.cos(headingPitchRoll.roll);
sinTheta = Math.sin(-headingPitchRoll.pitch);
sinPsi = Math.sin(-headingPitchRoll.heading);
sinPhi = Math.sin(headingPitchRoll.roll);
}
cosTheta = Math.cos(headingPitchRoll.pitch);
cosPsi = Math.cos(headingPitchRoll.heading);
cosPhi = Math.cos(headingPitchRoll.roll);
sinTheta = Math.sin(headingPitchRoll.pitch);
sinPsi = Math.sin(headingPitchRoll.heading);
sinPhi = Math.sin(headingPitchRoll.roll);

var m00 = cosTheta * cosPsi;
var m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;
Expand Down
25 changes: 8 additions & 17 deletions Source/Core/Quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,31 +181,22 @@ define([
* Computes a rotation from the given heading, pitch and roll angles. Heading is the rotation about the
* negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about
* the positive x axis.
* @deprecated since V1.38. An optional boolean flag can be supplied to this function that, if true, uses the classical orientation of heading and pitch calculated counter-clockwise. The flag will be removed and the new behavior made default in 1.40
*
* @param {HeadingPitchRoll} headingPitchRoll The rotation expressed as a heading, pitch and roll.
* @param {Quaternion} [result] The object onto which to store the result.
* @param {Boolean} [false] Indicates if the function uses the classical orientation of heading and pitch (counter-clockwise).
* @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided.
*/
Quaternion.fromHeadingPitchRoll = function(headingPitchRoll, result, classical) {
Quaternion.fromHeadingPitchRoll = function(headingPitchRoll, result) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object('headingPitchRoll', headingPitchRoll);
//>>includeEnd('debug');
classical = defaultValue(classical, false);

if(classical === true){
scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion);
scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, headingPitchRoll.pitch, result);
result = Quaternion.multiply(scratchPitchQuaternion, scratchRollQuaternion, scratchPitchQuaternion);
scratchHeadingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, headingPitchRoll.heading, scratchHPRQuaternion);
}else{
deprecationWarning('Quaternion.fromHeadingPitchRoll', 'This Quaternion.fromHeadingPitchRoll works in the Cesium legacy fashion which means that heading and pitch is opposite of the classical interpretation used in mathematics. This behavior will be corrected in 1.40 in order to be classical. The new behavior can be evaluate using parameter classical setted to true');
scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion);
scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, -headingPitchRoll.pitch, result);
result = Quaternion.multiply(scratchPitchQuaternion, scratchRollQuaternion, scratchPitchQuaternion);
scratchHeadingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, -headingPitchRoll.heading, scratchHPRQuaternion);
}

deprecationWarning('Quaternion.fromHeadingPitchRoll', 'This function now uses a counter-clockwise orientation as per mathematical conventions. This deprecation warning will be removed in Cesium 1.40.');

scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion);
scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, -headingPitchRoll.pitch, result);
result = Quaternion.multiply(scratchPitchQuaternion, scratchRollQuaternion, scratchPitchQuaternion);
scratchHeadingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, -headingPitchRoll.heading, scratchHPRQuaternion);

return Quaternion.multiply(scratchHeadingQuaternion, result, result);
};
Expand Down
Loading

0 comments on commit 09e76ce

Please sign in to comment.