diff --git a/Apps/Sandcastle/gallery/development/Frustum.html b/Apps/Sandcastle/gallery/development/Frustum.html index d4f53ff4662c..356194302cdd 100644 --- a/Apps/Sandcastle/gallery/development/Frustum.html +++ b/Apps/Sandcastle/gallery/development/Frustum.html @@ -34,7 +34,7 @@ var positionOnEllipsoid = Cesium.Cartesian3.fromDegrees(-105.0, 45.0, 20.0); var enu = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid); -var rotation = Cesium.Matrix4.getRotation(enu, new Cesium.Matrix3()); +var rotation = Cesium.Matrix4.getMatrix3(enu, new Cesium.Matrix3()); Cesium.Matrix3.multiply(rotation, Cesium.Matrix3.fromRotationX(-Cesium.Math.PI_OVER_TWO), rotation); var orientation = Cesium.Quaternion.fromRotationMatrix(rotation); diff --git a/CHANGES.md b/CHANGES.md index 29e7f72c11b6..7889cea18895 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Change Log ##### Deprecated :hourglass_flowing_sand: * `createTileMapServiceImageryProvider` and `createOpenStreetMapImageryProvider` have been deprecated and will be removed in Cesium 1.65. Instead, pass the same options to `new TileMapServiceImageryProvider` and `new OpenStreetMapImageryProvider` respectively. +* The function `Matrix4.getRotation` has been deprecated and renamed to `Matrix4.getMatrix3`. `Matrix4.getRotation` will be removed in version 1.65. ##### Additions :tada: * Added ability to create partial ellipsoids using both the Entity API and CZML. New ellipsoid geometry properties: `innerRadii`, `minimumClock`, `maximumClock`, `minimumCone`, and `maximumCone`. This affects both `EllipsoidGeometry` and `EllipsoidOutlineGeometry`. See the updated [Sandcastle example](https://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Partial%20Ellipsoids.html&label=Geometries). [#5995](https://github.com/AnalyticalGraphicsInc/cesium/pull/5995) diff --git a/Source/Core/GeometryPipeline.js b/Source/Core/GeometryPipeline.js index 25ab70f16775..816416fa96dc 100644 --- a/Source/Core/GeometryPipeline.js +++ b/Source/Core/GeometryPipeline.js @@ -808,7 +808,7 @@ define([ Matrix4.inverse(modelMatrix, inverseTranspose); Matrix4.transpose(inverseTranspose, inverseTranspose); - Matrix4.getRotation(inverseTranspose, normalMatrix); + Matrix4.getMatrix3(inverseTranspose, normalMatrix); transformVector(normalMatrix, attributes.normal); transformVector(normalMatrix, attributes.tangent); diff --git a/Source/Core/Matrix3.js b/Source/Core/Matrix3.js index 23e9b6c21376..7c1f86843e69 100644 --- a/Source/Core/Matrix3.js +++ b/Source/Core/Matrix3.js @@ -1023,6 +1023,27 @@ define([ return result; }; + var UNIT = new Cartesian3(1, 1, 1); + + /** + * Extracts the rotation assuming the matrix is an affine transformation. + * + * @param {Matrix3} matrix The matrix. + * @param {Matrix3} result The object onto which to store the result. + * @returns {Matrix3} The modified result parameter + */ + Matrix3.getRotation = function(matrix, result) { + //>>includeStart('debug', pragmas.debug); + Check.typeOf.object('matrix', matrix); + Check.typeOf.object('result', result); + //>>includeEnd('debug'); + + var inverseScale = Cartesian3.divideComponents(UNIT, Matrix3.getScale(matrix, scratchScale), scratchScale); + result = Matrix3.multiplyByScale(matrix, inverseScale, result); + + return result; + }; + function computeFrobeniusNorm(matrix) { var norm = 0.0; for (var i = 0; i < 9; ++i) { diff --git a/Source/Core/Matrix4.js b/Source/Core/Matrix4.js index 19ed5ed1d520..edb25e0db7bc 100644 --- a/Source/Core/Matrix4.js +++ b/Source/Core/Matrix4.js @@ -5,6 +5,7 @@ define([ './defaultValue', './defined', './defineProperties', + './deprecationWarning', './freezeObject', './Math', './Matrix3', @@ -16,6 +17,7 @@ define([ defaultValue, defined, defineProperties, + deprecationWarning, freezeObject, CesiumMath, Matrix3, @@ -65,9 +67,9 @@ define([ * @see Packable */ function Matrix4(column0Row0, column1Row0, column2Row0, column3Row0, - column0Row1, column1Row1, column2Row1, column3Row1, - column0Row2, column1Row2, column2Row2, column3Row2, - column0Row3, column1Row3, column2Row3, column3Row3) { + column0Row1, column1Row1, column2Row1, column3Row1, + column0Row2, column1Row2, column2Row2, column3Row2, + column0Row3, column1Row3, column2Row3, column3Row3) { this[0] = defaultValue(column0Row0, 0.0); this[1] = defaultValue(column0Row1, 0.0); this[2] = defaultValue(column0Row2, 0.0); @@ -378,16 +380,16 @@ define([ var m21 = 2.0 * (yz + xw); var m22 = -x2 - y2 + z2 + w2; - result[0] = m00 * scaleX; - result[1] = m10 * scaleX; - result[2] = m20 * scaleX; - result[3] = 0.0; - result[4] = m01 * scaleY; - result[5] = m11 * scaleY; - result[6] = m21 * scaleY; - result[7] = 0.0; - result[8] = m02 * scaleZ; - result[9] = m12 * scaleZ; + result[0] = m00 * scaleX; + result[1] = m10 * scaleX; + result[2] = m20 * scaleX; + result[3] = 0.0; + result[4] = m01 * scaleY; + result[5] = m11 * scaleY; + result[6] = m21 * scaleY; + result[7] = 0.0; + result[8] = m02 * scaleZ; + result[9] = m12 * scaleZ; result[10] = m22 * scaleZ; result[11] = 0.0; result[12] = translation.x; @@ -565,8 +567,8 @@ define([ var positionX = position.x; var positionY = position.y; var positionZ = position.z; - var t0 = sX * -positionX + sY * -positionY+ sZ * -positionZ; - var t1 = uX * -positionX + uY * -positionY+ uZ * -positionZ; + var t0 = sX * -positionX + sY * -positionY + sZ * -positionZ; + var t1 = uX * -positionX + uY * -positionY + uZ * -positionZ; var t2 = fX * positionX + fY * positionY + fZ * positionZ; // The code below this comment is an optimized @@ -610,21 +612,21 @@ define([ return result; }; - /** - * Computes a Matrix4 instance representing a perspective transformation matrix. - * - * @param {Number} fovY The field of view along the Y axis in radians. - * @param {Number} aspectRatio The aspect ratio. - * @param {Number} near The distance to the near plane in meters. - * @param {Number} far The distance to the far plane in meters. - * @param {Matrix4} result The object in which the result will be stored. - * @returns {Matrix4} The modified result parameter. - * - * @exception {DeveloperError} fovY must be in (0, PI]. - * @exception {DeveloperError} aspectRatio must be greater than zero. - * @exception {DeveloperError} near must be greater than zero. - * @exception {DeveloperError} far must be greater than zero. - */ + /** + * Computes a Matrix4 instance representing a perspective transformation matrix. + * + * @param {Number} fovY The field of view along the Y axis in radians. + * @param {Number} aspectRatio The aspect ratio. + * @param {Number} near The distance to the near plane in meters. + * @param {Number} far The distance to the far plane in meters. + * @param {Matrix4} result The object in which the result will be stored. + * @returns {Matrix4} The modified result parameter. + * + * @exception {DeveloperError} fovY must be in (0, PI]. + * @exception {DeveloperError} aspectRatio must be greater than zero. + * @exception {DeveloperError} near must be greater than zero. + * @exception {DeveloperError} far must be greater than zero. + */ Matrix4.computePerspectiveFieldOfView = function(fovY, aspectRatio, near, far, result) { //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThan('fovY', fovY, 0.0); @@ -661,17 +663,17 @@ define([ }; /** - * Computes a Matrix4 instance representing an orthographic transformation matrix. - * - * @param {Number} left The number of meters to the left of the camera that will be in view. - * @param {Number} right The number of meters to the right of the camera that will be in view. - * @param {Number} bottom The number of meters below of the camera that will be in view. - * @param {Number} top The number of meters above of the camera that will be in view. - * @param {Number} near The distance to the near plane in meters. - * @param {Number} far The distance to the far plane in meters. - * @param {Matrix4} result The object in which the result will be stored. - * @returns {Matrix4} The modified result parameter. - */ + * Computes a Matrix4 instance representing an orthographic transformation matrix. + * + * @param {Number} left The number of meters to the left of the camera that will be in view. + * @param {Number} right The number of meters to the right of the camera that will be in view. + * @param {Number} bottom The number of meters below of the camera that will be in view. + * @param {Number} top The number of meters above of the camera that will be in view. + * @param {Number} near The distance to the near plane in meters. + * @param {Number} far The distance to the far plane in meters. + * @param {Matrix4} result The object in which the result will be stored. + * @returns {Matrix4} The modified result parameter. + */ Matrix4.computeOrthographicOffCenter = function(left, right, bottom, top, near, far, result) { //>>includeStart('debug', pragmas.debug); Check.typeOf.number('left', left); @@ -2110,7 +2112,7 @@ define([ //>>includeEnd('debug'); return (left === right) || - (defined(left) && + (defined(left) && defined(right) && Math.abs(left[0] - right[0]) <= epsilon && Math.abs(left[1] - right[1]) <= epsilon && @@ -2150,7 +2152,21 @@ define([ }; /** - * Gets the upper left 3x3 rotation matrix of the provided matrix, assuming the matrix is a affine transformation matrix. + * Gets the upper left 3x3 rotation matrix of the provided matrix, assuming the matrix is an affine transformation matrix. + * + * @param {Matrix4} matrix The matrix to use. + * @param {Matrix3} result The object onto which to store the result. + * @returns {Matrix3} The modified result parameter. + * + * @deprecated moved to Matrix4.getMatrix3 + */ + Matrix4.getRotation = function(matrix, result) { + deprecationWarning('Matrix4.getRotation', 'Matrix4.getRotation is deprecated and will be removed in Cesium 1.65. Use Matrix4.getMatrix3 instead.'); + return Matrix4.getMatrix3(matrix, result); + }; + + /** + * Gets the upper left 3x3 rotation matrix of the provided matrix, assuming the matrix is an affine transformation matrix. * * @param {Matrix4} matrix The matrix to use. * @param {Matrix3} result The object onto which to store the result. @@ -2165,13 +2181,13 @@ define([ * // [13.0, 17.0, 21.0, 25.0] * * var b = new Cesium.Matrix3(); - * Cesium.Matrix4.getRotation(m,b); + * Cesium.Matrix4.getMatrix3(m,b); * * // b = [10.0, 14.0, 18.0] * // [11.0, 15.0, 19.0] * // [12.0, 16.0, 20.0] */ - Matrix4.getRotation = function(matrix, result) { + Matrix4.getMatrix3 = function(matrix, result) { //>>includeStart('debug', pragmas.debug); Check.typeOf.object('matrix', matrix); Check.typeOf.object('result', result); @@ -2194,18 +2210,18 @@ define([ var scratchBottomRow = new Cartesian4(); var scratchExpectedBottomRow = new Cartesian4(0.0, 0.0, 0.0, 1.0); - /** - * Computes the inverse of the provided matrix using Cramers Rule. - * If the determinant is zero, the matrix can not be inverted, and an exception is thrown. - * If the matrix is an affine transformation matrix, it is more efficient - * to invert it with {@link Matrix4.inverseTransformation}. - * - * @param {Matrix4} matrix The matrix to invert. - * @param {Matrix4} result The object onto which to store the result. - * @returns {Matrix4} The modified result parameter. - * - * @exception {RuntimeError} matrix is not invertible because its determinate is zero. - */ + /** + * Computes the inverse of the provided matrix using Cramers Rule. + * If the determinant is zero, the matrix can not be inverted, and an exception is thrown. + * If the matrix is an affine transformation matrix, it is more efficient + * to invert it with {@link Matrix4.inverseTransformation}. + * + * @param {Matrix4} matrix The matrix to invert. + * @param {Matrix4} result The object onto which to store the result. + * @returns {Matrix4} The modified result parameter. + * + * @exception {RuntimeError} matrix is not invertible because its determinate is zero. + */ Matrix4.inverse = function(matrix, result) { //>>includeStart('debug', pragmas.debug); Check.typeOf.object('matrix', matrix); @@ -2284,9 +2300,9 @@ define([ var det = src0 * dst0 + src1 * dst1 + src2 * dst2 + src3 * dst3; if (Math.abs(det) < CesiumMath.EPSILON21) { - // Special case for a zero scale matrix that can occur, for example, - // when a model's node has a [0, 0, 0] scale. - if (Matrix3.equalsEpsilon(Matrix4.getRotation(matrix, scratchInverseRotation), scratchMatrix3Zero, CesiumMath.EPSILON7) && + // Special case for a zero scale matrix that can occur, for example, + // when a model's node has a [0, 0, 0] scale. + if (Matrix3.equalsEpsilon(Matrix4.getMatrix3(matrix, scratchInverseRotation), scratchMatrix3Zero, CesiumMath.EPSILON7) && Cartesian4.equals(Matrix4.getRow(matrix, 3, scratchBottomRow), scratchExpectedBottomRow)) { result[0] = 0.0; @@ -2353,7 +2369,7 @@ define([ //>>includeEnd('debug'); //This function is an optimized version of the below 4 lines. - //var rT = Matrix3.transpose(Matrix4.getRotation(matrix)); + //var rT = Matrix3.transpose(Matrix4.getMatrix3(matrix)); //var rTN = Matrix3.negate(rT); //var rTT = Matrix3.multiplyByVector(rTN, Matrix4.getTranslation(matrix)); //return Matrix4.fromRotationTranslation(rT, rTT, result); @@ -2622,10 +2638,10 @@ define([ * @returns {String} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2, column3)'. */ Matrix4.prototype.toString = function() { - return '(' + this[0] + ', ' + this[4] + ', ' + this[8] + ', ' + this[12] +')\n' + - '(' + this[1] + ', ' + this[5] + ', ' + this[9] + ', ' + this[13] +')\n' + - '(' + this[2] + ', ' + this[6] + ', ' + this[10] + ', ' + this[14] +')\n' + - '(' + this[3] + ', ' + this[7] + ', ' + this[11] + ', ' + this[15] +')'; + return '(' + this[0] + ', ' + this[4] + ', ' + this[8] + ', ' + this[12] + ')\n' + + '(' + this[1] + ', ' + this[5] + ', ' + this[9] + ', ' + this[13] + ')\n' + + '(' + this[2] + ', ' + this[6] + ', ' + this[10] + ', ' + this[14] + ')\n' + + '(' + this[3] + ', ' + this[7] + ', ' + this[11] + ', ' + this[15] + ')'; }; return Matrix4; diff --git a/Source/Core/Transforms.js b/Source/Core/Transforms.js index 7732bb39f097..72928ec492e8 100644 --- a/Source/Core/Transforms.js +++ b/Source/Core/Transforms.js @@ -376,7 +376,7 @@ define([ //>>includeEnd('debug'); var transform = Transforms.headingPitchRollToFixedFrame(origin, headingPitchRoll, ellipsoid, fixedFrameTransform, scratchENUMatrix4); - var rotation = Matrix4.getRotation(transform, scratchHPRMatrix3); + var rotation = Matrix4.getMatrix3(transform, scratchHPRMatrix3); return Quaternion.fromRotationMatrix(rotation, result); }; @@ -421,7 +421,7 @@ define([ transformCopy = Matrix4.setTranslation(transformCopy, Cartesian3.ZERO, transformCopy); toFixedFrame = Matrix4.multiply(toFixedFrame, transformCopy, toFixedFrame); - var quaternionRotation = Quaternion.fromRotationMatrix(Matrix4.getRotation(toFixedFrame, hprRotationScratch), hprQuaternionScratch); + var quaternionRotation = Quaternion.fromRotationMatrix(Matrix4.getMatrix3(toFixedFrame, hprRotationScratch), hprQuaternionScratch); quaternionRotation = Quaternion.normalize(quaternionRotation, quaternionRotation); return HeadingPitchRoll.fromQuaternion(quaternionRotation, result); @@ -878,7 +878,7 @@ define([ // Assuming the instance are positioned in WGS84, invert the WGS84 transform to get the local transform and then convert to 2D var fromENU = Transforms.eastNorthUpToFixedFrame(rtcCenter, ellipsoid, scratchFromENU); var toENU = Matrix4.inverseTransformation(fromENU, scratchToENU); - var rotation = Matrix4.getRotation(matrix, scratchRotation); + var rotation = Matrix4.getMatrix3(matrix, scratchRotation); var local = Matrix4.multiplyByMatrix3(toENU, rotation, result); Matrix4.multiply(swizzleMatrix, local, result); // Swap x, y, z for 2D Matrix4.setTranslation(result, projectedPosition, result); // Use the projected center diff --git a/Source/Renderer/UniformState.js b/Source/Renderer/UniformState.js index e2898aa2c6b4..5f18a7eee16f 100644 --- a/Source/Renderer/UniformState.js +++ b/Source/Renderer/UniformState.js @@ -297,7 +297,7 @@ define([ if (this._inverseTransposeModelDirty) { this._inverseTransposeModelDirty = false; - Matrix4.getRotation(this.inverseModel, m); + Matrix4.getMatrix3(this.inverseModel, m); Matrix3.transpose(m, m); } @@ -979,7 +979,7 @@ define([ function setView(uniformState, matrix) { Matrix4.clone(matrix, uniformState._view); - Matrix4.getRotation(matrix, uniformState._viewRotation); + Matrix4.getMatrix3(matrix, uniformState._viewRotation); uniformState._view3DDirty = true; uniformState._inverseView3DDirty = true; @@ -1001,7 +1001,7 @@ define([ function setInverseView(uniformState, matrix) { Matrix4.clone(matrix, uniformState._inverseView); - Matrix4.getRotation(matrix, uniformState._inverseViewRotation); + Matrix4.getMatrix3(matrix, uniformState._inverseViewRotation); } function setProjection(uniformState, matrix) { @@ -1314,7 +1314,8 @@ define([ uniformState._normalDirty = false; var m = uniformState._normal; - Matrix4.getRotation(uniformState.inverseModelView, m); + Matrix4.getMatrix3(uniformState.inverseModelView, m); + Matrix3.getRotation(m, m); Matrix3.transpose(m, m); } } @@ -1324,7 +1325,8 @@ define([ uniformState._normal3DDirty = false; var m = uniformState._normal3D; - Matrix4.getRotation(uniformState.inverseModelView3D, m); + Matrix4.getMatrix3(uniformState.inverseModelView3D, m); + Matrix3.getRotation(m, m); Matrix3.transpose(m, m); } } @@ -1332,16 +1334,16 @@ define([ function cleanInverseNormal(uniformState) { if (uniformState._inverseNormalDirty) { uniformState._inverseNormalDirty = false; - - Matrix4.getRotation(uniformState.inverseModelView, uniformState._inverseNormal); + Matrix4.getMatrix3(uniformState.inverseModelView, uniformState._inverseNormal); + Matrix3.getRotation(uniformState._inverseNormal, uniformState._inverseNormal); } } function cleanInverseNormal3D(uniformState) { if (uniformState._inverseNormal3DDirty) { uniformState._inverseNormal3DDirty = false; - - Matrix4.getRotation(uniformState.inverseModelView3D, uniformState._inverseNormal3D); + Matrix4.getMatrix3(uniformState.inverseModelView3D, uniformState._inverseNormal3D); + Matrix3.getRotation(uniformState._inverseNormal3D, uniformState._inverseNormal3D); } } @@ -1444,7 +1446,7 @@ define([ } else { view2Dto3D(that._cameraPosition, that._cameraDirection, that._cameraRight, that._cameraUp, that._frustum2DWidth, that._mode, that._mapProjection, that._view3D); } - Matrix4.getRotation(that._view3D, that._viewRotation3D); + Matrix4.getMatrix3(that._view3D, that._viewRotation3D); that._view3DDirty = false; } } @@ -1452,7 +1454,7 @@ define([ function updateInverseView3D(that){ if (that._inverseView3DDirty) { Matrix4.inverseTransformation(that.view3D, that._inverseView3D); - Matrix4.getRotation(that._inverseView3D, that._inverseViewRotation3D); + Matrix4.getMatrix3(that._inverseView3D, that._inverseViewRotation3D); that._inverseView3DDirty = false; } } diff --git a/Source/Scene/Cesium3DTile.js b/Source/Scene/Cesium3DTile.js index d0eedba6895a..c19bc82b81a5 100644 --- a/Source/Scene/Cesium3DTile.js +++ b/Source/Scene/Cesium3DTile.js @@ -142,12 +142,15 @@ define([ * @readonly */ this.geometricError = header.geometricError; + this._geometricError = header.geometricError; - if (!defined(this.geometricError)) { - this.geometricError = defined(parent) ? parent.geometricError : tileset._geometricError; + if (!defined(this._geometricError)) { + this._geometricError = defined(parent) ? parent.geometricError : tileset._geometricError; Cesium3DTile._deprecationWarning('geometricErrorUndefined', 'Required property geometricError is undefined for this tile. Using parent\'s geometric error instead.'); } + this.updateGeometricErrorScale(); + var refine; if (defined(header.refine)) { if (header.refine === 'replace' || header.refine === 'add') { @@ -1107,7 +1110,7 @@ define([ // Find the transformed center and halfAxes center = Matrix4.multiplyByPoint(transform, center, center); - var rotationScale = Matrix4.getRotation(transform, scratchMatrix); + var rotationScale = Matrix4.getMatrix3(transform, scratchMatrix); halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes); if (defined(result)) { @@ -1131,7 +1134,7 @@ define([ // This is why the transform is calculated as the difference between the initial transform and the current transform. transform = Matrix4.multiplyTransformation(transform, Matrix4.inverseTransformation(initialTransform, scratchTransform), scratchTransform); center = Matrix4.multiplyByPoint(transform, center, center); - var rotationScale = Matrix4.getRotation(transform, scratchMatrix); + var rotationScale = Matrix4.getMatrix3(transform, scratchMatrix); halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes); if (defined(result) && (result instanceof TileOrientedBoundingBox)) { @@ -1231,12 +1234,20 @@ define([ this._viewerRequestVolume = this.createBoundingVolume(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume); } + this.updateGeometricErrorScale(); + // Destroy the debug bounding volumes. They will be generated fresh. this._debugBoundingVolume = this._debugBoundingVolume && this._debugBoundingVolume.destroy(); this._debugContentBoundingVolume = this._debugContentBoundingVolume && this._debugContentBoundingVolume.destroy(); this._debugViewerRequestVolume = this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy(); }; + Cesium3DTile.prototype.updateGeometricErrorScale = function() { + var scale = Matrix4.getScale(this.computedTransform, scratchScale); + var uniformScale = Cartesian3.maximumComponent(scale); + this.geometricError = this._geometricError * uniformScale; + }; + function applyDebugSettings(tile, tileset, frameState) { if (!frameState.passes.render) { return; diff --git a/Source/Scene/Instanced3DModel3DTileContent.js b/Source/Scene/Instanced3DModel3DTileContent.js index aa150f33f08b..d00d17e8b288 100644 --- a/Source/Scene/Instanced3DModel3DTileContent.js +++ b/Source/Scene/Instanced3DModel3DTileContent.js @@ -378,7 +378,7 @@ define([ hasCustomOrientation = true; } else if (eastNorthUp) { Transforms.eastNorthUpToFixedFrame(instancePosition, Ellipsoid.WGS84, instanceTransform); - Matrix4.getRotation(instanceTransform, instanceRotation); + Matrix4.getMatrix3(instanceTransform, instanceRotation); } else { Matrix3.clone(Matrix3.IDENTITY, instanceRotation); } diff --git a/Source/Scene/Model.js b/Source/Scene/Model.js index 0f04998aea38..e185a46c7d58 100644 --- a/Source/Scene/Model.js +++ b/Source/Scene/Model.js @@ -3159,7 +3159,7 @@ define([ var mInverseTranspose = new Matrix3(); return function() { Matrix4.inverse(runtimeNode.computedMatrix, mInverse); - Matrix4.getRotation(mInverse, mInverseTranspose); + Matrix4.getMatrix3(mInverse, mInverseTranspose); return Matrix3.transpose(mInverseTranspose, mInverseTranspose); }; }, @@ -3170,7 +3170,7 @@ define([ return function() { Matrix4.multiplyTransformation(uniformState.view, runtimeNode.computedMatrix, mv); Matrix4.inverse(mv, mvInverse); - Matrix4.getRotation(mvInverse, mvInverseTranspose); + Matrix4.getMatrix3(mvInverse, mvInverseTranspose); return Matrix3.transpose(mvInverseTranspose, mvInverseTranspose); }; }, diff --git a/Specs/Core/Matrix3Spec.js b/Specs/Core/Matrix3Spec.js index 5094c37c82c2..2a4613f202ce 100644 --- a/Specs/Core/Matrix3Spec.js +++ b/Specs/Core/Matrix3Spec.js @@ -641,6 +641,46 @@ describe('Core/Matrix3', function() { expect(result).toEqual(expected); }); + it('getRotation returns matrix without scale', function() { + var matrix = new Matrix3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); + var result = new Matrix3(); + var expected = Matrix3.fromArray([ + 0.12309149097933272, 0.4923659639173309, 0.8616404368553291, + 0.20739033894608505, 0.5184758473652127, 0.8295613557843402, + 0.26726124191242440, 0.5345224838248488, 0.8017837257372732 + ]); + var scale = new Cartesian3(); + var expectedScale = new Cartesian3(1.0, 1.0, 1.0); + result = Matrix3.getRotation(matrix, result); + var resultScale = Matrix3.getScale(result, scale); + expect(resultScale).toEqualEpsilon(expectedScale, CesiumMath.EPSILON14); + expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON14); + }); + + it('getRotation does not modify rotation matrix', function() { + var tmp = new Matrix3(); + var result = new Matrix3(); + var rotation = Matrix3.clone(Matrix3.IDENTITY, new Matrix3()); + Matrix3.multiply(rotation, Matrix3.fromRotationX(1.0, tmp), rotation); + Matrix3.multiply(rotation, Matrix3.fromRotationY(2.0, tmp), rotation); + Matrix3.multiply(rotation, Matrix3.fromRotationZ(3.0, tmp), rotation); + result = Matrix3.getRotation(rotation, result); + expect(rotation).toEqualEpsilon(result, CesiumMath.EPSILON14); + expect(rotation).not.toBe(result); + }); + + it('getRotation throws without a matrix', function() { + expect(function() { + return Matrix3.getRotation(); + }).toThrowDeveloperError(); + }); + + it('getRotation throws without a result', function() { + expect(function() { + return Matrix3.getRotation(new Matrix3()); + }).toThrowDeveloperError(); + }); + it('transpose works with a result parameter that is an input result parameter', function() { var matrix = new Matrix3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); var expected = new Matrix3(1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0); diff --git a/Specs/Core/Matrix4Spec.js b/Specs/Core/Matrix4Spec.js index ebb3b9b0696c..c9a96345ca83 100644 --- a/Specs/Core/Matrix4Spec.js +++ b/Specs/Core/Matrix4Spec.js @@ -958,11 +958,11 @@ describe('Core/Matrix4', function() { expect(expected).toEqual(returnedResult); }); - it('getRotation works', function() { + it('getMatrix3 works', function() { var matrix = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); var expected = new Matrix3(1, 2, 3, 5, 6, 7, 9, 10, 11); var result = new Matrix3(); - var returnedResult = Matrix4.getRotation(matrix, result); + var returnedResult = Matrix4.getMatrix3(matrix, result); expect(returnedResult).toBe(result); expect(expected).toEqual(returnedResult); }); @@ -1545,9 +1545,9 @@ describe('Core/Matrix4', function() { }).toThrowDeveloperError(); }); - it('getRotation throws without matrix parameter', function() { + it('getMatrix3 throws without matrix parameter', function() { expect(function() { - Matrix4.getRotation(undefined); + Matrix4.getMatrix3(undefined); }).toThrowDeveloperError(); }); @@ -1720,9 +1720,9 @@ describe('Core/Matrix4', function() { }).toThrowDeveloperError(); }); - it('getRotation throws without result parameter', function() { + it('getMatrix3 throws without result parameter', function() { expect(function() { - Matrix4.getRotation(new Matrix4()); + Matrix4.getMatrix3(new Matrix4()); }).toThrowDeveloperError(); }); diff --git a/Specs/Core/TransformsSpec.js b/Specs/Core/TransformsSpec.js index 43244093ac5f..81b5afe7d656 100644 --- a/Specs/Core/TransformsSpec.js +++ b/Specs/Core/TransformsSpec.js @@ -548,7 +548,7 @@ describe('Core/Transforms', function() { var hpr = new HeadingPitchRoll(heading, pitch, roll); var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); - var expected = Matrix4.getRotation(transform, new Matrix3()); + var expected = Matrix4.getMatrix3(transform, new Matrix3()); var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame); var actual = Matrix3.fromQuaternion(quaternion); @@ -563,7 +563,7 @@ describe('Core/Transforms', function() { var hpr = new HeadingPitchRoll(heading, pitch, roll); var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); - var expected = Matrix4.getRotation(transform, new Matrix3()); + var expected = Matrix4.getMatrix3(transform, new Matrix3()); var result = new Quaternion(); var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, Transforms.eastNorthUpToFixedFrame, result); @@ -580,7 +580,7 @@ describe('Core/Transforms', function() { var hpr = new HeadingPitchRoll(heading, pitch, roll); var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE); - var expected = Matrix4.getRotation(transform, new Matrix3()); + var expected = Matrix4.getMatrix3(transform, new Matrix3()); var result = new Quaternion(); var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, undefined, result); @@ -598,7 +598,7 @@ describe('Core/Transforms', function() { var fixedFrameTransform = Transforms.localFrameToFixedFrameGenerator('west','south'); var transform = Transforms.headingPitchRollToFixedFrame(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform); - var expected = Matrix4.getRotation(transform, new Matrix3()); + var expected = Matrix4.getMatrix3(transform, new Matrix3()); var result = new Quaternion(); var quaternion = Transforms.headingPitchRollQuaternion(origin, hpr, Ellipsoid.UNIT_SPHERE, fixedFrameTransform, result); @@ -1075,13 +1075,13 @@ describe('Core/Transforms', function() { var modelMatrix = Transforms.headingPitchRollToFixedFrame(origin, hpr, ellipsoid); var modelMatrix2D = Transforms.basisTo2D(projection, modelMatrix, new Matrix4()); - var rotation2D = Matrix4.getRotation(modelMatrix2D, new Matrix3()); + var rotation2D = Matrix4.getMatrix3(modelMatrix2D, new Matrix3()); var enu = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid); var enuInverse = Matrix4.inverseTransformation(enu, enu); var hprPlusTranslate = Matrix4.multiply(enuInverse, modelMatrix, new Matrix4()); - var hpr2 = Matrix4.getRotation(hprPlusTranslate, new Matrix3()); + var hpr2 = Matrix4.getMatrix3(hprPlusTranslate, new Matrix3()); var row0 = Matrix3.getRow(hpr2, 0, new Cartesian3()); var row1 = Matrix3.getRow(hpr2, 1, new Cartesian3()); @@ -1104,8 +1104,8 @@ describe('Core/Transforms', function() { var expected = Matrix4.fromTranslation(origin); Transforms.basisTo2D(projection, expected, expected); - var actualRotation = Matrix4.getRotation(actual, new Matrix3()); - var expectedRotation = Matrix4.getRotation(expected, new Matrix3()); + var actualRotation = Matrix4.getMatrix3(actual, new Matrix3()); + var expectedRotation = Matrix4.getMatrix3(expected, new Matrix3()); expect(actualRotation).toEqualEpsilon(expectedRotation, CesiumMath.EPSILON14); var fromENU = Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, new Matrix4()); diff --git a/Specs/Scene/CameraSpec.js b/Specs/Scene/CameraSpec.js index 3696ded64abf..fea2f632880f 100644 --- a/Specs/Scene/CameraSpec.js +++ b/Specs/Scene/CameraSpec.js @@ -208,7 +208,7 @@ describe('Scene/Camera', function() { var ellipsoid = Ellipsoid.WGS84; var toFixedFrame = Transforms.eastNorthUpToFixedFrame(camera.position, ellipsoid); - var transform = Matrix4.getRotation(toFixedFrame, new Matrix3()); + var transform = Matrix4.getMatrix3(toFixedFrame, new Matrix3()); Matrix3.transpose(transform, transform); var right = Matrix3.multiplyByVector(transform, camera.right, new Cartesian3()); @@ -477,7 +477,7 @@ describe('Scene/Camera', function() { camera.up = Cartesian3.cross(camera.right, camera.direction, new Cartesian3()); var toFixedFrame = Transforms.eastNorthUpToFixedFrame(camera.position, ellipsoid); - var transform = Matrix4.getRotation(toFixedFrame, new Matrix3()); + var transform = Matrix4.getMatrix3(toFixedFrame, new Matrix3()); Matrix3.transpose(transform, transform); var right = Matrix3.multiplyByVector(transform, camera.right, new Cartesian3());