public static FromRotationMatrix ( Axiom.Math.Matrix3 matrix ) : |
||
matrix | Axiom.Math.Matrix3 | |
return |
/// <summary> /// Decompose the matrix. /// </summary> /// <param name="translation"></param> /// <param name="scale"></param> /// <param name="orientation"></param> public void Decompose(out Vector3 translation, out Vector3 scale, out Quaternion orientation) { scale = Vector3.UnitScale; Matrix3 rotation = Matrix3.Identity; Vector3 axis = Vector3.Zero; axis.x = this.m00; axis.y = this.m10; axis.z = this.m20; scale.x = axis.Normalize(); // Normalize() returns the vector's length before it was normalized rotation.m00 = axis.x; rotation.m10 = axis.y; rotation.m20 = axis.z; axis.x = this.m01; axis.y = this.m11; axis.z = this.m21; scale.y = axis.Normalize(); rotation.m01 = axis.x; rotation.m11 = axis.y; rotation.m21 = axis.z; axis.x = this.m02; axis.y = this.m12; axis.z = this.m22; scale.z = axis.Normalize(); rotation.m02 = axis.x; rotation.m12 = axis.y; rotation.m22 = axis.z; orientation = Quaternion.FromRotationMatrix(rotation); translation = this.Translation; }
/// <summary> /// Decompose the matrix. /// </summary> /// <param name="translation"></param> /// <param name="scale"></param> /// <param name="orientation"></param> public void Decompose(out Vector3 translation, out Vector3 scale, out Quaternion orientation) { scale = Vector3.UnitScale; var rotation = Matrix3.Identity; var axis = Vector3.Zero; axis.x = this.m00; axis.y = this.m10; axis.z = this.m20; scale.x = axis.Normalize(); // Normalize() returns the vector's length before it was normalized rotation.m00 = axis.x; rotation.m10 = axis.y; rotation.m20 = axis.z; axis.x = this.m01; axis.y = this.m11; axis.z = this.m21; scale.y = axis.Normalize(); rotation.m01 = axis.x; rotation.m11 = axis.y; rotation.m21 = axis.z; axis.x = this.m02; axis.y = this.m12; axis.z = this.m22; scale.z = axis.Normalize(); rotation.m02 = axis.x; rotation.m12 = axis.y; rotation.m22 = axis.z; /* http://www.robertblum.com/articles/2005/02/14/decomposing-matrices check to support transforms with negative scaling */ //thanks sebj for the info if (rotation.Determinant < 0) { rotation.m00 = -rotation.m00; rotation.m10 = -rotation.m10; rotation.m20 = -rotation.m20; scale.x = -scale.x; } orientation = Quaternion.FromRotationMatrix(rotation); translation = Translation; }