Example #1
0
        /// <remarks>
        /// This function assumes that the quaternion has a magnitude of one.  (it's optimized for that)
        ///
        /// I still have no clue what should be done with this matrix, but here it is
        /// </remarks>
        public MyMatrix4 ToMatrix4FromUnitQuaternion()
        {
            throw new ApplicationException("Test this function first");

            MyMatrix4 retVal = new MyMatrix4();

            // All these cached results are used at least twice, so I'm not being wastefull
            double xx = this.X * this.X;
            double yy = this.Y * this.Y;
            double zz = this.Z * this.Z;

            double xy = this.X * this.Y;
            double xz = this.X * this.Z;

            double yz = this.Y * this.Z;

            double wy = this.W * this.Y;
            double wz = this.W * this.Z;

            // Row 1
            retVal.M11 = 1 - ((2 * yy) - (2 * zz));
            retVal.M12 = (2 * xy) - (2 * wz);
            retVal.M13 = (2 * xz) + (2 * wy);
            retVal.M14 = 0;

            // Row 2
            retVal.M21 = (2 * xy) + (2 * wz);
            retVal.M22 = 1 - ((2 * xx) - (2 * zz));
            retVal.M23 = (2 * yz) - (2 * wz);
            retVal.M24 = 0;

            // Row 3
            retVal.M31 = (2 * xz) - (2 * wy);
            retVal.M32 = (2 * yz) - (2 * wz);
            retVal.M33 = 1 - ((2 * xx) - (2 * yy));
            retVal.M34 = 0;

            // Row 4
            retVal.M41 = 0;
            retVal.M42 = 0;
            retVal.M43 = 0;
            retVal.M44 = 1;

            // Exit Function
            return(retVal);
        }
Example #2
0
        /// <remarks>
        /// This function assumes that the quaternion has a magnitude of one.  (it's optimized for that)
        /// 
        /// I still have no clue what should be done with this matrix, but here it is
        /// </remarks>
        public MyMatrix4 ToMatrix4FromUnitQuaternion()
        {
            throw new ApplicationException("Test this function first");

            MyMatrix4 retVal = new MyMatrix4();

            // All these cached results are used at least twice, so I'm not being wastefull
            double xx = this.X * this.X;
            double yy = this.Y * this.Y;
            double zz = this.Z * this.Z;

            double xy = this.X * this.Y;
            double xz = this.X * this.Z;

            double yz = this.Y * this.Z;

            double wy = this.W * this.Y;
            double wz = this.W * this.Z;

            // Row 1
            retVal.M11 = 1 - ((2 * yy) - (2 * zz));
            retVal.M12 = (2 * xy) - (2 * wz);
            retVal.M13 = (2 * xz) + (2 * wy);
            retVal.M14 = 0;

            // Row 2
            retVal.M21 = (2 * xy) + (2 * wz);
            retVal.M22 = 1 - ((2 * xx) - (2 * zz));
            retVal.M23 = (2 * yz) - (2 * wz);
            retVal.M24 = 0;

            // Row 3
            retVal.M31 = (2 * xz) - (2 * wy);
            retVal.M32 = (2 * yz) - (2 * wz);
            retVal.M33 = 1 - ((2 * xx) - (2 * yy));
            retVal.M34 = 0;

            // Row 4
            retVal.M41 = 0;
            retVal.M42 = 0;
            retVal.M43 = 0;
            retVal.M44 = 1;

            // Exit Function
            return retVal;
        }