/// <summary> Performs SVD on this matrix and gets scale and rotation. /// Rotation is placed into rot. /// </summary> /// <param name="rot3">the rotation factor(Matrix3d). /// </param> /// <param name="rot4">the rotation factor(Matrix4f) only upper 3x3 elements are changed. /// </param> /// <returns> scale factor /// </returns> private float SVD(Matrix3f rot3, Matrix4f rot4) { // this is a simple svd. // Not complete but fast and reasonable. // See comment in Matrix3d. //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" float s = (float) System.Math.Sqrt((m00 * m00 + m10 * m10 + m20 * m20 + m01 * m01 + m11 * m11 + m21 * m21 + m02 * m02 + m12 * m12 + m22 * m22) / 3.0); // zero-div may occur. float t = (s == 0.0f?0.0f:1.0f / s); if (rot3 != null) { this.getRotationScale(rot3); rot3.mul(t); } if (rot4 != null) { if (rot4 != this) rot4.setRotationScale(this); // private method rot4.mulRotationScale(t); // private method } return s; }
/// <summary> Performs SVD on this matrix and gets the scale and the pure rotation. /// The pure rotation is placed into rot. /// </summary> /// <param name="rot">the rotation factor. /// </param> /// <returns> scale factor /// </returns> private float SVD(Matrix3f rot) { // this is a simple svd. // Not complete but fast and reasonable. // See comment in Matrix3d. double s = System.Math.Sqrt((m00 * m00 + m10 * m10 + m20 * m20 + m01 * m01 + m11 * m11 + m21 * m21 + m02 * m02 + m12 * m12 + m22 * m22) / 3.0); // zero-div may occur. double t = (s == 0.0?0.0:1.0 / s); if (rot != null) { this.getRotationScale(rot); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" rot.mul((float) t); } //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" return (float) s; }