Example #1
0
        public float Determinant()
        {
            //Current implementation of cross far from optimal without shuffles. This assumes it'll eventually be accelerated.
            Vector3 cross;

            Vector3x.Cross(ref Y, ref Z, out cross);
            return(Vector3.Dot(X, cross));
        }
Example #2
0
        public static void Invert(ref Matrix3x3 m, out Matrix3x3 inverse)
        {
            //Current implementation of cross far from optimal without shuffles, and even then this has some room for improvement.
            //Inverts should be really rare, so it's not too concerning. Use the scalar version when possible until ryujit improves (and we improve this implementation).
            Vector3 yz, zx, xy;

            Vector3x.Cross(ref m.Y, ref m.Z, out yz);
            Vector3x.Cross(ref m.Z, ref m.X, out zx);
            Vector3x.Cross(ref m.X, ref m.Y, out xy);
            var inverseDeterminant = 1f / Vector3.Dot(m.X, yz);

            inverse.X = yz * inverseDeterminant;
            inverse.Y = zx * inverseDeterminant;
            inverse.Z = xy * inverseDeterminant;
            Transpose(ref inverse, out inverse);
        }
Example #3
0
        /// <summary>
        /// Creates a view matrix pointing in a direction with a given up vector.
        /// </summary>
        /// <param name="position">Position of the camera.</param>
        /// <param name="forward">Forward direction of the camera.</param>
        /// <param name="upVector">Up vector of the camera.</param>
        /// <param name="viewMatrix">Look at matrix.</param>
        public static void CreateView(ref Vector3 position, ref Vector3 forward, ref Vector3 upVector, out Matrix viewMatrix)
        {
            float   length = forward.Length();
            var     z      = forward / -length;
            Vector3 x;

            Vector3x.Cross(ref upVector, ref z, out x);
            x = Vector3.Normalize(x);
            Vector3 y;

            Vector3x.Cross(ref z, ref x, out y);

            viewMatrix.X = new Vector4(x.X, y.X, z.X, 0);
            viewMatrix.Y = new Vector4(x.Y, y.Y, z.Y, 0);
            viewMatrix.Z = new Vector4(x.Z, y.Z, z.Z, 0);
            viewMatrix.W = new Vector4(
                -Vector3.Dot(x, position),
                -Vector3.Dot(y, position),
                -Vector3.Dot(z, position), 1);
        }