From b12bf9dde5fecd76970203b6c428e48006f8f552 Mon Sep 17 00:00:00 2001 From: Farouk Abdou Date: Sat, 4 Mar 2017 08:40:20 +0100 Subject: [PATCH 1/8] make heading pitch roll counter clock wise again --- Source/Core/HeadingPitchRoll.js | 4 ++-- Source/Core/Matrix3.js | 8 ++++---- Source/Core/Quaternion.js | 4 ++-- Source/Scene/Camera.js | 10 ++++++---- Specs/Core/QuaternionSpec.js | 12 ++++++------ 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index 6428fc73a83b..513baae2c0f6 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -49,9 +49,9 @@ define([ 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); - result.heading = -Math.atan2(numeratorHeading, denominatorHeading); + result.heading = Math.atan2(numeratorHeading, denominatorHeading); result.roll = Math.atan2(numeratorRoll, denominatorRoll); - result.pitch = -Math.asin(test); + result.pitch = Math.asin(test); return result; }; diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index 9cbf90c63002..b0846dd2d755 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -305,11 +305,11 @@ define([ Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - var cosTheta = Math.cos(-headingPitchRoll.pitch); - var cosPsi = Math.cos(-headingPitchRoll.heading); + var cosTheta = Math.cos(headingPitchRoll.pitch); + var cosPsi = Math.cos(headingPitchRoll.heading); var cosPhi = Math.cos(headingPitchRoll.roll); - var sinTheta = Math.sin(-headingPitchRoll.pitch); - var sinPsi = Math.sin(-headingPitchRoll.heading); + var sinTheta = Math.sin(headingPitchRoll.pitch); + var sinPsi = Math.sin(headingPitchRoll.heading); var sinPhi = Math.sin(headingPitchRoll.roll); var m00 = cosTheta * cosPsi; diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index cd19446e2fc8..971e99dd0111 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -210,9 +210,9 @@ define([ hpr = new HeadingPitchRoll(headingOrHeadingPitchRoll, pitchOrResult, roll); } scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, hpr.roll, scratchHPRQuaternion); - scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, -hpr.pitch, result); + scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, hpr.pitch, result); result = Quaternion.multiply(scratchPitchQuaternion, scratchRollQuaternion, scratchPitchQuaternion); - scratchHeadingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, -hpr.heading, scratchHPRQuaternion); + scratchHeadingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, hpr.heading, scratchHPRQuaternion); return Quaternion.multiply(scratchHeadingQuaternion, result, result); }; diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index d2ee120847fc..d7fb19b74a67 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -971,7 +971,8 @@ define([ camera._setTransform(localTransform); Cartesian3.clone(Cartesian3.ZERO, camera.position); - hpr.heading = hpr.heading - CesiumMath.PI_OVER_TWO; + hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; + hpr.pitch = -hpr.pitch; var rotQuat = Quaternion.fromHeadingPitchRoll(hpr, scratchSetViewQuaternion); var rotMat = Matrix3.fromQuaternion(rotQuat, scratchSetViewMatrix3); @@ -995,7 +996,8 @@ define([ } Cartesian3.clone(position, camera.position); } - hpr.heading = hpr.heading - CesiumMath.PI_OVER_TWO; + hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; + hpr.pitch = -hpr.pitch; var rotQuat = Quaternion.fromHeadingPitchRoll(hpr, scratchSetViewQuaternion); var rotMat = Matrix3.fromQuaternion(rotQuat, scratchSetViewMatrix3); @@ -1034,8 +1036,8 @@ define([ } if (camera._scene.mapMode2D === MapMode2D.ROTATE) { - hpr.heading = hpr.heading - CesiumMath.PI_OVER_TWO; - hpr.pitch = -CesiumMath.PI_OVER_TWO; + hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; + hpr.pitch = CesiumMath.PI_OVER_TWO; hpr.roll = 0.0; var rotQuat = Quaternion.fromHeadingPitchRoll(hpr, scratchSetViewQuaternion); var rotMat = Matrix3.fromQuaternion(rotQuat, scratchSetViewMatrix3); diff --git a/Specs/Core/QuaternionSpec.js b/Specs/Core/QuaternionSpec.js index ca4861320cab..5cb723d20b48 100644 --- a/Specs/Core/QuaternionSpec.js +++ b/Specs/Core/QuaternionSpec.js @@ -109,14 +109,14 @@ defineSuite([ var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll(angle, 0.0, 0.0); var quaternion = Quaternion.fromHeadingPitchRoll(hpr); - expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(-angle), CesiumMath.EPSILON11); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(angle), CesiumMath.EPSILON11); }); it('fromHeadingPitchRoll with just pitch', function() { var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll(0.0, angle, 0.0); var quaternion = Quaternion.fromHeadingPitchRoll(hpr); - expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(-angle), CesiumMath.EPSILON11); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(angle), CesiumMath.EPSILON11); }); it('fromHeadingPitchRoll with just roll', function() { @@ -131,8 +131,8 @@ defineSuite([ var hpr = new HeadingPitchRoll( angle, angle, angle); var quaternion = Quaternion.fromHeadingPitchRoll(hpr); var expected = Matrix3.fromRotationX(angle); - Matrix3.multiply(Matrix3.fromRotationY(-angle), expected, expected); - Matrix3.multiply(Matrix3.fromRotationZ(-angle), expected, expected); + Matrix3.multiply(Matrix3.fromRotationY(angle), expected, expected); + Matrix3.multiply(Matrix3.fromRotationZ(angle), expected, expected); expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); @@ -143,8 +143,8 @@ defineSuite([ var hpr = new HeadingPitchRoll( heading, pitch, roll); var quaternion = Quaternion.fromHeadingPitchRoll(hpr); var expected = Matrix3.fromRotationX(roll); - Matrix3.multiply(Matrix3.fromRotationY(-pitch), expected, expected); - Matrix3.multiply(Matrix3.fromRotationZ(-heading), expected, expected); + Matrix3.multiply(Matrix3.fromRotationY(pitch), expected, expected); + Matrix3.multiply(Matrix3.fromRotationZ(heading), expected, expected); expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); From a8234af315ecc6c8c92b5339ded79d4e78b04bcb Mon Sep 17 00:00:00 2001 From: Farouk Abdou Date: Sun, 3 Sep 2017 09:50:37 +0200 Subject: [PATCH 2/8] Added warning and create separate functions --- .../gallery/3D Models Coloring.html | 4 +- Apps/Sandcastle/gallery/Classification.html | 6 +- .../gallery/Distance Display Conditions.html | 4 +- Apps/Sandcastle/gallery/HeadingPitchRoll.html | 4 +- .../Sandcastle/gallery/LocalToFixedFrame.html | 6 +- Apps/Sandcastle/gallery/Projection.html | 4 +- .../gallery/development/3D Models.html | 6 +- CHANGES.md | 16 ++ Source/Core/HeadingPitchRoll.js | 35 ++- Source/Core/Matrix3.js | 56 +++- Source/Core/Quaternion.js | 29 +- Source/Core/Transforms.js | 78 +++++- Source/Scene/Camera.js | 9 +- Specs/Core/HeadingPitchRollSpec.js | 32 +++ Specs/Core/Matrix3Spec.js | 51 ++++ Specs/Core/QuaternionSpec.js | 65 ++++- Specs/Core/TransformsSpec.js | 249 +++++++++++++++++- Specs/Scene/ModelInstanceCollectionSpec.js | 4 +- 18 files changed, 616 insertions(+), 42 deletions(-) diff --git a/Apps/Sandcastle/gallery/3D Models Coloring.html b/Apps/Sandcastle/gallery/3D Models Coloring.html index 979c9a6f955a..edf0acd58ebb 100644 --- a/Apps/Sandcastle/gallery/3D Models Coloring.html +++ b/Apps/Sandcastle/gallery/3D Models Coloring.html @@ -172,11 +172,11 @@ viewer.entities.removeAll(); var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height); - var heading = Cesium.Math.toRadians(135); + var heading = -Cesium.Math.toRadians(135); var pitch = 0; var roll = 0; var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); - var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); + var orientation = Cesium.Transforms.directHeadingPitchRollQuaternion(position, hpr); entity = viewer.entities.add({ name : url, diff --git a/Apps/Sandcastle/gallery/Classification.html b/Apps/Sandcastle/gallery/Classification.html index b5ec8301a0bc..84034bcb43ca 100644 --- a/Apps/Sandcastle/gallery/Classification.html +++ b/Apps/Sandcastle/gallery/Classification.html @@ -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)); + var hprRotation = Cesium.Matrix3.fromDirectHeadingPitchRoll(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); @@ -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)); + var hprRotation = Cesium.Matrix3.fromDirectHeadingPitchRoll(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); @@ -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)); + hprRotation = Cesium.Matrix3.fromDirectHeadingPitchRoll(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); diff --git a/Apps/Sandcastle/gallery/Distance Display Conditions.html b/Apps/Sandcastle/gallery/Distance Display Conditions.html index d4475cabe5d8..83a85e13f154 100644 --- a/Apps/Sandcastle/gallery/Distance Display Conditions.html +++ b/Apps/Sandcastle/gallery/Distance Display Conditions.html @@ -54,8 +54,8 @@ 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); + var hpr = new Cesium.HeadingPitchRoll(-heading, 0.0, 0.0); + var orientation = Cesium.Transforms.directHeadingPitchRollQuaternion(position, hpr); viewer.entities.add({ position : position, diff --git a/Apps/Sandcastle/gallery/HeadingPitchRoll.html b/Apps/Sandcastle/gallery/HeadingPitchRoll.html index 6dc4987bf4eb..989e66ee5762 100644 --- a/Apps/Sandcastle/gallery/HeadingPitchRoll.html +++ b/Apps/Sandcastle/gallery/HeadingPitchRoll.html @@ -110,7 +110,7 @@

Loading...

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), + modelMatrix : Cesium.Transforms.directHeadingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform), minimumPixelSize : 128 })); @@ -208,7 +208,7 @@

