Afterglow.Math.Quaternion.ToMatrix C# (CSharp) Method

ToMatrix() public method

Converts to quaternion to a rotation matrix.
public ToMatrix ( ) : Matrix
return Matrix
        public Matrix ToMatrix()
        {
            var m1 = new Matrix(
                 W, -Z,  Y,  X,
                 Z,  W, -X,  Y,
                -Y,  X,  W,  Z,
                -X, -Y, -Z,  W);
            var m2 = new Matrix(
                 W, -Z,  Y, -X,
                 Z,  W, -X, -Y,
                -Y,  X,  W, -Z,
                 X,  Y,  Z,  W);

            return m1 * m2;
        }

Usage Example

Example #1
0
        public void ToMatrix()
        {
            Vector3 rotationAxis = Vector3.ZAxis;
            var angle = Constants.HALF_PI;

            var quaternion = new Quaternion(rotationAxis, angle);

            Matrix matrix = quaternion.ToMatrix();

            var expected = new Matrix(
                Functions.Cos(angle), -Functions.Sin(angle), 0, 0,
                Functions.Sin(angle), Functions.Cos(angle), 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1);

            matrix.ShouldEqual(expected);
        }