diff --git a/Apps/Sandcastle/gallery/3D Models Coloring.html b/Apps/Sandcastle/gallery/3D Models Coloring.html index 979c9a6f955a..4c93eb361365 100644 --- a/Apps/Sandcastle/gallery/3D Models Coloring.html +++ b/Apps/Sandcastle/gallery/3D Models Coloring.html @@ -172,7 +172,7 @@ 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); diff --git a/Apps/Sandcastle/gallery/Classification.html b/Apps/Sandcastle/gallery/Classification.html index b5ec8301a0bc..acce340b4274 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.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-2.619728786416368, 0.0, 0.0)); var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.0, 0.0, -2.0)); Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix); @@ -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.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0)); var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.4, 0.0, -2.0)); Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix); @@ -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.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0)); hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(-0.25, 0.0, -2.0)); Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix); diff --git a/Apps/Sandcastle/gallery/Distance Display Conditions.html b/Apps/Sandcastle/gallery/Distance Display Conditions.html index d4475cabe5d8..46d8a2f05652 100644 --- a/Apps/Sandcastle/gallery/Distance Display Conditions.html +++ b/Apps/Sandcastle/gallery/Distance Display Conditions.html @@ -54,7 +54,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 hpr = new Cesium.HeadingPitchRoll(-heading, 0.0, 0.0); var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); viewer.entities.add({ diff --git a/Apps/Sandcastle/gallery/Projection.html b/Apps/Sandcastle/gallery/Projection.html index faa01ed692d1..eda3b3ceeecc 100644 --- a/Apps/Sandcastle/gallery/Projection.html +++ b/Apps/Sandcastle/gallery/Projection.html @@ -36,7 +36,7 @@ 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 hpr = new Cesium.HeadingPitchRoll(-Cesium.Math.toRadians(135), 0.0, 0.0); var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); var entity = viewer.entities.add({ diff --git a/Apps/Sandcastle/gallery/development/3D Models.html b/Apps/Sandcastle/gallery/development/3D Models.html index 9739f74752ef..a7956d555994 100644 --- a/Apps/Sandcastle/gallery/development/3D Models.html +++ b/Apps/Sandcastle/gallery/development/3D Models.html @@ -123,8 +123,8 @@ 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); diff --git a/CHANGES.md b/CHANGES.md index 432dff7bc1a0..1f34d65a8b74 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ Change Log ### 1.38 - 2017-10-02 * Breaking changes + * `HeadingPitchRoll.fromQuaternion`, `Matrix3.fromHeadingPitchRoll`, `Quaternion.fromHeadingPitchRoll`, `Transforms.headingPitchRollToFixedFrame`, and `Transforms.headingPitchRollQuaternion` now use the classical orientation of heading and pitch calculated counter-clockwise. With this new behavior, heading and pitch need to be the negative of their previous values. The warning message will be removed in Cesium 1.40.[#5666](https://github.com/AnalyticalGraphicsInc/cesium/issues/5666) * `Scene/CullingVolume` has been removed. Use `Core/CullingVolume`. * `Scene/OrthographicFrustum` has been removed. Use `Core/OrthographicFrustum`. * `Scene/OrthographicOffCenterFrustum` has been removed. Use `Core/OrthographicOffCenterFrustum`. diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index b934f6d04f3e..66448aede003 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,17 +42,23 @@ define([ throw new DeveloperError('quaternion is required'); } //>>includeEnd('debug'); + + deprecationWarning('HeadingPitchRoll.fromQuaternion', 'This function now uses a counter-clockwise orientation of heading and pitch as per mathematical conventions. With this new behavior, heading and pitch will need to be the negative of their previous values. This was introduced in 1.38 and the deprecation warning will be removed in Cesium 1.40.'); + 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.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 23e9b6c21376..933ff08e7dc7 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'; /** @@ -304,11 +306,13 @@ define([ Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); - var cosTheta = Math.cos(-headingPitchRoll.pitch); - var cosPsi = Math.cos(-headingPitchRoll.heading); + deprecationWarning('Matrix3.fromHeadingPitchRoll', 'This function now uses a counter-clockwise orientation of heading and pitch as per mathematical conventions. With this new behavior, heading and pitch will need to be the negative of their previous values. This was introduced in 1.38 and the deprecation warning will be removed in Cesium 1.40.'); + + 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 346c135d71d9..0a1e2cae8ec5 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'; /** @@ -189,10 +191,13 @@ define([ Check.typeOf.object('headingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); + deprecationWarning('Quaternion.fromHeadingPitchRoll', 'This function now uses a counter-clockwise orientation of heading and pitch as per mathematical conventions. With this new behavior, heading and pitch will need to be the negative of their previous values. This was introduced in 1.38 and the deprecation warning will be removed in Cesium 1.40.'); + scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion); - scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, -headingPitchRoll.pitch, result); + scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, headingPitchRoll.pitch, result); result = Quaternion.multiply(scratchPitchQuaternion, scratchRollQuaternion, scratchPitchQuaternion); - scratchHeadingQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Z, -headingPitchRoll.heading, scratchHPRQuaternion); + 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 ef3ce08a0cbe..737bf10c4982 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'; /** @@ -334,8 +336,12 @@ define([ Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); + deprecationWarning('Transforms.headingPitchRollToFixedFrame', 'This function now uses a counter-clockwise orientation of heading and pitch as per mathematical conventions. With this new behavior, heading and pitch will need to be the negative of their previous values. This was introduced in 1.38 and the deprecation warning will be removed in Cesium 1.40.'); + fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame); - var hprQuaternion = Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); + + 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); @@ -372,6 +378,11 @@ define([ Check.typeOf.object( 'HeadingPitchRoll', headingPitchRoll); //>>includeEnd('debug'); + deprecationWarning('Transforms.headingPitchRollQuaternion', 'This function now uses a counter-clockwise orientation of heading and pitch as per mathematical conventions. With this new behavior, heading and pitch will need to be the negative of their previous values. This was introduced in 1.38 and the deprecation warning will be removed in Cesium 1.40.'); + + scratchENUMatrix4 = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); + Matrix4.getRotation(scratchENUMatrix4, scratchHPRMatrix3); + var transform = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3); return Quaternion.fromRotationMatrix(rotation, result); diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index f7155fc5c35e..a0d38927b66b 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(); @@ -1049,10 +1048,10 @@ 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); + var rotMat = Matrix3.fromHeadingPitchRoll(hpr, scratchSetViewMatrix3); Matrix3.getColumn(rotMat, 0, camera.direction); Matrix3.getColumn(rotMat, 2, camera.up); @@ -1075,10 +1074,10 @@ 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); + var rotMat = Matrix3.fromHeadingPitchRoll(hpr, scratchSetViewMatrix3); Matrix3.getColumn(rotMat, 0, camera.direction); Matrix3.getColumn(rotMat, 2, camera.up); @@ -1116,11 +1115,10 @@ 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); + var rotMat = Matrix3.fromHeadingPitchRoll(hpr, scratchSetViewMatrix3); Matrix3.getColumn(rotMat, 2, camera.up); Cartesian3.cross(camera.direction, camera.up, camera.right); diff --git a/Specs/Core/Matrix3Spec.js b/Specs/Core/Matrix3Spec.js index b87c0775d199..7e94a7b58eea 100644 --- a/Specs/Core/Matrix3Spec.js +++ b/Specs/Core/Matrix3Spec.js @@ -154,7 +154,7 @@ defineSuite([ 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 headingPitchRoll = new HeadingPitchRoll(CesiumMath.toRadians(10), CesiumMath.toRadians(40), CesiumMath.toRadians(55)); var result = new Matrix3(); var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result); expect(result).toBe(returnedResult); diff --git a/Specs/Core/QuaternionSpec.js b/Specs/Core/QuaternionSpec.js index c969f95f690c..ddaac291b46a 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); }); diff --git a/Specs/Core/TransformsSpec.js b/Specs/Core/TransformsSpec.js index 07a702507f56..59643313d657 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -587,7 +587,6 @@ defineSuite([ expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON11); }); - it('headingPitchRollQuaternion works with a custom fixedFrameTransform', function() { var origin = new Cartesian3(1.0, 0.0, 0.0); var heading = CesiumMath.toRadians(20.0); @@ -1048,7 +1047,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()); @@ -1069,7 +1068,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()); diff --git a/Specs/Scene/ModelInstanceCollectionSpec.js b/Specs/Scene/ModelInstanceCollectionSpec.js index 1b493721d190..9f2caa63b5c0 100644 --- a/Specs/Scene/ModelInstanceCollectionSpec.js +++ b/Specs/Scene/ModelInstanceCollectionSpec.js @@ -133,7 +133,7 @@ defineSuite([ var heading = Math.PI/2.0; var pitch = 0.0; var roll = 0.0; - var hpr = new HeadingPitchRoll(heading, pitch, roll); + var hpr = new HeadingPitchRoll(-heading, -pitch, roll); var modelMatrix = Transforms.headingPitchRollToFixedFrame(position, hpr); instances.push({ modelMatrix : modelMatrix