Loading...

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); + Cesium.Transforms.directHeadingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, planePrimitive.modelMatrix); if (fromBehind.checked) { // Zoom to model diff --git a/Apps/Sandcastle/gallery/LocalToFixedFrame.html b/Apps/Sandcastle/gallery/LocalToFixedFrame.html index e2ac326ceee2..0c3c7afb014d 100644 --- a/Apps/Sandcastle/gallery/LocalToFixedFrame.html +++ b/Apps/Sandcastle/gallery/LocalToFixedFrame.html @@ -110,12 +110,12 @@

Loading...

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), + modelMatrix : Cesium.Transforms.directHeadingPitchRollToFixedFrame(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); + var modelMatrix = Cesium.Transforms.directHeadingPitchRollToFixedFrame(position, hprRollZero, Cesium.Ellipsoid.WGS84, converter); scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({ modelMatrix : modelMatrix, length : 300.0, @@ -221,7 +221,7 @@

Loading...

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); + Cesium.Transforms.directHeadingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, primitive.modelMatrix); } }); //Sandcastle_End diff --git a/Apps/Sandcastle/gallery/Projection.html b/Apps/Sandcastle/gallery/Projection.html index faa01ed692d1..c9ee5facb843 100644 --- a/Apps/Sandcastle/gallery/Projection.html +++ b/Apps/Sandcastle/gallery/Projection.html @@ -36,8 +36,8 @@ viewer.projectionPicker.viewModel.switchToOrthographic(); 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); +var hpr = new Cesium.HeadingPitchRoll(-Cesium.Math.toRadians(135), 0.0, 0.0); +var orientation = Cesium.Transforms.directHeadingPitchRollQuaternion(position, hpr); var entity = viewer.entities.add({ position : position, diff --git a/Apps/Sandcastle/gallery/development/3D Models.html b/Apps/Sandcastle/gallery/development/3D Models.html index 9739f74752ef..5634f1c11e84 100644 --- a/Apps/Sandcastle/gallery/development/3D Models.html +++ b/Apps/Sandcastle/gallery/development/3D Models.html @@ -123,13 +123,13 @@ function createModel(url, height, heading, pitch, roll) { height = Cesium.defaultValue(height, 0.0); - heading = Cesium.defaultValue(heading, 0.0); - pitch = Cesium.defaultValue(pitch, 0.0); + 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, hpr); + var modelMatrix = Cesium.Transforms.directHeadingPitchRollToFixedFrame(origin, hpr); scene.primitives.removeAll(); // Remove previous model model = scene.primitives.add(Cesium.Model.fromGltf({ diff --git a/CHANGES.md b/CHANGES.md index aa13b9f20e12..6982b04e1b61 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,21 @@ Change Log ========== +### 1.38 - 2017-10-01 + +* Breaking changes + +* Deprecated + * `HeadingPitchRoll.fromDirectQuaternion` is deprecated and his behaviour will replace `HeadingPitchRoll.fromQuaternion` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `Matrix3.fromDirectHeadingPitchRoll` is deprecated and his behaviour will replace `Matrix3.fromHeadingPitchRoll` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `Quaternion.fromDirectHeadingPitchRoll` is deprecated and his behaviour will replace `Quaternion.fromHeadingPitchRoll` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `Transforms.directHeadingPitchRollToFixedFrame` is deprecated and his behaviour will replace `Transforms.headingPitchRollToFixedFrame` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `Transforms.directHeadingPitchRollQuaternion` is deprecated and his behaviour will replace `Transforms.headingPitchRollQuaternion` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) +* Added HeadingPitchRoll.fromDirectQuaternion that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) +* Added Matrix3.fromDirectHeadingPitchRoll that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) +* Added Quaternion.fromDirectHeadingPitchRoll that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) +* Added Transforms.directHeadingPitchRollToFixedFrame that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) +* Added Transforms.directHeadingPitchRollQuaternion that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + ### 1.37 - 2017-09-01 * Breaking changes diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index dd6a030f9d1e..db71971d0332 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -2,12 +2,14 @@ define([ './defaultValue', './defined', './DeveloperError', - './Math' + './Math', + './deprecationWarning' ], function( defaultValue, defined, DeveloperError, - CesiumMath) { + CesiumMath, + deprecationWarning) { 'use strict'; /** @@ -40,6 +42,35 @@ define([ throw new DeveloperError('quaternion is required'); } //>>includeEnd('debug'); + 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.43 in order to be classical. The new behavior can be evaluate with HeadingPitchRoll.fromDirectQuaternion'); + if (!defined(result)) { + result = new HeadingPitchRoll(); + } + 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); + result.heading = -Math.atan2(numeratorHeading, denominatorHeading); + result.roll = Math.atan2(numeratorRoll, denominatorRoll); + result.pitch = -Math.asin(test); + return result; + }; + + /** + * Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense + * + * @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. + * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided. + */ + HeadingPitchRoll.fromDirectQuaternion = function(quaternion, result) { + //>>includeStart('debug', pragmas.debug); + if (!defined(quaternion)) { + throw new DeveloperError('quaternion is required'); + } + //>>includeEnd('debug'); + deprecationWarning('HeadingPitchRoll.fromDirectQuaternion', 'This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.43.'); if (!defined(result)) { result = new HeadingPitchRoll(); } diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index 261c700f30ce..7b1162d2c8cc 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -6,7 +6,8 @@ define([ './defineProperties', './DeveloperError', './freezeObject', - './Math' + './Math', + './deprecationWarning' ], function( Cartesian3, Check, @@ -15,7 +16,8 @@ define([ defineProperties, DeveloperError, freezeObject, - CesiumMath) { + CesiumMath, + deprecationWarning) { 'use strict'; /** @@ -303,6 +305,56 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); + 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.43 in order to be classical. The new behavior can be evaluate with Matrix3.fromDirectHeadingPitchRoll'); + + var cosTheta = Math.cos(-headingPitchRoll.pitch); + var cosPsi = Math.cos(-headingPitchRoll.heading); + var cosPhi = Math.cos(headingPitchRoll.roll); + var sinTheta = Math.sin(-headingPitchRoll.pitch); + var sinPsi = Math.sin(-headingPitchRoll.heading); + var sinPhi = Math.sin(headingPitchRoll.roll); + + var m00 = cosTheta * cosPsi; + var m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi; + var m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi; + + var m10 = cosTheta * sinPsi; + var m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi; + var m12 = -sinPhi * cosPsi + cosPhi * sinTheta * sinPsi; + + var m20 = -sinTheta; + var m21 = sinPhi * cosTheta; + var m22 = cosPhi * cosTheta; + + if (!defined(result)) { + return new Matrix3(m00, m01, m02, + m10, m11, m12, + m20, m21, m22); + } + result[0] = m00; + result[1] = m10; + result[2] = m20; + result[3] = m01; + result[4] = m11; + result[5] = m21; + result[6] = m02; + result[7] = m12; + result[8] = m22; + return result; + }; + + /** + * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense + * + * @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. + * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll. + */ + Matrix3.fromDirectHeadingPitchRoll = function(headingPitchRoll, result) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object('headingPitchRoll', headingPitchRoll); + //>>includeEnd('debug'); + deprecationWarning('Matrix3.fromDirectHeadingPitchRoll', 'This Matrix3.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Matrix3.fromHeadingPitchRoll in 1.43.'); var cosTheta = Math.cos(headingPitchRoll.pitch); var cosPsi = Math.cos(headingPitchRoll.heading); diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index 83afd0410093..dee07de2641a 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -7,7 +7,8 @@ define([ './freezeObject', './HeadingPitchRoll', './Math', - './Matrix3' + './Matrix3', + './deprecationWarning' ], function( Cartesian3, Check, @@ -17,7 +18,8 @@ define([ freezeObject, HeadingPitchRoll, CesiumMath, - Matrix3) { + Matrix3, + deprecationWarning) { 'use strict'; /** @@ -188,6 +190,29 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); + 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.43 in order to be classical. The new behavior can be evaluate with Quaternion.fromDirectHeadingPitchRoll'); + + 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); + }; + + /** + * Computes a rotation from the given heading, pitch and roll angles in the mathematical common sense. 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. + * + * @param {HeadingPitchRoll} headingPitchRoll The rotation expressed as a heading, pitch and roll. + * @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. + */ + Quaternion.fromDirectHeadingPitchRoll = function(headingPitchRoll, result) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object('headingPitchRoll', headingPitchRoll); + //>>includeEnd('debug'); + deprecationWarning('Quaternion.fromDirectHeadingPitchRoll', 'This Quaternion.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Quaternion.fromHeadingPitchRoll in 1.43.'); scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion); scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, headingPitchRoll.pitch, result); diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index ef3ce08a0cbe..d9cb0cd9f627 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -18,7 +18,8 @@ define([ './Matrix3', './Matrix4', './Quaternion', - './TimeConstants' + './TimeConstants', + './deprecationWarning' ], function( when, Cartesian2, @@ -39,7 +40,8 @@ define([ Matrix3, Matrix4, Quaternion, - TimeConstants) { + TimeConstants, + deprecationWarning) { 'use strict'; /** @@ -333,6 +335,7 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); + deprecationWarning('Transforms.headingPitchRollToFixedFrame', 'This Transforms.headingPitchRollToFixedFrame 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.43 in order to be classical. The new behavior can be evaluate with Transforms.directHeadingPitchRollToFixedFrame'); fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame); var hprQuaternion = Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); @@ -341,6 +344,42 @@ define([ return Matrix4.multiply(result, hprMatrix, result); }; + /** + * Computes a 4x4 transformation matrix from a reference frame with axes computed from the heading-pitch-roll angles ( in the mathematical common sense) + * 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, and roll. + * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation. + * @param {Transforms~LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation + * matrix from a reference frame to the provided ellipsoid's fixed reference frame + * @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 heading = -Cesium.Math.PI_OVER_TWO; + * var pitch = Cesium.Math.PI_OVER_FOUR; + * var roll = 0.0; + * var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); + * var transform = Cesium.Transforms.directHeadingPitchRollToFixedFrame(center, hpr); + */ + Transforms.directHeadingPitchRollToFixedFrame = function(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); + //>>includeEnd('debug'); + deprecationWarning('Transforms.directHeadingPitchRollToFixedFrame', 'This Transforms.directHeadingPitchRollToFixedFrame works in the classical interpretation used in mathematics. This function will replaced Transforms.headingPitchRollToFixedFrame in 1.43.'); + + fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame); + var hprQuaternion = Quaternion.fromDirectHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); + var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4); + result = fixedFrameTransform(origin, ellipsoid, result); + return Matrix4.multiply(result, hprMatrix, result); + }; + var scratchENUMatrix4 = new Matrix4(); var scratchHPRMatrix3 = new Matrix3(); @@ -371,12 +410,47 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); + deprecationWarning('Transforms.headingPitchRollQuaternion', 'This Transforms.headingPitchRollQuaternion 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.43 in order to be classical. The new behavior can be evaluate with Transforms.directHeadingPitchRollQuaternion'); var transform = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, 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 ( in the mathematical common sense) + * 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, and roll. + * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation. + * @param {Transforms~LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation + * matrix from a reference frame to the provided ellipsoid's fixed reference frame + * @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 heading = -Cesium.Math.PI_OVER_TWO; + * var pitch = Cesium.Math.PI_OVER_FOUR; + * var roll = 0.0; + * var hpr = new HeadingPitchRoll(heading, pitch, roll); + * var quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr); + */ + Transforms.directHeadingPitchRollQuaternion = function(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); + //>>includeEnd('debug'); + deprecationWarning('HeadingPitchRoll.fromDirectQuaternion', 'This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.43.'); + + var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); + var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3); + return Quaternion.fromRotationMatrix(rotation, result); + }; + var gmstConstant0 = 6 * 3600 + 41 * 60 + 50.54841; var gmstConstant1 = 8640184.812866; var gmstConstant2 = 0.093104; diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 1f1a6b5e02a6..ae191451faea 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -1052,8 +1052,7 @@ define([ hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; hpr.pitch = -hpr.pitch; - var rotQuat = Quaternion.fromHeadingPitchRoll(hpr, scratchSetViewQuaternion); - var rotMat = Matrix3.fromQuaternion(rotQuat, scratchSetViewMatrix3); + var rotMat = Matrix3.fromDirectHeadingPitchRoll(hpr, scratchSetViewMatrix3); Matrix3.getColumn(rotMat, 0, camera.direction); Matrix3.getColumn(rotMat, 2, camera.up); @@ -1079,8 +1078,7 @@ define([ hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; hpr.pitch = -hpr.pitch; - var rotQuat = Quaternion.fromHeadingPitchRoll(hpr, scratchSetViewQuaternion); - var rotMat = Matrix3.fromQuaternion(rotQuat, scratchSetViewMatrix3); + var rotMat = Matrix3.fromDirectHeadingPitchRoll(hpr, scratchSetViewMatrix3); Matrix3.getColumn(rotMat, 0, camera.direction); Matrix3.getColumn(rotMat, 2, camera.up); @@ -1121,8 +1119,7 @@ define([ hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; hpr.pitch = CesiumMath.PI_OVER_TWO; hpr.roll = 0.0; - var rotQuat = Quaternion.fromHeadingPitchRoll(hpr, scratchSetViewQuaternion); - var rotMat = Matrix3.fromQuaternion(rotQuat, scratchSetViewMatrix3); + var rotMat = Matrix3.fromDirectHeadingPitchRoll(hpr, scratchSetViewMatrix3); Matrix3.getColumn(rotMat, 2, camera.up); Cartesian3.cross(camera.direction, camera.up, camera.right); diff --git a/Specs/Core/HeadingPitchRollSpec.js b/Specs/Core/HeadingPitchRollSpec.js index 96642a9d99cd..c848cf69f246 100644 --- a/Specs/Core/HeadingPitchRollSpec.js +++ b/Specs/Core/HeadingPitchRollSpec.js @@ -51,6 +51,32 @@ defineSuite([ } }); + it('conversion from direct quaternion', function() { + var testingTab = [ + [0, 0, 0], + [90 * deg2rad, 0, 0], + [-90 * deg2rad, 0, 0], + [0, 89 * deg2rad, 0], + [0, -89 * deg2rad, 0], + [0, 0, 90 * deg2rad], + [0, 0, -90 * deg2rad], + [30 * deg2rad, 30 * deg2rad, 30 * deg2rad], + [-30 * deg2rad, -30 * deg2rad, 45 * deg2rad] + ]; + var hpr = new HeadingPitchRoll(); + for (var i = 0; i < testingTab.length; i++) { + var init = testingTab[i]; + hpr.heading = init[0]; + hpr.pitch = init[1]; + hpr.roll = init[2]; + + var result = HeadingPitchRoll.fromDirectQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + expect(init[0]).toEqualEpsilon(result.heading, CesiumMath.EPSILON11); + expect(init[1]).toEqualEpsilon(result.pitch, CesiumMath.EPSILON11); + expect(init[2]).toEqualEpsilon(result.roll, CesiumMath.EPSILON11); + } + }); + it('conversion from degrees', function() { var testingTab = [ [0, 0, 0], @@ -145,6 +171,12 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('fromDirectQuaternion throws with no parameter', function() { + expect(function() { + HeadingPitchRoll.fromDirectQuaternion(); + }).toThrowDeveloperError(); + }); + var scratchHeadingPitchRoll = new HeadingPitchRoll(); it('fromDegrees throws with no heading parameter', function() { diff --git a/Specs/Core/Matrix3Spec.js b/Specs/Core/Matrix3Spec.js index b87c0775d199..987071bab774 100644 --- a/Specs/Core/Matrix3Spec.js +++ b/Specs/Core/Matrix3Spec.js @@ -161,6 +161,51 @@ defineSuite([ expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); }); + it('fromDirectHeadingPitchRoll works without a result parameter', function() { + var sPiOver4 = Math.sin(CesiumMath.PI_OVER_FOUR); + var cPiOver4 = Math.cos(CesiumMath.PI_OVER_FOUR); + var sPiOver2 = Math.sin(CesiumMath.PI_OVER_TWO); + var cPiOver2 = Math.cos(CesiumMath.PI_OVER_TWO); + + var tmp = Cartesian3.multiplyByScalar(new Cartesian3(0.0, 0.0, 1.0), sPiOver4, new Cartesian3()); + var quaternion = new Quaternion(tmp.x, tmp.y, tmp.z, cPiOver4); + var headingPitchRoll = HeadingPitchRoll.fromDirectQuaternion(quaternion); + var expected = new Matrix3(cPiOver2, -sPiOver2, 0.0, sPiOver2, cPiOver2, 0.0, 0.0, 0.0, 1.0); + + var returnedResult = Matrix3.fromDirectHeadingPitchRoll(headingPitchRoll); + expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); + }); + + it('fromDirectHeadingPitchRoll works with a result parameter', function() { + var sPiOver4 = Math.sin(CesiumMath.PI_OVER_FOUR); + var cPiOver4 = Math.cos(CesiumMath.PI_OVER_FOUR); + var sPiOver2 = Math.sin(CesiumMath.PI_OVER_TWO); + var cPiOver2 = Math.cos(CesiumMath.PI_OVER_TWO); + + var tmp = Cartesian3.multiplyByScalar(new Cartesian3(0.0, 0.0, 1.0), sPiOver4, new Cartesian3()); + var quaternion = new Quaternion(tmp.x, tmp.y, tmp.z, cPiOver4); + var headingPitchRoll = HeadingPitchRoll.fromDirectQuaternion(quaternion); + var expected = new Matrix3(cPiOver2, -sPiOver2, 0.0, sPiOver2, cPiOver2, 0.0, 0.0, 0.0, 1.0); + var result = new Matrix3(); + var returnedResult = Matrix3.fromDirectHeadingPitchRoll(headingPitchRoll, result); + expect(result).toBe(returnedResult); + expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); + }); + + it('fromDirectHeadingPitchRoll computed correctly', function() { + // Expected generated via STK Components + var expected = new Matrix3( + 0.754406506735489, 0.418940943945763, 0.505330889696038, + 0.133022221559489, 0.656295369162553, -0.742685314912828, + -0.642787609686539, 0.627506871597133, 0.439385041770705); + + var headingPitchRoll = new HeadingPitchRoll(CesiumMath.toRadians(10), CesiumMath.toRadians(40), CesiumMath.toRadians(55)); + var result = new Matrix3(); + var returnedResult = Matrix3.fromDirectHeadingPitchRoll(headingPitchRoll, result); + expect(result).toBe(returnedResult); + expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); + }); + it('fromScale works without a result parameter', function() { var expected = new Matrix3( @@ -1088,6 +1133,12 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('fromDirectHeadingPitchRoll throws without quaternion parameter', function() { + expect(function() { + Matrix3.fromDirectHeadingPitchRoll(undefined); + }).toThrowDeveloperError(); + }); + it('fromScale throws without scale parameter', function() { expect(function() { Matrix3.fromScale(undefined); diff --git a/Specs/Core/QuaternionSpec.js b/Specs/Core/QuaternionSpec.js index ddaac291b46a..0f97bd72274d 100644 --- a/Specs/Core/QuaternionSpec.js +++ b/Specs/Core/QuaternionSpec.js @@ -108,14 +108,14 @@ defineSuite([ var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll(angle, 0.0, 0.0); var quaternion = Quaternion.fromHeadingPitchRoll(hpr); - expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(angle), CesiumMath.EPSILON11); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(-angle), CesiumMath.EPSILON11); }); it('fromHeadingPitchRoll with just pitch', function() { var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll(0.0, angle, 0.0); var quaternion = Quaternion.fromHeadingPitchRoll(hpr); - expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(angle), CesiumMath.EPSILON11); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(-angle), CesiumMath.EPSILON11); }); it('fromHeadingPitchRoll with just roll', function() { @@ -130,8 +130,8 @@ defineSuite([ var hpr = new HeadingPitchRoll( angle, angle, angle); var quaternion = Quaternion.fromHeadingPitchRoll(hpr); var expected = Matrix3.fromRotationX(angle); - Matrix3.multiply(Matrix3.fromRotationY(angle), expected, expected); - Matrix3.multiply(Matrix3.fromRotationZ(angle), expected, expected); + Matrix3.multiply(Matrix3.fromRotationY(-angle), expected, expected); + Matrix3.multiply(Matrix3.fromRotationZ(-angle), expected, expected); expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); @@ -142,8 +142,8 @@ defineSuite([ var hpr = new HeadingPitchRoll( heading, pitch, roll); var quaternion = Quaternion.fromHeadingPitchRoll(hpr); var expected = Matrix3.fromRotationX(roll); - Matrix3.multiply(Matrix3.fromRotationY(pitch), expected, expected); - Matrix3.multiply(Matrix3.fromRotationZ(heading), expected, expected); + Matrix3.multiply(Matrix3.fromRotationY(-pitch), expected, expected); + Matrix3.multiply(Matrix3.fromRotationZ(-heading), expected, expected); expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); @@ -157,6 +157,59 @@ defineSuite([ expect(quaternion).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); + it('fromDirectHeadingPitchRoll with just heading', function() { + var angle = CesiumMath.toRadians(20.0); + var hpr = new HeadingPitchRoll(angle, 0.0, 0.0); + var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(angle), CesiumMath.EPSILON11); + }); + + it('fromDirectHeadingPitchRoll with just pitch', function() { + var angle = CesiumMath.toRadians(20.0); + var hpr = new HeadingPitchRoll(0.0, angle, 0.0); + var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(angle), CesiumMath.EPSILON11); + }); + + it('fromDirectHeadingPitchRoll with just roll', function() { + var angle = CesiumMath.toRadians(20.0); + var hpr = new HeadingPitchRoll( 0.0, 0.0, angle); + var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationX(angle), CesiumMath.EPSILON11); + }); + + it('fromDirectHeadingPitchRoll with all angles (1)', function() { + var angle = CesiumMath.toRadians(20.0); + var hpr = new HeadingPitchRoll( angle, angle, angle); + var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + var expected = Matrix3.fromRotationX(angle); + Matrix3.multiply(Matrix3.fromRotationY(angle), expected, expected); + Matrix3.multiply(Matrix3.fromRotationZ(angle), expected, expected); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11); + }); + + it('fromDirectHeadingPitchRoll with all angles (2)', function() { + var heading = CesiumMath.toRadians(180.0); + var pitch = CesiumMath.toRadians(-45.0); + var roll = CesiumMath.toRadians(45.0); + var hpr = new HeadingPitchRoll( heading, pitch, roll); + var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + var expected = Matrix3.fromRotationX(roll); + Matrix3.multiply(Matrix3.fromRotationY(pitch), expected, expected); + Matrix3.multiply(Matrix3.fromRotationZ(heading), expected, expected); + expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11); + }); + + it('fromDirectHeadingPitchRoll works with result parameter', function() { + var angle = CesiumMath.toRadians(20.0); + var hpr = new HeadingPitchRoll(0.0, 0.0, angle); + var result = new Quaternion(); + var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr, result); + var expected = Quaternion.fromRotationMatrix(Matrix3.fromRotationX(angle)); + expect(quaternion).toBe(result); + expect(quaternion).toEqualEpsilon(expected, CesiumMath.EPSILON11); + }); + it('clone without a result parameter', function() { var quaternion = new Quaternion(1.0, 2.0, 3.0, 4.0); var result = quaternion.clone(); diff --git a/Specs/Core/TransformsSpec.js b/Specs/Core/TransformsSpec.js index 07a702507f56..82dcac52a57c 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -538,6 +538,169 @@ defineSuite([ expect(actualTranslation).toEqual(origin); }); + it('directHeadingPitchRollToFixedFrame works without a result parameter', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedX = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); + var expectedY = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); + var expectedZ = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); + + Cartesian3.fromElements(expectedX.z, expectedX.x, expectedX.y, expectedX); + Cartesian3.fromElements(expectedY.z, expectedY.x, expectedY.y, expectedY); + Cartesian3.fromElements(expectedZ.z, expectedZ.x, expectedZ.y, expectedZ); + + var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var actualX = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); + var actualY = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); + var actualZ = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); + var actualTranslation = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 3, new Cartesian4())); + + expect(actualX).toEqual(expectedX); + expect(actualY).toEqual(expectedY); + expect(actualZ).toEqual(expectedZ); + expect(actualTranslation).toEqual(origin); + }); + + it('directHeadingPitchRollToFixedFrame works with a HeadingPitchRoll object and without a result parameter and a fixedFrameTransform', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedX = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); + var expectedY = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); + var expectedZ = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); + + Cartesian3.fromElements(expectedX.z, expectedX.x, expectedX.y, expectedX); + Cartesian3.fromElements(expectedY.z, expectedY.x, expectedY.y, expectedY); + Cartesian3.fromElements(expectedZ.z, expectedZ.x, expectedZ.y, expectedZ); + + var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var actualX = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); + var actualY = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); + var actualZ = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); + var actualTranslation = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 3, new Cartesian4())); + + expect(actualX).toEqual(expectedX); + expect(actualY).toEqual(expectedY); + expect(actualZ).toEqual(expectedZ); + expect(actualTranslation).toEqual(origin); + }); + + it('directHeadingPitchRollToFixedFrame works with a HeadingPitchRoll object and without a result parameter', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedX = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); + var expectedY = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); + var expectedZ = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); + + Cartesian3.fromElements(expectedX.z, expectedX.x, expectedX.y, expectedX); + Cartesian3.fromElements(expectedY.z, expectedY.x, expectedY.y, expectedY); + Cartesian3.fromElements(expectedZ.z, expectedZ.x, expectedZ.y, expectedZ); + + var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame); + var actualX = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); + var actualY = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); + var actualZ = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); + var actualTranslation = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 3, new Cartesian4())); + + expect(actualX).toEqual(expectedX); + expect(actualY).toEqual(expectedY); + expect(actualZ).toEqual(expectedZ); + expect(actualTranslation).toEqual(origin); + }); + + it('directHeadingPitchRollToFixedFrame works with a result parameter', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedX = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); + var expectedY = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); + var expectedZ = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); + + Cartesian3.fromElements(expectedX.z, expectedX.x, expectedX.y, expectedX); + Cartesian3.fromElements(expectedY.z, expectedY.x, expectedY.y, expectedY); + Cartesian3.fromElements(expectedZ.z, expectedZ.x, expectedZ.y, expectedZ); + + var result = new Matrix4(); + var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result); + var actualX = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); + var actualY = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); + var actualZ = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); + var actualTranslation = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 3, new Cartesian4())); + + expect(returnedResult).toBe(result); + expect(actualX).toEqual(expectedX); + expect(actualY).toEqual(expectedY); + expect(actualZ).toEqual(expectedZ); + expect(actualTranslation).toEqual(origin); + }); + + it('directHeadingPitchRollToFixedFrame works with a custom fixedFrameTransform', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedEast = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); // east + var expectedNorth = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); // north + var expectedUp = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); // up + + Cartesian3.fromElements(expectedEast.z, expectedEast.x, expectedEast.y, expectedEast); + Cartesian3.fromElements(expectedNorth.z, expectedNorth.x, expectedNorth.y, expectedNorth); + Cartesian3.fromElements(expectedUp.z, expectedUp.x, expectedUp.y, expectedUp); + + var result = new Matrix4(); + var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result); + var actualEast = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); // east + var actualNorth = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); // north + var actualUp = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); // up + var actualTranslation = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 3, new Cartesian4())); + + expect(returnedResult).toBe(result); + expect(actualEast).toEqual(expectedEast); + expect(actualNorth).toEqual(expectedNorth); + expect(actualUp).toEqual(expectedUp); + expect(actualTranslation).toEqual(origin); + + var UNEFixedFrameConverter = Transforms.localFrameToFixedFrameGenerator('west','south'); // up north east + returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, UNEFixedFrameConverter, result); + actualEast = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); // east + actualEast.y = -actualEast.y; + actualEast.z= -actualEast.z; + actualNorth = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); // north + actualNorth.y = -actualNorth.y; + actualNorth.z= -actualNorth.z; + actualUp = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); // up + actualUp.y = -actualUp.y; + actualUp.z= -actualUp.z; + actualTranslation = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 3, new Cartesian4())); + + expect(returnedResult).toBe(result); + expect(actualEast).toEqual(expectedEast); + expect(actualNorth).toEqual(expectedNorth); + expect(actualUp).toEqual(expectedUp); + expect(actualTranslation).toEqual(origin); + }); + it('headingPitchRollQuaternion works without a result parameter', function() { var origin = new Cartesian3(1.0, 0.0, 0.0); var heading = CesiumMath.toRadians(20.0); @@ -606,6 +769,74 @@ defineSuite([ expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); + it('directHeadingPitchRollQuaternion works without a result parameter', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + + var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var expected = Matrix4.getRotation(transform, new Matrix3()); + + var quaternion = Transforms.directHeadingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame); + var actual = Matrix3.fromQuaternion(quaternion); + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); + }); + + it('directHeadingPitchRollQuaternion works with a result parameter', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + + var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var expected = Matrix4.getRotation(transform, new Matrix3()); + + var result = new Quaternion(); + var quaternion = Transforms.directHeadingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result); + var actual = Matrix3.fromQuaternion(quaternion); + expect(quaternion).toBe(result); + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); + }); + + it('directHeadingPitchRollQuaternion works without a custom fixedFrameTransform', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + + var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var expected = Matrix4.getRotation(transform, new Matrix3()); + + var result = new Quaternion(); + var quaternion = Transforms.directHeadingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, result); + var actual = Matrix3.fromQuaternion(quaternion); + expect(quaternion).toBe(result); + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); + }); + + + it('directHeadingPitchRollQuaternion works with a custom fixedFrameTransform', function() { + var origin = new Cartesian3(1.0, 0.0, 0.0); + var heading = CesiumMath.toRadians(20.0); + var pitch = CesiumMath.toRadians(30.0); + var roll = CesiumMath.toRadians(40.0); + var hpr = new HeadingPitchRoll(heading, pitch, roll); + var fixedFrameTransform = Transforms.localFrameToFixedFrameGenerator('west','south'); + + var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform); + var expected = Matrix4.getRotation(transform, new Matrix3()); + + var result = new Quaternion(); + var quaternion = Transforms.directHeadingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform, result); + var actual = Matrix3.fromQuaternion(quaternion); + expect(quaternion).toBe(result); + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); + }); + it('computeTemeToPseudoFixedMatrix works before noon', function() { var time = JulianDate.fromDate(new Date('June 29, 2015 12:00:00 UTC')); var t = Transforms.computeTemeToPseudoFixedMatrix(time); @@ -1048,9 +1279,9 @@ defineSuite([ var heading = CesiumMath.toRadians(90.0); var pitch = CesiumMath.toRadians(45.0); var roll = 0.0; - var hpr = new HeadingPitchRoll(heading, pitch, roll); + var hpr = new HeadingPitchRoll(-heading, -pitch, roll); - var modelMatrix = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid); + var modelMatrix = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, ellipsoid); var modelMatrix2D = Transforms.basisTo2D(projection, modelMatrix, new Matrix4()); var translation2D = Cartesian3.fromCartesian4(Matrix4.getColumn(modelMatrix2D, 3, new Cartesian4())); @@ -1069,7 +1300,7 @@ defineSuite([ var heading = CesiumMath.toRadians(90.0); var pitch = CesiumMath.toRadians(45.0); var roll = 0.0; - var hpr = new HeadingPitchRoll(heading, pitch, roll); + var hpr = new HeadingPitchRoll(-heading, -pitch, roll); var modelMatrix = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid); var modelMatrix2D = Transforms.basisTo2D(projection, modelMatrix, new Matrix4()); @@ -1152,6 +1383,18 @@ defineSuite([ }).toThrowDeveloperError(); }); + it('directHeadingPitchRollToFixedFrame throws without an origin', function() { + expect(function() { + Transforms.directHeadingPitchRollToFixedFrame(undefined, new HeadingPitchRoll()); + }).toThrowDeveloperError(); + }); + + it('directHeadingPitchRollToFixedFrame throws without a headingPitchRoll', function() { + expect(function() { + Transforms.directHeadingPitchRollToFixedFrame(Cartesian3.ZERO, undefined); + }).toThrowDeveloperError(); + }); + it('computeTemeToPseudoFixedMatrix throws without a date', function() { expect(function() { Transforms.computeTemeToPseudoFixedMatrix(undefined); diff --git a/Specs/Scene/ModelInstanceCollectionSpec.js b/Specs/Scene/ModelInstanceCollectionSpec.js index 1b493721d190..3029b7f4fa8a 100644 --- a/Specs/Scene/ModelInstanceCollectionSpec.js +++ b/Specs/Scene/ModelInstanceCollectionSpec.js @@ -133,8 +133,8 @@ defineSuite([ var heading = Math.PI/2.0; var pitch = 0.0; var roll = 0.0; - var hpr = new HeadingPitchRoll(heading, pitch, roll); - var modelMatrix = Transforms.headingPitchRollToFixedFrame(position, hpr); + var hpr = new HeadingPitchRoll(-heading, -pitch, roll); + var modelMatrix = Transforms.directHeadingPitchRollToFixedFrame(position, hpr); instances.push({ modelMatrix : modelMatrix }); From 91351555d49382772b9318b89ab97b749ab10b70 Mon Sep 17 00:00:00 2001 From: Farouk Abdou Date: Sun, 3 Sep 2017 17:26:49 +0200 Subject: [PATCH 3/8] Correct of unused variable --- Source/Scene/Camera.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index ae191451faea..6787051117a1 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -1039,7 +1039,6 @@ define([ var scratchSetViewCartesian = new Cartesian3(); var scratchSetViewTransform1 = new Matrix4(); var scratchSetViewTransform2 = new Matrix4(); - var scratchSetViewQuaternion = new Quaternion(); var scratchSetViewMatrix3 = new Matrix3(); var scratchSetViewCartographic = new Cartographic(); From f1c13375eab57bc756e9635e85584ea47edfcd94 Mon Sep 17 00:00:00 2001 From: Farouk Abdou Date: Wed, 6 Sep 2017 18:13:01 +0200 Subject: [PATCH 4/8] remove warnings from new functions --- Source/Core/HeadingPitchRoll.js | 4 ++-- Source/Core/Matrix3.js | 4 ++-- Source/Core/Quaternion.js | 2 +- Source/Core/Transforms.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index db71971d0332..55e66d495c4d 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -58,7 +58,8 @@ define([ }; /** - * Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense + * Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense. + * This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.43. * * @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. @@ -70,7 +71,6 @@ define([ throw new DeveloperError('quaternion is required'); } //>>includeEnd('debug'); - deprecationWarning('HeadingPitchRoll.fromDirectQuaternion', 'This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.43.'); if (!defined(result)) { result = new HeadingPitchRoll(); } diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index 7b1162d2c8cc..2d4c1e6c5b2f 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -344,7 +344,8 @@ define([ }; /** - * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense + * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense. + * This Matrix3.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Matrix3.fromHeadingPitchRoll in 1.43. * * @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. @@ -354,7 +355,6 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - deprecationWarning('Matrix3.fromDirectHeadingPitchRoll', 'This Matrix3.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Matrix3.fromHeadingPitchRoll in 1.43.'); var cosTheta = Math.cos(headingPitchRoll.pitch); var cosPsi = Math.cos(headingPitchRoll.heading); diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index dee07de2641a..4370d1b3ac8c 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -203,6 +203,7 @@ define([ * Computes a rotation from the given heading, pitch and roll angles in the mathematical common sense. 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. + * This Quaternion.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Quaternion.fromHeadingPitchRoll in 1.43. * * @param {HeadingPitchRoll} headingPitchRoll The rotation expressed as a heading, pitch and roll. * @param {Quaternion} [result] The object onto which to store the result. @@ -212,7 +213,6 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - deprecationWarning('Quaternion.fromDirectHeadingPitchRoll', 'This Quaternion.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Quaternion.fromHeadingPitchRoll in 1.43.'); scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion); scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, headingPitchRoll.pitch, result); diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index d9cb0cd9f627..9a450fbfa35f 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -349,6 +349,7 @@ define([ * 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. + * This Transforms.directHeadingPitchRollToFixedFrame works in the classical interpretation used in mathematics. This function will replaced Transforms.headingPitchRollToFixedFrame in 1.43. * * @param {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. @@ -371,7 +372,6 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - deprecationWarning('Transforms.directHeadingPitchRollToFixedFrame', 'This Transforms.directHeadingPitchRollToFixedFrame works in the classical interpretation used in mathematics. This function will replaced Transforms.headingPitchRollToFixedFrame in 1.43.'); fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame); var hprQuaternion = Quaternion.fromDirectHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); @@ -422,6 +422,7 @@ define([ * 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. + * This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.43. * * @param {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. @@ -444,7 +445,6 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - deprecationWarning('HeadingPitchRoll.fromDirectQuaternion', 'This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.43.'); var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3); From 628111680dcbea742badf3ae091d08efc3e6a7c4 Mon Sep 17 00:00:00 2001 From: Farouk Abdou Date: Thu, 7 Sep 2017 22:16:08 +0200 Subject: [PATCH 5/8] add deprecated tag --- Source/Core/HeadingPitchRoll.js | 1 + Source/Core/Matrix3.js | 1 + Source/Core/Quaternion.js | 1 + Source/Core/Transforms.js | 2 ++ 4 files changed, 5 insertions(+) diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index 55e66d495c4d..6bf4cf1be7f0 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -32,6 +32,7 @@ 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 * @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. * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided. diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index 2d4c1e6c5b2f..cba81d942548 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -297,6 +297,7 @@ 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 * @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. * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll. diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index 4370d1b3ac8c..34568a33cc7a 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -181,6 +181,7 @@ 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 * * @param {HeadingPitchRoll} headingPitchRoll The rotation expressed as a heading, pitch and roll. * @param {Quaternion} [result] The object onto which to store the result. diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index 9a450fbfa35f..10917de62b60 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -313,6 +313,7 @@ define([ * 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. + * @deprecated since V1.38 * * @param {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. @@ -350,6 +351,7 @@ define([ * 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. * This Transforms.directHeadingPitchRollToFixedFrame works in the classical interpretation used in mathematics. This function will replaced Transforms.headingPitchRollToFixedFrame in 1.43. + * @deprecated since V1.38 * * @param {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. From 02f4046ae5728844e5a4436c197aadcaa140b4a6 Mon Sep 17 00:00:00 2001 From: Farouk Abdou Date: Thu, 7 Sep 2017 23:13:02 +0200 Subject: [PATCH 6/8] deprecated tag misplaced --- Source/Core/Transforms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index 10917de62b60..904815d224ed 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -351,7 +351,6 @@ define([ * 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. * This Transforms.directHeadingPitchRollToFixedFrame works in the classical interpretation used in mathematics. This function will replaced Transforms.headingPitchRollToFixedFrame in 1.43. - * @deprecated since V1.38 * * @param {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. @@ -390,6 +389,7 @@ define([ * 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. + * @deprecated since V1.38 * * @param {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. From db16f8f9f3c5da35225326d7a24369ed51c60aec Mon Sep 17 00:00:00 2001 From: Farouk Abdou Date: Sun, 10 Sep 2017 05:16:17 +0200 Subject: [PATCH 7/8] Change deprecated version to 1.40 --- CHANGES.md | 11 +++++------ Source/Core/HeadingPitchRoll.js | 4 ++-- Source/Core/Matrix3.js | 4 ++-- Source/Core/Quaternion.js | 4 ++-- Source/Core/Transforms.js | 8 ++++---- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8beb044c646d..2b4c2346d859 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,11 +5,11 @@ Change Log * Breaking changes * Deprecated - * `HeadingPitchRoll.fromDirectQuaternion` is deprecated and his behaviour will replace `HeadingPitchRoll.fromQuaternion` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) - * `Matrix3.fromDirectHeadingPitchRoll` is deprecated and his behaviour will replace `Matrix3.fromHeadingPitchRoll` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) - * `Quaternion.fromDirectHeadingPitchRoll` is deprecated and his behaviour will replace `Quaternion.fromHeadingPitchRoll` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) - * `Transforms.directHeadingPitchRollToFixedFrame` is deprecated and his behaviour will replace `Transforms.headingPitchRollToFixedFrame` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) - * `Transforms.directHeadingPitchRollQuaternion` is deprecated and his behaviour will replace `Transforms.headingPitchRollQuaternion` behaviour in 1.43. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `HeadingPitchRoll.fromDirectQuaternion` is deprecated and his behaviour will replace `HeadingPitchRoll.fromQuaternion` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `Matrix3.fromDirectHeadingPitchRoll` is deprecated and his behaviour will replace `Matrix3.fromHeadingPitchRoll` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `Quaternion.fromDirectHeadingPitchRoll` is deprecated and his behaviour will replace `Quaternion.fromHeadingPitchRoll` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `Transforms.directHeadingPitchRollToFixedFrame` is deprecated and his behaviour will replace `Transforms.headingPitchRollToFixedFrame` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * `Transforms.directHeadingPitchRollQuaternion` is deprecated and his behaviour will replace `Transforms.headingPitchRollQuaternion` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) * Added HeadingPitchRoll.fromDirectQuaternion that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) * Added Matrix3.fromDirectHeadingPitchRoll that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) * Added Quaternion.fromDirectHeadingPitchRoll that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) @@ -19,7 +19,6 @@ Change Log * Fixed a bug in `ModelAnimationCollection` that caused adding an animation by its name to throw an error. [#5815](https://github.com/AnalyticalGraphicsInc/cesium/pull/5815) * Zoom about mouse now maintains camera heading, pitch, and roll [#4639](https://github.com/AnalyticalGraphicsInc/cesium/pull/5603) - ### 1.37 - 2017-09-01 * Breaking changes diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index 6bf4cf1be7f0..b8b4b5547883 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -43,7 +43,7 @@ define([ throw new DeveloperError('quaternion is required'); } //>>includeEnd('debug'); - 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.43 in order to be classical. The new behavior can be evaluate with HeadingPitchRoll.fromDirectQuaternion'); + 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 with HeadingPitchRoll.fromDirectQuaternion'); if (!defined(result)) { result = new HeadingPitchRoll(); } @@ -60,7 +60,7 @@ define([ /** * Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense. - * This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.43. + * This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion 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. diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index cba81d942548..bcf8a8b34c3c 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -306,7 +306,7 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - 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.43 in order to be classical. The new behavior can be evaluate with Matrix3.fromDirectHeadingPitchRoll'); + 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 with Matrix3.fromDirectHeadingPitchRoll'); var cosTheta = Math.cos(-headingPitchRoll.pitch); var cosPsi = Math.cos(-headingPitchRoll.heading); @@ -346,7 +346,7 @@ define([ /** * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense. - * This Matrix3.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Matrix3.fromHeadingPitchRoll in 1.43. + * This Matrix3.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Matrix3.fromHeadingPitchRoll 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. diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index 34568a33cc7a..3c2a511fdefb 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -191,7 +191,7 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - 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.43 in order to be classical. The new behavior can be evaluate with Quaternion.fromDirectHeadingPitchRoll'); + 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 with Quaternion.fromDirectHeadingPitchRoll'); scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion); scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, -headingPitchRoll.pitch, result); @@ -204,7 +204,7 @@ define([ * Computes a rotation from the given heading, pitch and roll angles in the mathematical common sense. 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. - * This Quaternion.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Quaternion.fromHeadingPitchRoll in 1.43. + * This Quaternion.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Quaternion.fromHeadingPitchRoll 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. diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index 904815d224ed..c54ee21e697c 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -336,7 +336,7 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - deprecationWarning('Transforms.headingPitchRollToFixedFrame', 'This Transforms.headingPitchRollToFixedFrame 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.43 in order to be classical. The new behavior can be evaluate with Transforms.directHeadingPitchRollToFixedFrame'); + deprecationWarning('Transforms.headingPitchRollToFixedFrame', 'This Transforms.headingPitchRollToFixedFrame 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 with Transforms.directHeadingPitchRollToFixedFrame'); fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame); var hprQuaternion = Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); @@ -350,7 +350,7 @@ define([ * 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. - * This Transforms.directHeadingPitchRollToFixedFrame works in the classical interpretation used in mathematics. This function will replaced Transforms.headingPitchRollToFixedFrame in 1.43. + * This Transforms.directHeadingPitchRollToFixedFrame works in the classical interpretation used in mathematics. This function will replaced Transforms.headingPitchRollToFixedFrame in 1.40. * * @param {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. @@ -412,7 +412,7 @@ define([ //>>includeStart('debug', pragmas.debug); Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - deprecationWarning('Transforms.headingPitchRollQuaternion', 'This Transforms.headingPitchRollQuaternion 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.43 in order to be classical. The new behavior can be evaluate with Transforms.directHeadingPitchRollQuaternion'); + deprecationWarning('Transforms.headingPitchRollQuaternion', 'This Transforms.headingPitchRollQuaternion 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 with Transforms.directHeadingPitchRollQuaternion'); var transform = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3); @@ -424,7 +424,7 @@ define([ * 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. - * This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.43. + * This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.40. * * @param {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. From fc9cb9368d0192a8fb6d0a113336d1e60aefd2fa Mon Sep 17 00:00:00 2001 From: Farouk Abdou Date: Tue, 12 Sep 2017 17:21:37 +0200 Subject: [PATCH 8/8] updates to add a boolean parameter --- .../gallery/3D Models Coloring.html | 2 +- Apps/Sandcastle/gallery/3D Models.html | 2 +- Apps/Sandcastle/gallery/Classification.html | 6 +- .../gallery/Distance Display Conditions.html | 2 +- Apps/Sandcastle/gallery/HeadingPitchRoll.html | 4 +- .../Sandcastle/gallery/LocalToFixedFrame.html | 6 +- Apps/Sandcastle/gallery/Projection.html | 2 +- .../gallery/development/3D Models.html | 2 +- CHANGES.md | 11 +- Source/Core/HeadingPitchRoll.js | 46 +++----- Source/Core/Matrix3.js | 85 +++++--------- Source/Core/Quaternion.js | 46 +++----- Source/Core/Transforms.js | 105 ++++-------------- Source/Scene/Camera.js | 6 +- Specs/Core/HeadingPitchRollSpec.js | 10 +- Specs/Core/Matrix3Spec.js | 22 ++-- Specs/Core/QuaternionSpec.js | 12 +- Specs/Core/TransformsSpec.js | 52 ++++----- Specs/Scene/ModelInstanceCollectionSpec.js | 2 +- 19 files changed, 136 insertions(+), 287 deletions(-) diff --git a/Apps/Sandcastle/gallery/3D Models Coloring.html b/Apps/Sandcastle/gallery/3D Models Coloring.html index edf0acd58ebb..46c9dfad832c 100644 --- a/Apps/Sandcastle/gallery/3D Models Coloring.html +++ b/Apps/Sandcastle/gallery/3D Models Coloring.html @@ -176,7 +176,7 @@ var pitch = 0; var roll = 0; var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); - var orientation = Cesium.Transforms.directHeadingPitchRollQuaternion(position, hpr); + var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr, undefined, undefined, undefined, true); entity = viewer.entities.add({ name : url, diff --git a/Apps/Sandcastle/gallery/3D Models.html b/Apps/Sandcastle/gallery/3D Models.html index faa2af95ed0a..30caabdb7188 100644 --- a/Apps/Sandcastle/gallery/3D Models.html +++ b/Apps/Sandcastle/gallery/3D Models.html @@ -94,4 +94,4 @@ } - \ No newline at end of file + diff --git a/Apps/Sandcastle/gallery/Classification.html b/Apps/Sandcastle/gallery/Classification.html index 84034bcb43ca..ea43207e72e1 100644 --- a/Apps/Sandcastle/gallery/Classification.html +++ b/Apps/Sandcastle/gallery/Classification.html @@ -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.fromDirectHeadingPitchRoll(new Cesium.HeadingPitchRoll(-2.619728786416368, 0.0, 0.0)); + var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-2.619728786416368, 0.0, 0.0), undefined, true); var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.0, 0.0, -2.0)); Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix); @@ -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.fromDirectHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0)); + var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0), undefined, true); var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.4, 0.0, -2.0)); Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix); @@ -111,7 +111,7 @@ center = new Cesium.Cartesian3(1216394.3346955755, -4736207.431365568, 4081336.7768881875); modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center); - hprRotation = Cesium.Matrix3.fromDirectHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0)); + hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0), undefined, true); hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(-0.25, 0.0, -2.0)); Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix); diff --git a/Apps/Sandcastle/gallery/Distance Display Conditions.html b/Apps/Sandcastle/gallery/Distance Display Conditions.html index 83a85e13f154..6e656bb6dd17 100644 --- a/Apps/Sandcastle/gallery/Distance Display Conditions.html +++ b/Apps/Sandcastle/gallery/Distance Display Conditions.html @@ -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.directHeadingPitchRollQuaternion(position, hpr); + var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr, undefined, undefined, undefined, true); viewer.entities.add({ position : position, diff --git a/Apps/Sandcastle/gallery/HeadingPitchRoll.html b/Apps/Sandcastle/gallery/HeadingPitchRoll.html index 989e66ee5762..b227b8ffc4e6 100644 --- a/Apps/Sandcastle/gallery/HeadingPitchRoll.html +++ b/Apps/Sandcastle/gallery/HeadingPitchRoll.html @@ -110,7 +110,7 @@

