Beispiel #1
0
        /// <summary>
        /// Creates a Matrix3x3 that flattens geometry into a shadow.
        /// </summary>
        /// <param name="light">The light direction. If the W component is 0, the light is directional light; if the
        /// W component is 1, the light is a point light.</param>
        /// <param name="plane">The plane onto which to project the geometry as a shadow. This parameter is assumed to be normalized.</param>
        /// <param name="result">When the method completes, contains the shadow Matrix3x3.</param>
        public static void Shadow(ref MyVector4 light, ref MyPlane plane, out MyMatrix3x3 result)
        {
            float dot = (plane.Normal.X * light.X) + (plane.Normal.Y * light.Y) + (plane.Normal.Z * light.Z) + (plane.D * light.W);
            float x   = -plane.Normal.X;
            float y   = -plane.Normal.Y;
            float z   = -plane.Normal.Z;
            float d   = -plane.D;

            result.M11 = (x * light.X) + dot;
            result.M21 = y * light.X;
            result.M31 = z * light.X;
            result.M12 = x * light.Y;
            result.M22 = (y * light.Y) + dot;
            result.M32 = z * light.Y;
            result.M13 = x * light.Z;
            result.M23 = y * light.Z;
            result.M33 = (z * light.Z) + dot;
        }
Beispiel #2
0
        /// <summary>
        /// Builds a Matrix3x3 that can be used to reflect vectors about a plane for which the reflection occurs.
        /// This plane is assumed to be normalized
        /// </summary>
        /// <param name="result">When the method completes, contains the reflection Matrix3x3.</param>
        public void Reflection(out MyMatrix3x3 result)
        {
            float x  = this.Normal.X;
            float y  = this.Normal.Y;
            float z  = this.Normal.Z;
            float x2 = -2.0f * x;
            float y2 = -2.0f * y;
            float z2 = -2.0f * z;

            result.M11 = (x2 * x) + 1.0f;
            result.M12 = y2 * x;
            result.M13 = z2 * x;
            result.M21 = x2 * y;
            result.M22 = (y2 * y) + 1.0f;
            result.M23 = z2 * y;
            result.M31 = x2 * z;
            result.M32 = y2 * z;
            result.M33 = (z2 * z) + 1.0f;
        }