Example #1
0
        /// <summary>
        /// Converts the quaternion rotation into euler angle (pitch/yaw/roll) rotation.
        /// </summary>
        /// <returns>Rotation as euler angles, in degrees.</returns>
        public Vector3 ToEuler()
        {
            Matrix3 matRot = ToRotationMatrix();

            return(matRot.ToEulerAngles());
        }
Example #2
0
        /// <summary>
        /// Decomposes the matrix into a set of values.
        /// </summary>
        /// <param name="matQ">Columns form orthonormal bases. If your matrix is affine and doesn't use non-uniform scaling
        /// this matrix will be the rotation part of the matrix.
        /// </param>
        /// <param name="vecD">If the matrix is affine these will be scaling factors of the matrix.</param>
        /// <param name="vecU">If the matrix is affine these will be shear factors of the matrix.</param>
        public void QDUDecomposition(out Matrix3 matQ, out Vector3 vecD, out Vector3 vecU)
        {
            matQ = new Matrix3();
            vecD = new Vector3();
            vecU = new Vector3();

            // Build orthogonal matrix Q
            float invLength = MathEx.InvSqrt(m00 * m00 + m10 * m10 + m20 * m20);

            matQ.m00 = m00 * invLength;
            matQ.m10 = m10 * invLength;
            matQ.m20 = m20 * invLength;

            float dot = matQ.m00 * m01 + matQ.m10 * m11 + matQ.m20 * m21;

            matQ.m01 = m01 - dot * matQ.m00;
            matQ.m11 = m11 - dot * matQ.m10;
            matQ.m21 = m21 - dot * matQ.m20;

            invLength = MathEx.InvSqrt(matQ.m01 * matQ.m01 + matQ.m11 * matQ.m11 + matQ.m21 * matQ.m21);
            matQ.m01 *= invLength;
            matQ.m11 *= invLength;
            matQ.m21 *= invLength;

            dot      = matQ.m00 * m02 + matQ.m10 * m12 + matQ.m20 * m22;
            matQ.m02 = m02 - dot * matQ.m00;
            matQ.m12 = m12 - dot * matQ.m10;
            matQ.m22 = m22 - dot * matQ.m20;

            dot       = matQ.m01 * m02 + matQ.m11 * m12 + matQ.m21 * m22;
            matQ.m02 -= dot * matQ.m01;
            matQ.m12 -= dot * matQ.m11;
            matQ.m22 -= dot * matQ.m21;

            invLength = MathEx.InvSqrt(matQ.m02 * matQ.m02 + matQ.m12 * matQ.m12 + matQ.m22 * matQ.m22);
            matQ.m02 *= invLength;
            matQ.m12 *= invLength;
            matQ.m22 *= invLength;

            // Guarantee that orthogonal matrix has determinant 1 (no reflections)
            float fDet = matQ.m00 * matQ.m11 * matQ.m22 + matQ.m01 * matQ.m12 * matQ.m20 +
                         matQ.m02 * matQ.m10 * matQ.m21 - matQ.m02 * matQ.m11 * matQ.m20 -
                         matQ.m01 * matQ.m10 * matQ.m22 - matQ.m00 * matQ.m12 * matQ.m21;

            if (fDet < 0.0f)
            {
                matQ.m00 = -matQ.m00;
                matQ.m01 = -matQ.m01;
                matQ.m02 = -matQ.m02;
                matQ.m10 = -matQ.m10;
                matQ.m11 = -matQ.m11;
                matQ.m12 = -matQ.m12;
                matQ.m20 = -matQ.m20;
                matQ.m21 = -matQ.m21;
                matQ.m21 = -matQ.m22;
            }

            // Build "right" matrix R
            Matrix3 matRight = new Matrix3();

            matRight.m00 = matQ.m00 * m00 + matQ.m10 * m10 + matQ.m20 * m20;
            matRight.m01 = matQ.m00 * m01 + matQ.m10 * m11 + matQ.m20 * m21;
            matRight.m11 = matQ.m01 * m01 + matQ.m11 * m11 + matQ.m21 * m21;
            matRight.m02 = matQ.m00 * m02 + matQ.m10 * m12 + matQ.m20 * m22;
            matRight.m12 = matQ.m01 * m02 + matQ.m11 * m12 + matQ.m21 * m22;
            matRight.m22 = matQ.m02 * m02 + matQ.m12 * m12 + matQ.m22 * m22;

            // The scaling component
            vecD[0] = matRight.m00;
            vecD[1] = matRight.m11;
            vecD[2] = matRight.m22;

            // The shear component
            float invD0 = 1.0f / vecD[0];

            vecU[0] = matRight.m01 * invD0;
            vecU[1] = matRight.m02 * invD0;
            vecU[2] = matRight.m12 / vecD[1];
        }
Example #3
0
 private static extern void Internal_setMat3(IntPtr thisPtr, string name, ref Matrix3 value, int arrayIdx);
Example #4
0
 private static extern void Internal_getMat3(IntPtr thisPtr, string name, int arrayIdx, out Matrix3 __output);
Example #5
0
 /// <summary>
 /// Assigns a 3x3 matrix to the shader parameter with the specified name.
 ///
 /// Optionally if the parameter is an array you may provide an array index to assign the value to.
 /// </summary>
 public void SetMatrix3(string name, Matrix3 value, int arrayIdx = 0)
 {
     Internal_setMat3(mCachedPtr, name, ref value, arrayIdx);
 }