diff --git a/Source/Core/HeadingPitchRoll.js b/Source/Core/HeadingPitchRoll.js index 8fb7901655fc..7ed90c5f59b1 100644 --- a/Source/Core/HeadingPitchRoll.js +++ b/Source/Core/HeadingPitchRoll.js @@ -55,9 +55,9 @@ define([ 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 eb1d8c241bed..734666a26e7b 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -308,19 +308,12 @@ define([ deprecationWarning('Matrix3.fromHeadingPitchRoll', 'This function now uses a counter-clockwise orientation as per mathematical conventions. This deprecation warning will be removed in Cesium 1.40.'); - var cosTheta; - var cosPsi; - var cosPhi; - var sinTheta; - var sinPsi; - var sinPhi; - - cosTheta = Math.cos(headingPitchRoll.pitch); - cosPsi = Math.cos(headingPitchRoll.heading); - cosPhi = Math.cos(headingPitchRoll.roll); - sinTheta = Math.sin(headingPitchRoll.pitch); - sinPsi = Math.sin(headingPitchRoll.heading); - sinPhi = Math.sin(headingPitchRoll.roll); + var 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 6baf6b484c2d..bd698dd4788f 100644 --- a/Source/Core/Quaternion.js +++ b/Source/Core/Quaternion.js @@ -194,9 +194,9 @@ define([ deprecationWarning('Quaternion.fromHeadingPitchRoll', 'This function now uses a counter-clockwise orientation as per mathematical conventions. This deprecation warning will be removed in Cesium 1.40.'); scratchRollQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_X, headingPitchRoll.roll, scratchHPRQuaternion); - scratchPitchQuaternion = Quaternion.fromAxisAngle(Cartesian3.UNIT_Y, -headingPitchRoll.pitch, result); + 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 2d79cc7d960c..c9485d5a6e04 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -340,9 +340,9 @@ define([ fixedFrameTransform = defaultValue(fixedFrameTransform, Transforms.eastNorthUpToFixedFrame); - Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); + var hprQuaternion = Quaternion.fromHeadingPitchRoll(headingPitchRoll, scratchHPRQuaternion); - var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, scratchHPRQuaternion, scratchScale, scratchHPRMatrix4); + var hprMatrix = Matrix4.fromTranslationQuaternionRotationScale(Cartesian3.ZERO, hprQuaternion, scratchScale, scratchHPRMatrix4); result = fixedFrameTransform(origin, ellipsoid, result); return Matrix4.multiply(result, hprMatrix, result); }; @@ -383,7 +383,9 @@ define([ scratchENUMatrix4 = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); Matrix4.getRotation(scratchENUMatrix4, scratchHPRMatrix3); - return Quaternion.fromRotationMatrix(scratchHPRMatrix3, result); + var transform = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); + var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3); + return Quaternion.fromRotationMatrix(rotation, result); }; var gmstConstant0 = 6 * 3600 + 41 * 60 + 50.54841; diff --git a/Specs/Core/HeadingPitchRollSpec.js b/Specs/Core/HeadingPitchRollSpec.js index f0b3466af9f0..96642a9d99cd 100644 --- a/Specs/Core/HeadingPitchRollSpec.js +++ b/Specs/Core/HeadingPitchRollSpec.js @@ -51,32 +51,6 @@ defineSuite([ } }); - it('conversion from 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.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); - } - }); - it('conversion from degrees', function() { var testingTab = [ [0, 0, 0], diff --git a/Specs/Core/Matrix3Spec.js b/Specs/Core/Matrix3Spec.js index 1fedc4554ec0..7e94a7b58eea 100644 --- a/Specs/Core/Matrix3Spec.js +++ b/Specs/Core/Matrix3Spec.js @@ -147,51 +147,6 @@ defineSuite([ expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); }); - it('fromHeadingPitchRoll 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.fromHeadingPitchRoll(headingPitchRoll, result); - expect(result).toBe(returnedResult); - expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); - }); - - 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); - 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.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.fromHeadingPitchRoll(headingPitchRoll, undefined, true); - expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); - }); - - 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); - 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.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.fromHeadingPitchRoll(headingPitchRoll, result, true); - expect(result).toBe(returnedResult); - expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); - }); - it('fromHeadingPitchRoll computed correctly', function() { // Expected generated via STK Components var expected = new Matrix3( @@ -201,7 +156,7 @@ defineSuite([ var headingPitchRoll = new HeadingPitchRoll(CesiumMath.toRadians(10), CesiumMath.toRadians(40), CesiumMath.toRadians(55)); var result = new Matrix3(); - var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result, true); + var returnedResult = Matrix3.fromHeadingPitchRoll(headingPitchRoll, result); expect(result).toBe(returnedResult); expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON15); }); diff --git a/Specs/Core/QuaternionSpec.js b/Specs/Core/QuaternionSpec.js index db9c7ac2703a..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,81 +130,28 @@ 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); - expect(Matrix3.fromQuaternion(quaternion)).toEqualEpsilon(expected, CesiumMath.EPSILON11); - }); - - it('fromHeadingPitchRoll 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.fromHeadingPitchRoll(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('fromHeadingPitchRoll 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.fromHeadingPitchRoll(hpr, result); - var expected = Quaternion.fromRotationMatrix(Matrix3.fromRotationX(angle)); - expect(quaternion).toBe(result); - 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.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.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.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.fromHeadingPitchRoll(hpr, undefined, true); - 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() { + it('fromHeadingPitchRoll 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.fromHeadingPitchRoll(hpr, undefined, true); + var quaternion = Quaternion.fromHeadingPitchRoll(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() { + it('fromHeadingPitchRoll 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.fromHeadingPitchRoll(hpr, result, true); + var quaternion = Quaternion.fromHeadingPitchRoll(hpr, result); 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 f4905106fc73..59643313d657 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -538,169 +538,6 @@ 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.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()); - - 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.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())); - 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.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()); - - 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.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())); - 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.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()); - - 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.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())); - 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.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()); - - 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.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())); - 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.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 - - 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.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 - 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.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; - 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); @@ -750,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); @@ -769,74 +605,6 @@ 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.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, undefined, true); - var expected = Matrix4.getRotation(transform, new Matrix3()); - - var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, undefined, true); - 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.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, undefined, true); - var expected = Matrix4.getRotation(transform, new Matrix3()); - - var result = new Quaternion(); - 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); - }); - - 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.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, undefined, true); - var expected = Matrix4.getRotation(transform, new Matrix3()); - - var result = new Quaternion(); - 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); - }); - - - 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.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform, undefined, true); - var expected = Matrix4.getRotation(transform, new Matrix3()); - - var result = new Quaternion(); - 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); - }); - it('computeTemeToPseudoFixedMatrix works before noon', function() { var time = JulianDate.fromDate(new Date('June 29, 2015 12:00:00 UTC')); var t = Transforms.computeTemeToPseudoFixedMatrix(time); @@ -1281,7 +1049,7 @@ defineSuite([ var roll = 0.0; var hpr = new HeadingPitchRoll(-heading, -pitch, roll); - var modelMatrix = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid, undefined, undefined, true); + var modelMatrix = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid); var modelMatrix2D = Transforms.basisTo2D(projection, modelMatrix, new Matrix4()); var translation2D = Cartesian3.fromCartesian4(Matrix4.getColumn(modelMatrix2D, 3, new Cartesian4())); diff --git a/Specs/Scene/ModelInstanceCollectionSpec.js b/Specs/Scene/ModelInstanceCollectionSpec.js index adaaeceecb21..9f2caa63b5c0 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.headingPitchRollToFixedFrame(position, hpr, undefined, undefined, undefined, true); + var modelMatrix = Transforms.headingPitchRollToFixedFrame(position, hpr); instances.push({ modelMatrix : modelMatrix });