コード例 #1
0
        /// <summary>
        /// Converts the input matrix to Unity transform matrix.
        /// </summary>
        public static UnityEngine.Matrix4x4 ToUnityTransform(this Matrix4x4 inputMatrix)
        {
            var zflip = UnityEngine.Matrix4x4.identity;

            zflip.SetColumn(2, -1 * zflip.GetColumn(2));

            return(zflip * inputMatrix.ToUnityRaw() * zflip);
        }
コード例 #2
0
        public static UnityEngine.Matrix4x4?GetUnityMatrix(this Matrix4x4 matrix)
        {
            if (matrix == Matrix4x4.Zero)
            {
                return(null);
            }

            return(matrix.ToUnityRaw());
        }
コード例 #3
0
        /// <summary>
        /// Converts the input projection matrix to a Unity matrix and overrides the near and far clip plane.
        /// </summary>
        public static UnityEngine.Matrix4x4 ToUnityProjection(this Matrix4x4 inputMatrix, float nearClipPlane, float farClipPlane)
        {
            // The following code enforces valid near/far clip plane values
            float epsilon = 0.01f;

            if (nearClipPlane < epsilon)
            {
                nearClipPlane = epsilon;
            }

            if (farClipPlane < nearClipPlane + epsilon)
            {
                farClipPlane = nearClipPlane + epsilon;
            }

            var unityMatrix = inputMatrix.ToUnityRaw();

            unityMatrix.m22 = -(farClipPlane + nearClipPlane) / (farClipPlane - nearClipPlane);
            unityMatrix.m23 = -(2.0f * farClipPlane * nearClipPlane) / (farClipPlane - nearClipPlane);

            return(unityMatrix);
        }