Loading...

var planePrimitive = scene.primitives.add(Cesium.Model.fromGltf({ url : '../../SampleData/models/CesiumAir/Cesium_Air.glb', - modelMatrix : Cesium.Transforms.directHeadingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform), + modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, undefined, true), minimumPixelSize : 128 })); @@ -208,7 +208,7 @@

Loading...

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.directHeadingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, planePrimitive.modelMatrix); + Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransform, planePrimitive.modelMatrix, true); if (fromBehind.checked) { // Zoom to model diff --git a/Apps/Sandcastle/gallery/LocalToFixedFrame.html b/Apps/Sandcastle/gallery/LocalToFixedFrame.html index 0c3c7afb014d..29e3bc3c83d5 100644 --- a/Apps/Sandcastle/gallery/LocalToFixedFrame.html +++ b/Apps/Sandcastle/gallery/LocalToFixedFrame.html @@ -110,12 +110,12 @@

Loading...

var comments = localFrames[i].comments; var planePrimitive = scene.primitives.add(Cesium.Model.fromGltf({ url : '../../SampleData/models/CesiumAir/Cesium_Air.glb', - modelMatrix : Cesium.Transforms.directHeadingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter), + modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, undefined, true), minimumPixelSize : 128 })); primitives.push({primitive : planePrimitive, converter : converter, position : position}); - var modelMatrix = Cesium.Transforms.directHeadingPitchRollToFixedFrame(position, hprRollZero, Cesium.Ellipsoid.WGS84, converter); + var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(position, hprRollZero, Cesium.Ellipsoid.WGS84, converter, undefined, true); scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({ modelMatrix : modelMatrix, length : 300.0, @@ -221,7 +221,7 @@

Loading...

var primitive = primitives[i].primitive; var converter = primitives[i].converter; var position = primitives[i].position; - Cesium.Transforms.directHeadingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, primitive.modelMatrix); + Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, primitive.modelMatrix, true); } }); //Sandcastle_End diff --git a/Apps/Sandcastle/gallery/Projection.html b/Apps/Sandcastle/gallery/Projection.html index c9ee5facb843..470d2764face 100644 --- a/Apps/Sandcastle/gallery/Projection.html +++ b/Apps/Sandcastle/gallery/Projection.html @@ -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.directHeadingPitchRollQuaternion(position, hpr); +var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr, undefined, undefined, undefined, true); var entity = viewer.entities.add({ position : position, diff --git a/Apps/Sandcastle/gallery/development/3D Models.html b/Apps/Sandcastle/gallery/development/3D Models.html index 5634f1c11e84..4151357601e4 100644 --- a/Apps/Sandcastle/gallery/development/3D Models.html +++ b/Apps/Sandcastle/gallery/development/3D Models.html @@ -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.directHeadingPitchRollToFixedFrame(origin, hpr); + var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, hpr, undefined, undefined, undefined, true); scene.primitives.removeAll(); // Remove previous model model = scene.primitives.add(Cesium.Model.fromGltf({ diff --git a/CHANGES.md b/CHANGES.md index 2b4c2346d859..c7c97e6770ea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,16 +5,7 @@ Change Log * Breaking changes * Deprecated - * `HeadingPitchRoll.fromDirectQuaternion` is deprecated and his behaviour will replace `HeadingPitchRoll.fromQuaternion` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) - * `Matrix3.fromDirectHeadingPitchRoll` is deprecated and his behaviour will replace `Matrix3.fromHeadingPitchRoll` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) - * `Quaternion.fromDirectHeadingPitchRoll` is deprecated and his behaviour will replace `Quaternion.fromHeadingPitchRoll` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) - * `Transforms.directHeadingPitchRollToFixedFrame` is deprecated and his behaviour will replace `Transforms.headingPitchRollToFixedFrame` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) - * `Transforms.directHeadingPitchRollQuaternion` is deprecated and his behaviour will replace `Transforms.headingPitchRollQuaternion` behaviour in 1.40. [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) -* Added HeadingPitchRoll.fromDirectQuaternion that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) -* Added Matrix3.fromDirectHeadingPitchRoll that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) -* Added Quaternion.fromDirectHeadingPitchRoll that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) -* Added Transforms.directHeadingPitchRollToFixedFrame that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) -* Added Transforms.directHeadingPitchRollQuaternion that works with classical orientation of heading and pitch [#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) + * The default behavior of the functions `HeadingPitchRoll.fromQuaternion`, `Matrix3.fromHeadingPitchRoll`, `Quaternion.fromHeadingPitchRoll`, `Transforms.headingPitchRollToFixedFrame`, and `Transforms.headingPitchRollQuaternion` has been deprecated. An optional boolean flag can be supplied to these functions 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.[#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) * Added ability to add an animation to `ModelAnimationCollection` by its index. [#5815](https://github.com/AnalyticalGraphicsInc/cesium/pull/5815) * Fixed a bug in `ModelAnimationCollection` that caused adding an animation by its name to throw an error. [#5815](https://github.com/AnalyticalGraphicsInc/cesium/pull/5815) * Zoom about mouse now maintains camera heading, pitch, and roll [#4639](https://github.com/AnalyticalGraphicsInc/cesium/pull/5603) diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index b8b4b5547883..03b3b4444519 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -32,57 +32,39 @@ 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 + * @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) { + HeadingPitchRoll.fromQuaternion = function(quaternion, result, classical) { //>>includeStart('debug', pragmas.debug); if (!defined(quaternion)) { throw new DeveloperError('quaternion is required'); } //>>includeEnd('debug'); - 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 with HeadingPitchRoll.fromDirectQuaternion'); 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); - result.heading = -Math.atan2(numeratorHeading, denominatorHeading); - result.roll = Math.atan2(numeratorRoll, denominatorRoll); - result.pitch = -Math.asin(test); - return result; - }; - /** - * Computes the heading, pitch and roll from a quaternion (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense. - * This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion 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. - * @returns {HeadingPitchRoll} The modified result parameter or a new HeadingPitchRoll instance if one was not provided. - */ - HeadingPitchRoll.fromDirectQuaternion = function(quaternion, result) { - //>>includeStart('debug', pragmas.debug); - if (!defined(quaternion)) { - throw new DeveloperError('quaternion is required'); + 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); } - //>>includeEnd('debug'); - if (!defined(result)) { - result = new HeadingPitchRoll(); - } - 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); - result.heading = Math.atan2(numeratorHeading, denominatorHeading); - result.roll = Math.atan2(numeratorRoll, denominatorRoll); - result.pitch = Math.asin(test); + return result; }; diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index bcf8a8b34c3c..47112adbe19d 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -297,72 +297,41 @@ 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 + * @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) { + Matrix3.fromHeadingPitchRoll = function(headingPitchRoll, result, classical) { //>>includeStart('debug', pragmas.debug); Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - 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 with Matrix3.fromDirectHeadingPitchRoll'); - - var cosTheta = Math.cos(-headingPitchRoll.pitch); - var cosPsi = Math.cos(-headingPitchRoll.heading); - var cosPhi = Math.cos(headingPitchRoll.roll); - var sinTheta = Math.sin(-headingPitchRoll.pitch); - var sinPsi = Math.sin(-headingPitchRoll.heading); - var sinPhi = Math.sin(headingPitchRoll.roll); - - var m00 = cosTheta * cosPsi; - var m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi; - var m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi; - - var m10 = cosTheta * sinPsi; - var m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi; - var m12 = -sinPhi * cosPsi + cosPhi * sinTheta * sinPsi; - - var m20 = -sinTheta; - var m21 = sinPhi * cosTheta; - var m22 = cosPhi * cosTheta; - - if (!defined(result)) { - return new Matrix3(m00, m01, m02, - m10, m11, m12, - m20, m21, m22); + classical = defaultValue(classical, false); + + var cosTheta; + var cosPsi; + var cosPhi; + var sinTheta; + 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); } - result[0] = m00; - result[1] = m10; - result[2] = m20; - result[3] = m01; - result[4] = m11; - result[5] = m21; - result[6] = m02; - result[7] = m12; - result[8] = m22; - return result; - }; - - /** - * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles ) in the mathematical common sense. - * This Matrix3.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Matrix3.fromHeadingPitchRoll 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. - * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll. - */ - Matrix3.fromDirectHeadingPitchRoll = function(headingPitchRoll, result) { - //>>includeStart('debug', pragmas.debug); - Check.typeOf.object('headingPitchRoll', headingPitchRoll); - //>>includeEnd('debug'); - - var cosTheta = Math.cos(headingPitchRoll.pitch); - var cosPsi = Math.cos(headingPitchRoll.heading); - var cosPhi = Math.cos(headingPitchRoll.roll); - var sinTheta = Math.sin(headingPitchRoll.pitch); - var sinPsi = Math.sin(headingPitchRoll.heading); - var sinPhi = Math.sin(headingPitchRoll.roll); var m00 = cosTheta * cosPsi; var m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi; diff --git a/Source/Core/Quaternion.js b/Source/Core/Quaternion.js index 3c2a511fdefb..babf555a4e17 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -181,44 +181,32 @@ 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 + * @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) { - //>>includeStart('debug', pragmas.debug); - Check.typeOf.object('headingPitchRoll', headingPitchRoll); - //>>includeEnd('debug'); - 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 with Quaternion.fromDirectHeadingPitchRoll'); - - 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); - }; - - /** - * Computes a rotation from the given heading, pitch and roll angles in the mathematical common sense. 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. - * This Quaternion.fromDirectHeadingPitchRoll works in the classical interpretation used in mathematics. This function will replaced Quaternion.fromHeadingPitchRoll 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. - * @returns {Quaternion} The modified result parameter or a new Quaternion instance if none was provided. - */ - Quaternion.fromDirectHeadingPitchRoll = function(headingPitchRoll, result) { + Quaternion.fromHeadingPitchRoll = function(headingPitchRoll, result, classical) { //>>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); + } - 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); }; diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index c54ee21e697c..4d5a489f3669 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -313,7 +313,7 @@ define([ * 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. - * @deprecated since V1.38 + * @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 {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. @@ -321,6 +321,7 @@ define([ * @param {Transforms~LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation * matrix from a reference frame to the provided ellipsoid's fixed reference frame * @param {Matrix4} [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 {Matrix4} The modified result parameter or a new Matrix4 instance if none was provided. * * @example @@ -332,51 +333,20 @@ define([ * var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); * var transform = Cesium.Transforms.headingPitchRollToFixedFrame(center, hpr); */ - Transforms.headingPitchRollToFixedFrame = function(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result) { + Transforms.headingPitchRollToFixedFrame = function(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result, classical) { //>>includeStart('debug', pragmas.debug); Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - deprecationWarning('Transforms.headingPitchRollToFixedFrame', 'This Transforms.headingPitchRollToFixedFrame 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 with Transforms.directHeadingPitchRollToFixedFrame'); - + classical = defaultValue(classical, false); fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame); - var hprQuaternion = Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); - var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4); - result = fixedFrameTransform(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 ( in the mathematical common sense) - * 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. - * This Transforms.directHeadingPitchRollToFixedFrame works in the classical interpretation used in mathematics. This function will replaced Transforms.headingPitchRollToFixedFrame in 1.40. - * - * @param {Cartesian3} origin The center point of the local reference frame. - * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. - * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation. - * @param {Transforms~LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation - * matrix from a reference frame to the provided ellipsoid's fixed reference frame - * @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 heading = -Cesium.Math.PI_OVER_TWO; - * var pitch = Cesium.Math.PI_OVER_FOUR; - * var roll = 0.0; - * var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); - * var transform = Cesium.Transforms.directHeadingPitchRollToFixedFrame(center, hpr); - */ - Transforms.directHeadingPitchRollToFixedFrame = function(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result) { - //>>includeStart('debug', pragmas.debug); - Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); - //>>includeEnd('debug'); - - fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame); - var hprQuaternion = Quaternion.fromDirectHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); - var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4); + if(classical === true){ + Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion, true); + } else { + deprecationWarning('Transforms.headingPitchRollToFixedFrame', 'This Transforms.headingPitchRollToFixedFrame 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'); + Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion, false); + } + var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, scratchHPRQuaternion, scratchScale, scratchHPRMatrix4); result = fixedFrameTransform(origin, ellipsoid, result); return Matrix4.multiply(result, hprMatrix, result); }; @@ -389,7 +359,7 @@ define([ * 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. - * @deprecated since V1.38 + * @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 {Cartesian3} origin The center point of the local reference frame. * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. @@ -397,6 +367,7 @@ define([ * @param {Transforms~LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation * matrix from a reference frame to the provided ellipsoid's fixed reference frame * @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. * * @example @@ -408,49 +379,21 @@ define([ * var hpr = new HeadingPitchRoll(heading, pitch, roll); * var quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr); */ - Transforms.headingPitchRollQuaternion = function(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result) { - //>>includeStart('debug', pragmas.debug); - Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); - //>>includeEnd('debug'); - deprecationWarning('Transforms.headingPitchRollQuaternion', 'This Transforms.headingPitchRollQuaternion 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 with Transforms.directHeadingPitchRollQuaternion'); - - var transform = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, 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 ( in the mathematical common sense) - * 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. - * This HeadingPitchRoll.fromDirectQuaternion works in the classical interpretation used in mathematics. This function will replaced HeadingPitchRoll.fromQuaternion in 1.40. - * - * @param {Cartesian3} origin The center point of the local reference frame. - * @param {HeadingPitchRoll} headingPitchRoll The heading, pitch, and roll. - * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid whose fixed frame is used in the transformation. - * @param {Transforms~LocalFrameToFixedFrame} [fixedFrameTransform=Transforms.eastNorthUpToFixedFrame] A 4x4 transformation - * matrix from a reference frame to the provided ellipsoid's fixed reference frame - * @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 heading = -Cesium.Math.PI_OVER_TWO; - * var pitch = Cesium.Math.PI_OVER_FOUR; - * var roll = 0.0; - * var hpr = new HeadingPitchRoll(heading, pitch, roll); - * var quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr); - */ - Transforms.directHeadingPitchRollQuaternion = function(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result) { + Transforms.headingPitchRollQuaternion = function(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, result, classical) { //>>includeStart('debug', pragmas.debug); Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); + classical = defaultValue(classical, false); + if(classical === true){ + scratchENUMatrix4 = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4, true); + Matrix4.getRotation(scratchENUMatrix4, scratchHPRMatrix3); + } else { + deprecationWarning('Transforms.headingPitchRollQuaternion', 'This Transforms.headingPitchRollQuaternion 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'); + scratchENUMatrix4 = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4, false); + Matrix4.getRotation(scratchENUMatrix4, scratchHPRMatrix3); + } - var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); - var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3); - return Quaternion.fromRotationMatrix(rotation, result); + return Quaternion.fromRotationMatrix(scratchHPRMatrix3, result); }; var gmstConstant0 = 6 * 3600 + 41 * 60 + 50.54841; diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 6787051117a1..f7fb64e07396 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -1051,7 +1051,7 @@ define([ hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; hpr.pitch = -hpr.pitch; - var rotMat = Matrix3.fromDirectHeadingPitchRoll(hpr, scratchSetViewMatrix3); + var rotMat = Matrix3.fromHeadingPitchRoll(hpr, scratchSetViewMatrix3, true); Matrix3.getColumn(rotMat, 0, camera.direction); Matrix3.getColumn(rotMat, 2, camera.up); @@ -1077,7 +1077,7 @@ define([ hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; hpr.pitch = -hpr.pitch; - var rotMat = Matrix3.fromDirectHeadingPitchRoll(hpr, scratchSetViewMatrix3); + var rotMat = Matrix3.fromHeadingPitchRoll(hpr, scratchSetViewMatrix3, true); Matrix3.getColumn(rotMat, 0, camera.direction); Matrix3.getColumn(rotMat, 2, camera.up); @@ -1118,7 +1118,7 @@ define([ hpr.heading = -hpr.heading + CesiumMath.PI_OVER_TWO; hpr.pitch = CesiumMath.PI_OVER_TWO; hpr.roll = 0.0; - var rotMat = Matrix3.fromDirectHeadingPitchRoll(hpr, scratchSetViewMatrix3); + var rotMat = Matrix3.fromHeadingPitchRoll(hpr, scratchSetViewMatrix3, true); Matrix3.getColumn(rotMat, 2, camera.up); Cartesian3.cross(camera.direction, camera.up, camera.right); diff --git a/Specs/Core/HeadingPitchRollSpec.js b/Specs/Core/HeadingPitchRollSpec.js index c848cf69f246..f0b3466af9f0 100644 --- a/Specs/Core/HeadingPitchRollSpec.js +++ b/Specs/Core/HeadingPitchRollSpec.js @@ -51,7 +51,7 @@ defineSuite([ } }); - it('conversion from direct quaternion', function() { + it('conversion from quaternion', function() { var testingTab = [ [0, 0, 0], [90 * deg2rad, 0, 0], @@ -70,7 +70,7 @@ defineSuite([ hpr.pitch = init[1]; hpr.roll = init[2]; - var result = HeadingPitchRoll.fromDirectQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var result = HeadingPitchRoll.fromQuaternion(Quaternion.fromHeadingPitchRoll(hpr, undefined, true), undefined, true); expect(init[0]).toEqualEpsilon(result.heading, CesiumMath.EPSILON11); expect(init[1]).toEqualEpsilon(result.pitch, CesiumMath.EPSILON11); expect(init[2]).toEqualEpsilon(result.roll, CesiumMath.EPSILON11); @@ -171,12 +171,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('fromDirectQuaternion throws with no parameter', function() { - expect(function() { - HeadingPitchRoll.fromDirectQuaternion(); - }).toThrowDeveloperError(); - }); - var scratchHeadingPitchRoll = new HeadingPitchRoll(); it('fromDegrees throws with no heading parameter', function() { diff --git a/Specs/Core/Matrix3Spec.js b/Specs/Core/Matrix3Spec.js index 987071bab774..1fedc4554ec0 100644 --- a/Specs/Core/Matrix3Spec.js +++ b/Specs/Core/Matrix3Spec.js @@ -161,7 +161,7 @@ defineSuite([ expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); }); - it('fromDirectHeadingPitchRoll works without a result parameter', function() { + it('fromHeadingPitchRoll works without a result parameter', function() { var sPiOver4 = Math.sin(CesiumMath.PI_OVER_FOUR); var cPiOver4 = Math.cos(CesiumMath.PI_OVER_FOUR); var sPiOver2 = Math.sin(CesiumMath.PI_OVER_TWO); @@ -169,14 +169,14 @@ defineSuite([ var tmp = Cartesian3.multiplyByScalar(new Cartesian3(0.0, 0.0, 1.0), sPiOver4, new Cartesian3()); var quaternion = new Quaternion(tmp.x, tmp.y, tmp.z, cPiOver4); - var headingPitchRoll = HeadingPitchRoll.fromDirectQuaternion(quaternion); + var headingPitchRoll = HeadingPitchRoll.fromQuaternion(quaternion, undefined, true); var expected = new Matrix3(cPiOver2, -sPiOver2, 0.0, sPiOver2, cPiOver2, 0.0, 0.0, 0.0, 1.0); - var returnedResult = Matrix3.fromDirectHeadingPitchRoll(headingPitchRoll); + var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, undefined, true); expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); }); - it('fromDirectHeadingPitchRoll works with a result parameter', function() { + it('fromHeadingPitchRoll works with a result parameter', function() { var sPiOver4 = Math.sin(CesiumMath.PI_OVER_FOUR); var cPiOver4 = Math.cos(CesiumMath.PI_OVER_FOUR); var sPiOver2 = Math.sin(CesiumMath.PI_OVER_TWO); @@ -184,15 +184,15 @@ defineSuite([ var tmp = Cartesian3.multiplyByScalar(new Cartesian3(0.0, 0.0, 1.0), sPiOver4, new Cartesian3()); var quaternion = new Quaternion(tmp.x, tmp.y, tmp.z, cPiOver4); - var headingPitchRoll = HeadingPitchRoll.fromDirectQuaternion(quaternion); + var headingPitchRoll = HeadingPitchRoll.fromQuaternion(quaternion, undefined, true); var expected = new Matrix3(cPiOver2, -sPiOver2, 0.0, sPiOver2, cPiOver2, 0.0, 0.0, 0.0, 1.0); var result = new Matrix3(); - var returnedResult = Matrix3.fromDirectHeadingPitchRoll(headingPitchRoll, result); + var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result, true); expect(result).toBe(returnedResult); expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); }); - it('fromDirectHeadingPitchRoll computed correctly', function() { + it('fromHeadingPitchRoll computed correctly', function() { // Expected generated via STK Components var expected = new Matrix3( 0.754406506735489, 0.418940943945763, 0.505330889696038, @@ -201,7 +201,7 @@ defineSuite([ var headingPitchRoll = new HeadingPitchRoll(CesiumMath.toRadians(10), CesiumMath.toRadians(40), CesiumMath.toRadians(55)); var result = new Matrix3(); - var returnedResult = Matrix3.fromDirectHeadingPitchRoll(headingPitchRoll, result); + var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result, true); expect(result).toBe(returnedResult); expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); }); @@ -1133,12 +1133,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('fromDirectHeadingPitchRoll throws without quaternion parameter', function() { - expect(function() { - Matrix3.fromDirectHeadingPitchRoll(undefined); - }).toThrowDeveloperError(); - }); - it('fromScale throws without scale parameter', function() { expect(function() { Matrix3.fromScale(undefined); diff --git a/Specs/Core/QuaternionSpec.js b/Specs/Core/QuaternionSpec.js index 0f97bd72274d..db9c7ac2703a 100644 --- a/Specs/Core/QuaternionSpec.js +++ b/Specs/Core/QuaternionSpec.js @@ -160,28 +160,28 @@ defineSuite([ it('fromDirectHeadingPitchRoll with just heading', function() { var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll(angle, 0.0, 0.0); - var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true); expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationZ(angle), CesiumMath.EPSILON11); }); it('fromDirectHeadingPitchRoll with just pitch', function() { var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll(0.0, angle, 0.0); - var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true); expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationY(angle), CesiumMath.EPSILON11); }); it('fromDirectHeadingPitchRoll with just roll', function() { var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll( 0.0, 0.0, angle); - var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true); expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(Matrix3.fromRotationX(angle), CesiumMath.EPSILON11); }); it('fromDirectHeadingPitchRoll with all angles (1)', function() { var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll( angle, angle, angle); - var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true); var expected = Matrix3.fromRotationX(angle); Matrix3.multiply(Matrix3.fromRotationY(angle), expected, expected); Matrix3.multiply(Matrix3.fromRotationZ(angle), expected, expected); @@ -193,7 +193,7 @@ defineSuite([ var pitch = CesiumMath.toRadians(-45.0); var roll = CesiumMath.toRadians(45.0); var hpr = new HeadingPitchRoll( heading, pitch, roll); - var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr); + var quaternion = Quaternion.fromHeadingPitchRoll(hpr, undefined, true); var expected = Matrix3.fromRotationX(roll); Matrix3.multiply(Matrix3.fromRotationY(pitch), expected, expected); Matrix3.multiply(Matrix3.fromRotationZ(heading), expected, expected); @@ -204,7 +204,7 @@ defineSuite([ var angle = CesiumMath.toRadians(20.0); var hpr = new HeadingPitchRoll(0.0, 0.0, angle); var result = new Quaternion(); - var quaternion = Quaternion.fromDirectHeadingPitchRoll(hpr, result); + var quaternion = Quaternion.fromHeadingPitchRoll(hpr, result, true); var expected = Quaternion.fromRotationMatrix(Matrix3.fromRotationX(angle)); expect(quaternion).toBe(result); expect(quaternion).toEqualEpsilon(expected, CesiumMath.EPSILON11); diff --git a/Specs/Core/TransformsSpec.js b/Specs/Core/TransformsSpec.js index 82dcac52a57c..f4905106fc73 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -545,7 +545,7 @@ defineSuite([ var roll = CesiumMath.toRadians(40.0); var hpr = new HeadingPitchRoll(heading, pitch, roll); - var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromHeadingPitchRoll(hpr, undefined, true)); var expectedX = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); var expectedY = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); var expectedZ = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); @@ -554,7 +554,7 @@ defineSuite([ Cartesian3.fromElements(expectedY.z, expectedY.x, expectedY.y, expectedY); Cartesian3.fromElements(expectedZ.z, expectedZ.x, expectedZ.y, expectedZ); - var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var returnedResult = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, undefined, true); var actualX = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); var actualY = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); var actualZ = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); @@ -573,7 +573,7 @@ defineSuite([ var roll = CesiumMath.toRadians(40.0); var hpr = new HeadingPitchRoll(heading, pitch, roll); - var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromHeadingPitchRoll(hpr, undefined, true)); var expectedX = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); var expectedY = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); var expectedZ = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); @@ -582,7 +582,7 @@ defineSuite([ Cartesian3.fromElements(expectedY.z, expectedY.x, expectedY.y, expectedY); Cartesian3.fromElements(expectedZ.z, expectedZ.x, expectedZ.y, expectedZ); - var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var returnedResult = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, undefined, true); var actualX = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); var actualY = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); var actualZ = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); @@ -601,7 +601,7 @@ defineSuite([ var roll = CesiumMath.toRadians(40.0); var hpr = new HeadingPitchRoll(heading, pitch, roll); - var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromHeadingPitchRoll(hpr, undefined, true)); var expectedX = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); var expectedY = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); var expectedZ = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); @@ -610,7 +610,7 @@ defineSuite([ Cartesian3.fromElements(expectedY.z, expectedY.x, expectedY.y, expectedY); Cartesian3.fromElements(expectedZ.z, expectedZ.x, expectedZ.y, expectedZ); - var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame); + var returnedResult = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, undefined, true); var actualX = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); var actualY = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); var actualZ = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); @@ -629,7 +629,7 @@ defineSuite([ var roll = CesiumMath.toRadians(40.0); var hpr = new HeadingPitchRoll(heading, pitch, roll); - var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromHeadingPitchRoll(hpr, undefined, true)); var expectedX = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); var expectedY = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); var expectedZ = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); @@ -639,7 +639,7 @@ defineSuite([ Cartesian3.fromElements(expectedZ.z, expectedZ.x, expectedZ.y, expectedZ); var result = new Matrix4(); - var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result); + var returnedResult = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result, true); var actualX = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); var actualY = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); var actualZ = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); @@ -659,7 +659,7 @@ defineSuite([ var roll = CesiumMath.toRadians(40.0); var hpr = new HeadingPitchRoll(heading, pitch, roll); - var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromDirectHeadingPitchRoll(hpr)); + var expectedRotation = Matrix3.fromQuaternion(Quaternion.fromHeadingPitchRoll(hpr, undefined, true)); var expectedEast = Matrix3.getColumn(expectedRotation, 0, new Cartesian3()); // east var expectedNorth = Matrix3.getColumn(expectedRotation, 1, new Cartesian3()); // north var expectedUp = Matrix3.getColumn(expectedRotation, 2, new Cartesian3()); // up @@ -669,7 +669,7 @@ defineSuite([ Cartesian3.fromElements(expectedUp.z, expectedUp.x, expectedUp.y, expectedUp); var result = new Matrix4(); - var returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result); + var returnedResult = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result, true); var actualEast = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); // east var actualNorth = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 1, new Cartesian4())); // north var actualUp = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 2, new Cartesian4())); // up @@ -682,7 +682,7 @@ defineSuite([ expect(actualTranslation).toEqual(origin); var UNEFixedFrameConverter = Transforms.localFrameToFixedFrameGenerator('west','south'); // up north east - returnedResult = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, UNEFixedFrameConverter, result); + returnedResult = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, UNEFixedFrameConverter, result, true); actualEast = Cartesian3.fromCartesian4(Matrix4.getColumn(returnedResult, 0, new Cartesian4())); // east actualEast.y = -actualEast.y; actualEast.z= -actualEast.z; @@ -776,10 +776,10 @@ defineSuite([ var roll = CesiumMath.toRadians(40.0); var hpr = new HeadingPitchRoll(heading, pitch, roll); - var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, undefined, true); var expected = Matrix4.getRotation(transform, new Matrix3()); - var quaternion = Transforms.directHeadingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame); + var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, undefined, true); var actual = Matrix3.fromQuaternion(quaternion); expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); @@ -791,11 +791,11 @@ defineSuite([ var roll = CesiumMath.toRadians(40.0); var hpr = new HeadingPitchRoll(heading, pitch, roll); - var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, undefined, true); var expected = Matrix4.getRotation(transform, new Matrix3()); var result = new Quaternion(); - var quaternion = Transforms.directHeadingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result); + var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result, true); var actual = Matrix3.fromQuaternion(quaternion); expect(quaternion).toBe(result); expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); @@ -808,11 +808,11 @@ defineSuite([ var roll = CesiumMath.toRadians(40.0); var hpr = new HeadingPitchRoll(heading, pitch, roll); - var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); + var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, undefined, true); var expected = Matrix4.getRotation(transform, new Matrix3()); var result = new Quaternion(); - var quaternion = Transforms.directHeadingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, result); + var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, result, true); var actual = Matrix3.fromQuaternion(quaternion); expect(quaternion).toBe(result); expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); @@ -827,11 +827,11 @@ defineSuite([ var hpr = new HeadingPitchRoll(heading, pitch, roll); var fixedFrameTransform = Transforms.localFrameToFixedFrameGenerator('west','south'); - var transform = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform); + var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform, undefined, true); var expected = Matrix4.getRotation(transform, new Matrix3()); var result = new Quaternion(); - var quaternion = Transforms.directHeadingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform, result); + var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform, result, true); var actual = Matrix3.fromQuaternion(quaternion); expect(quaternion).toBe(result); expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); @@ -1281,7 +1281,7 @@ defineSuite([ var roll = 0.0; var hpr = new HeadingPitchRoll(-heading, -pitch, roll); - var modelMatrix = Transforms.directHeadingPitchRollToFixedFrame(origin, hpr, ellipsoid); + var modelMatrix = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid, undefined, undefined, true); var modelMatrix2D = Transforms.basisTo2D(projection, modelMatrix, new Matrix4()); var translation2D = Cartesian3.fromCartesian4(Matrix4.getColumn(modelMatrix2D, 3, new Cartesian4())); @@ -1383,18 +1383,6 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('directHeadingPitchRollToFixedFrame throws without an origin', function() { - expect(function() { - Transforms.directHeadingPitchRollToFixedFrame(undefined, new HeadingPitchRoll()); - }).toThrowDeveloperError(); - }); - - it('directHeadingPitchRollToFixedFrame throws without a headingPitchRoll', function() { - expect(function() { - Transforms.directHeadingPitchRollToFixedFrame(Cartesian3.ZERO, undefined); - }).toThrowDeveloperError(); - }); - it('computeTemeToPseudoFixedMatrix throws without a date', function() { expect(function() { Transforms.computeTemeToPseudoFixedMatrix(undefined); diff --git a/Specs/Scene/ModelInstanceCollectionSpec.js b/Specs/Scene/ModelInstanceCollectionSpec.js index 3029b7f4fa8a..adaaeceecb21 100644 --- a/Specs/Scene/ModelInstanceCollectionSpec.js +++ b/Specs/Scene/ModelInstanceCollectionSpec.js @@ -134,7 +134,7 @@ defineSuite([ var pitch = 0.0; var roll = 0.0; var hpr = new HeadingPitchRoll(-heading, -pitch, roll); - var modelMatrix = Transforms.directHeadingPitchRollToFixedFrame(position, hpr); + var modelMatrix = Transforms.headingPitchRollToFixedFrame(position, hpr, undefined, undefined, undefined, true); instances.push({ modelMatrix : modelMatrix });